Fix Tracr demo output_label: compiled labels are auto-numbered#1525
Merged
jlarson4 merged 1 commit intoJul 21, 2026
Merged
Conversation
The Tracr demo passes output_label="reverse", but Tracr builds labels as
f"{name}_{unique_id}", so the compiled expression's residual labels are
reverse_1:* and the demo raises ValueError at the state-dict cell. Pass
reverse.label instead of hardcoding the name, and correct the same wrong
label shape in the unit-test fixture (real Tracr never emits "reverse:1")
and in the infer_tracr_output_label docstring example.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
The Tracr demo as shipped fails at its state-dict cell. Cell 11 passes
output_label="reverse", but Tracr builds labels asf"{name}_{unique_id}", so the compiled expression's residual labels arereverse_1:*andmake_tracr_transformer_bridge_state_dictraises:This is a follow-up to #1460 (the TransformerBridge port addressing #481): the conversion helpers there are correct, but the demo call site — and the unit-test fixture — assume the un-numbered label. The fixture in
tests/unit/test_tracr_conversion.pyhand-writesresidual_labelscontaining"reverse:1"etc., a shape real Tracr never emits, which is why the tests pass while the demo doesn't run.Three small changes, one concept (Tracr labels are auto-numbered; ask the expression for its label instead of hardcoding its name):
output_label="reverse"→output_label=reverse.label, plus a sentence in the preceding markdown cell explaining the auto-numbering (and that omittingoutput_labelalso works viainfer_tracr_output_label)."reverse:*"→"reverse_1:*"in_fake_tracr_model()and the matchingoutput_labelcall sites, so the mock matches what the compiler actually produces. The ambiguity test still has two candidate prefixes (aggregate_1,reverse_1) and all positional assertions are unchanged.infer_tracr_output_labelexample"reverse:3"→"reverse_1:3".Fixes #481.
Type of change
Validation
Run locally against this branch (Python 3.12, torch CPU, real
tracrfromgoogle-deepmind/tracr— note the Tracr stack needsjax<0.11, since dm-haiku still references the removedjax.core.DropVar):pytest tests/unit/test_tracr_conversion.py— 5 passed.TransformerBridge.boot_native→ load state dict → run): withoutput_label="reverse"it raises as above; withoutput_label=reverse.labeland withoutput_labelomitted, the Bridge decoding matches Tracr (['BOS', 3, 2, 1]) and every layer's attn/MLPhook_outmatches Tracr'slayer_outputs(np.isclose(...).all()per layer).Prepared with AI assistance and human-reviewed; all validation runs above are real runs on the contributor's machine.