Skip to content

fix: expose bridge boot methods to type checkers - #1981

Merged
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
koriyoshi2041:fix/typed-bridge-boot-methods
Nov 10, 2026
Merged

jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
koriyoshi2041:fix/typed-bridge-boot-methods

Conversation

@koriyoshi2041

Copy link
Copy Markdown
Contributor

Problem

TransformerBridge.boot_transformers, boot_native, and boot_tl_legacy are attached at runtime, so typed callers cannot see the full public API. The existing declaration only covers boot_transformers as Callable[..., TransformerBridge], which also discards its parameter types.

Fix

Declare all three static methods under TYPE_CHECKING with signatures matching their source implementations. This preserves the existing bridge-to-sources import direction and does not change runtime behavior.

Test

  • uvx ty check typed_boot_check.py against calls to all three methods; each return type is revealed as TransformerBridge
  • uv run mypy transformer_lens/model_bridge/transformer_bridge.py
  • uv run pytest tests/unit/model_bridge/test_boot_native.py -q (72 passed)
  • Runtime inspect.signature check for all three attached methods
  • git diff --check

Risk

Low. The declarations are excluded at runtime. The only maintenance risk is signature drift if a source boot function changes; keeping the declarations next to the bridge API makes that mismatch visible to static checks and review.

Closes #1980.

@jlarson4

jlarson4 commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

@koriyoshi2041 Can you please rebase this to dev so that it can pass CI?

@koriyoshi2041
koriyoshi2041 force-pushed the fix/typed-bridge-boot-methods branch from 6a6177a to 56f572b Compare November 6, 2026 00:43
@koriyoshi2041
koriyoshi2041 changed the base branch from main to dev November 6, 2026 00:43
@koriyoshi2041

Copy link
Copy Markdown
Contributor Author

Rebased onto dev at 177d2cc1. The updated head is 56f572b6; focused typing, runtime signature, format, and diff checks pass, and the hosted compatibility/type/coverage matrix is green.

@koriyoshi2041

Copy link
Copy Markdown
Contributor Author

Correction to my earlier status note: the delayed MPS runner finished with four failures in test_corrected_experts_preserve_input_route_and_parameter_gradients.

I checked this against the current dev workflow rather than changing this typing-only patch. The dev run at 41e048e1 fails the same four parametrizations, with the same 2 / 16384 gradient mismatch at line 244:

https://github.com/TransformerLensOrg/TransformerLens/actions/runs/42322880002/job/128276527426

This PR changes only transformer_lens/model_bridge/transformer_bridge.py; the failing file is tests/mps/test_granite_grouped_expert_dispatch.py. So the red MPS check is reproduced on dev independently of #1981. I have not added an unrelated tolerance change here.

@jlarson4

jlarson4 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

@koriyoshi2041 That is correct, I am investigating that now as part of the v4.4.0 release. Once that release is out, you'll need to rebase to dev again, which will have the correct code and allow your checks to pass.

In the future, be sure to base your PRs on dev so you don't trip the MPS workflow, it is only intended to be run on PR release merges from dev to main.

@jlarson4

jlarson4 commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

@koriyoshi2041 The bug fix is now on dev, feel free to rebase whenever you see MPS Checks passing on #1997

@koriyoshi2041
koriyoshi2041 force-pushed the fix/typed-bridge-boot-methods branch from 56f572b to b7fd43c Compare November 10, 2026 00:41
@koriyoshi2041

Copy link
Copy Markdown
Contributor Author

Rebased onto the post-release dev head. The new head is b7fd43ca; compatibility (3.10–3.12), type, format, coverage, benchmark, docstring, and notebook checks are green.

@jlarson4
jlarson4 merged commit 27483c1 into TransformerLensOrg:dev Nov 10, 2026
31 checks passed
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.

[Bug Report] TransformerBridge.boot_* methods are invisible to static type checkers

2 participants