Skip to content

mindtorch_v2: add torch proxy for HuggingFace transformers testing#2761

Closed
lvyufeng wants to merge 1 commit into
candle-org:masterfrom
lvyufeng:feat/torch-proxy-albert
Closed

mindtorch_v2: add torch proxy for HuggingFace transformers testing#2761
lvyufeng wants to merge 1 commit into
candle-org:masterfrom
lvyufeng:feat/torch-proxy-albert

Conversation

@lvyufeng

@lvyufeng lvyufeng commented Mar 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add _torch_proxy.py with MetaPathFinder that redirects import torch to mindtorch_v2, enabling HuggingFace transformers tests to run against mindtorch_v2 without real PyTorch
  • Add stub modules for torch.cuda, torch.backends, torch._dynamo, torch.fx, torch._subclasses, torch.distributions, torch.hub, torch._C, etc.
  • Patch importlib.metadata to fake torch version as 2.7.1+dev (passes transformers version check)
  • Add FSDP fully_sharded_data_parallel.py re-export for isinstance checks

Test plan

  • pylint passes (10.00/10)
  • Albert model tests: 54/98 non-skipped tests pass (54 passed, 44 failed, 96 skipped)
  • CI pipeline passes (pylint-check + mindtorch-v2-test)

🤖 Generated with Claude Code

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>
@lvyufeng lvyufeng closed this Mar 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant