Update locked PyTorch version to 2.10.0#1421
Open
danra wants to merge 6 commits into
Open
Conversation
nn.ModuleList is not generic, so iterating or indexing it yields a bare nn.Module (or Any on torch < 2.8). TypedModuleList[T] preserves the element type T through iteration and other methods while remaining a drop-in nn.ModuleList at runtime (children are still registered as submodules). For technical reasons, the return type information lives in a companion .pyi stub (technical: method-level beartype, enforced by jaxtyping, cannot resolve a Self return type. The explicit TypedModuleList[T] works only if we update jaxtyping's major version to 3.x, which is a bigger change). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Type HookedTransformer.blocks, HookedEncoder.blocks, and HookedEncoderDecoder.encoder/decoder as TypedModuleList[...] so iteration and indexing preserve the element type. This removes the # type: ignore[type-arg] annotations and the _get_blocks()/cast() workarounds that existed only because nn.ModuleList erased the element type, and lets downstream consumers (ActivationCache and the weight_processing benchmark) drop their now-redundant casts and union-attr ignores. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
… PyTorch Unlike the HT-family refactor, the goal here isn't to remove casts, it's a step towards updating PyTorch: as of torch 2.8, iterating a plain nn.ModuleList yields `Tensor | Module` instead of `Any`, which triggers new mypy errors. Typing blocks as TypedModuleList[BertBlock] fixes them (and also allows extra asserts to be dropped). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Clean fix for another mypy arg-type error that surfaces on torch >= 2.8 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolves the last remaining mypy errors with newer PyTorch Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Conservative: pyproject minimum requirement unchanged, still >=2.6 Incremental: stopping at 2.10.0 because 2.11.0's bundled torchvision 0.26.0 introduced relevant breaking changes - Makes TransformerLens compatible with Python 3.14 (previously, if 3.14 installed, then the default uv sync failed because the locked torch 2.7.1 wasn't compatible with it - Towards enabling MPS by default when torch is new enough and contains the required bugfixes (see TransformerLensOrg#1178)
Contributor
Author
Additional changes were indeed needed due to |
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.
Description
Conservative: pyproject minimum requirement unchanged, still
>=2.6Incremental: Latest available is 2.12.1, this PR updates to 2.10.0 because 2.11.0's bundled torchvision 0.26.0 introduced breaking changes which cause some existing tests to fail.
Tests passing on my local machine; CI will tell if this breaks elsewhere, or is good to go with no additional changes.
Motivation
Specific motivations (other than keeping dependencies up-to-date):
Type of change
Should probably be mentioned in the next release notes
Checklist: