mindtorch_v2: add torch proxy for HuggingFace transformers testing#2761
Closed
lvyufeng wants to merge 1 commit into
Closed
mindtorch_v2: add torch proxy for HuggingFace transformers testing#2761lvyufeng wants to merge 1 commit into
lvyufeng wants to merge 1 commit into
Conversation
Add `_torch_proxy.py` with MetaPathFinder that redirects `import torch` to mindtorch_v2, enabling HuggingFace transformers tests to run against the mindtorch_v2 backend without real PyTorch installed. Key components: - MetaPathFinder/Loader: intercepts torch.* imports → mindtorch_v2.* - Stub modules: torch.cuda, torch.backends, torch._dynamo, torch.fx, torch._subclasses, torch.distributions, torch.hub, torch._C, etc. - importlib.metadata patching: fakes torch version as 2.7.1+dev - Auto-stub fallback: unknown torch.xxx → empty stub (no ImportError) - FSDP fully_sharded_data_parallel re-export for isinstance checks Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
_torch_proxy.pywithMetaPathFinderthat redirectsimport torchtomindtorch_v2, enabling HuggingFace transformers tests to run against mindtorch_v2 without real PyTorchtorch.cuda,torch.backends,torch._dynamo,torch.fx,torch._subclasses,torch.distributions,torch.hub,torch._C, etc.importlib.metadatato fake torch version as2.7.1+dev(passes transformers version check)fully_sharded_data_parallel.pyre-export for isinstance checksTest plan
🤖 Generated with Claude Code