-
Notifications
You must be signed in to change notification settings - Fork 74
fix: remove device_map to prevent TableTransformer meta tensor errors #462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Remove device_map parameter from from_pretrained() calls to fix meta tensor errors during concurrent processing. Changes: - Device normalization (cuda -> cuda:0) for consistent caching - Remove device_map from DetrImageProcessor.from_pretrained() - Remove device_map from TableTransformerForObjectDetection.from_pretrained() - Add explicit .to(device, dtype=torch.float32) for proper placement - Improve logging to show target device Fixes: - "Trying to set a tensor of type Float but got Meta" errors - AssertionError during concurrent PDF processing - Finalization race conditions with device_map Root Cause: device_map causes models to initialize with meta tensors, which fail when explicitly moved to device. Removing device_map and using explicit .to() ensures proper tensor placement. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
08b5a5b to
01304fd
Compare
- Add CUDA availability check before torch.cuda.current_device() - Capture model.to() return value per PyTorch documentation - Add fallback to CPU if CUDA requested but unavailable - Document rationale for return value capture
5a9fc95 to
86e3b6a
Compare
Resolved conflicts: - CHANGELOG.md: Keep both 1.1.9 fixes (TableTransformer device_map + pdfium context manager)
|
@claude review |
|
Claude finished @micmarty-deepsense's task —— View job Code Review Complete ✅Todo List:
Review Summary🎯 Overall Assessment: APPROVE WITH MINOR SUGGESTIONS This PR effectively addresses the meta tensor error during concurrent processing by removing ✅ Strengths
🔍 Technical AnalysisDevice Map Removal: # OLD (problematic):
self.model = TableTransformerForObjectDetection.from_pretrained(model, device_map="auto")
# NEW (correct):
self.model = TableTransformerForObjectDetection.from_pretrained(model)
self.model = self.model.to(self.device, dtype=torch.float32)This change prevents the model from being loaded with meta tensors that can't be properly copied during concurrent operations. Device Normalization ( if device.startswith("cuda") and ":" not in device:
if torch.cuda.is_available():
device = f"cuda:{torch.cuda.current_device()}"Smart approach for consistent device naming and caching. 🔧 Minor Suggestions
📋 Code Quality
🚀 ImpactThis fix will:
📝 Minor Nits
Recommendation: MERGE This is a solid fix that addresses a real production issue with a clean, well-tested solution. The minor suggestions above are optional improvements that don't block merging. |
Summary
Remove device_map parameter from TableTransformer initialization to prevent meta tensor errors during concurrent processing.
Problem
We were observing this error "Cannot copy out of meta tensor; no data!"
Solution
device_mapfromDetrImageProcessor.from_pretrained()device_mapfromTableTransformerForObjectDetection.from_pretrained().to(device, dtype=torch.float32)with return value capture per PyTorch best practicestorch.cuda.current_device()to prevent crashesTesting
Tested in production (core-product) where this fix eliminated:
Performance Impact
Backward Compatibility
✅ Fully backward compatible - no API changes