Fix: Remove device_map to prevent meta tensor errors in table detection#459
Open
micmarty-deepsense wants to merge 2 commits intomainfrom
Open
Fix: Remove device_map to prevent meta tensor errors in table detection#459micmarty-deepsense wants to merge 2 commits intomainfrom
micmarty-deepsense wants to merge 2 commits intomainfrom
Conversation
The device_map parameter with HuggingFace Transformers can cause NotImplementedError "Cannot copy out of meta tensor" in multi-threaded contexts when loading TableTransformerForObjectDetection models. This fix: - Removes device_map from DetrImageProcessor.from_pretrained() - Removes device_map from TableTransformerForObjectDetection.from_pretrained() - Uses explicit .to(device) after model loading instead This pattern matches the fix applied to SentenceTransformer models in core-product (commits c8b175f7 and db636932). Error observed in in-vpc customer deployment when using strategy=fast with table detection.
…rors Removed manual bitmap.close() and page.close() calls in convert_pdf_to_image() to prevent pypdfium2 AssertionError during concurrent PDF processing. Issue: When manually closing child objects (bitmap, page) followed by parent PDF close, pypdfium2's weakref finalizers can run after parent closes, triggering assertion failures in cleanup logic. Solution: Let pypdfium2 finalizers handle resource cleanup automatically. This prevents double-cleanup race conditions and simplifies code. Version: Bumped to 1.1.9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes
NotImplementedError: Cannot copy out of meta tensorerror in table detection during multi-threaded processing.Root Cause: How device_map Creates Meta Tensors
The Problem
When passing
device_maptofrom_pretrained(), HuggingFace Transformers uses a special loading path:assign=True(HF #37615).to(device)From HF issue #33326:
From HF issue #26700:
Two Different Code Paths in Transformers
With device_map (broken path):
Without device_map (working path):
Why device_map Exists
Originally designed for HUGE models (>100B params) that don't fit in memory. Our TableTransformer models (~500MB) don't need this optimization and shouldn't use it.
Changes
device_mapfromDetrImageProcessor.from_pretrained()(line 75)device_mapfromTableTransformerForObjectDetection.from_pretrained()(lines 85-88).to(self.device)after model loading (line 87)Pattern Consistency
This matches the fix pattern used for SentenceTransformer models in core-product:
deviceparameter to model constructor@threadsafe_lazypropertyAntonio's PR #446 addressed a different issue (thread-safety race condition), while this PR fixes the underlying meta tensor problem.
Testing
Error observed in in-vpc customer deployment with
strategy=fast+ table detection during OCR processing.Stacktrace (from customer deployment)
References