Skip to content

Update locked PyTorch version to 2.10.0#1421

Open
danra wants to merge 6 commits into
TransformerLensOrg:devfrom
danra:torch_2_10
Open

Update locked PyTorch version to 2.10.0#1421
danra wants to merge 6 commits into
TransformerLensOrg:devfrom
danra:torch_2_10

Conversation

@danra

@danra danra commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Description

Conservative: pyproject minimum requirement unchanged, still >=2.6

Incremental: 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

  • This change requires a documentation update

Should probably be mentioned in the next release notes

Checklist:

  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

danra and others added 6 commits June 20, 2026 21:37
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)
@danra

danra commented Jun 21, 2026

Copy link
Copy Markdown
Contributor Author

Tests passing on my local machine; CI will tell if this breaks elsewhere, or is good to go with no additional changes.

Additional changes were indeed needed due to ModuleList iteration returning Module rather than Any starting with PyTorch 2.8, which triggered new mypy errors, the bulk of which were resolved using a new TypedModuleList generic wrapper around ModuleList. These changes are now rebased in this PR ahead of the torch update.

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