Skip to content

refactor(train): relocate to tools/training.py for bridge compatibility - #1594

Open
MdSadiqMd wants to merge 2 commits into
TransformerLensOrg:dev-4.xfrom
MdSadiqMd:sadiq/relocate-training.py
Open

refactor(train): relocate to tools/training.py for bridge compatibility#1594
MdSadiqMd wants to merge 2 commits into
TransformerLensOrg:dev-4.xfrom
MdSadiqMd:sadiq/relocate-training.py

Conversation

@MdSadiqMd

Copy link
Copy Markdown
Contributor

Description

Relocate train() + HookedTransformerTrainConfig from transformer_lens/train.py to transformer_lens/tools/training.py, typed against nn.Module so TransformerBridge trains through it.

Motivation: train.py:17 hard-imports HookedTransformer and is re-exported from __init__.py:10, so at 4.0 the package import breaks unless the loop leaves the HT namespace.

Changes:

  • transformer_lens/tools/training.py: New home for TrainConfig (renamed from HookedTransformerTrainConfig) and train(), typed against nn.Module
  • transformer_lens/train.py: Deprecation shim with DeprecationWarning on use
  • transformer_lens/tools/__init__.py: Add training to lazy submodules
  • tests/integration/model_bridge/test_native_training.py: Add test_train_loop_trains_bridge_via_train_config, fix InductionDataset to return single samples

Acceptance:

  • tools/training.py exists, no HookedTransformer import
  • TransformerBridge (via boot_native) trains through train()
  • from transformer_lens import train still imports, emits DeprecationWarning, delegates
  • Tests under tests/integration/model_bridge/test_native_training.py
  • make unit-test + uv run mypy . clean

Fixes #1589

Type of change

  • New feature (non-breaking change which adds functionality)

Screenshots

N/A

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

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