fix: improve pytorch model initialization to prevent meta tensor issues#180
Merged
nicoloboschi merged 3 commits intomainfrom Jan 20, 2026
Merged
fix: improve pytorch model initialization to prevent meta tensor issues#180nicoloboschi merged 3 commits intomainfrom
nicoloboschi merged 3 commits intomainfrom
Conversation
When accelerate is installed but no GPU is available, transformers can incorrectly use lazy loading (meta tensors) which fails when sentence-transformers tries to move the model to a device. The fix checks hardware and installed packages to determine the right loading strategy: - GPU available: device=None, device_map=None (auto-detect GPU) - No GPU + accelerate: device='cpu', device_map='cpu' (force CPU loading) - No GPU + no accelerate: device='cpu', device_map=None (normal CPU) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
1839db1 to
c935c57
Compare
When pytest-xdist runs multiple workers in parallel, they all try to load models from the HuggingFace cache simultaneously, causing race conditions and intermittent meta tensor errors. Added filelock around embeddings and cross_encoder initialization in conftest.py, similar to how pg0 database setup is serialized. Models are now pre-initialized in the fixture before being passed to tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Extend GPU detection to include Apple MPS backend in addition to CUDA. This ensures macOS users with Apple Silicon use MPS acceleration instead of being incorrectly routed to the CPU fallback path.
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.
No description provided.