Proposal
Base on dev-4.x. Add tests/integration/model_bridge/test_bridge_vs_hf_bert_parity.py: a bridge-vs-HF numerical parity test for a BERT checkpoint (e.g. bert-base-cased).
Motivation
The bridge's BERT path has no numerical certification anywhere in CI. The only BERT coverage that exists today is either structural or HookedEncoder-side:
tests/unit/model_bridge/supported_architectures/test_bert_adapter.py asserts component-mapping shape, weight-conversion patterns, and config flags. It never runs a forward pass.
tests/acceptance/test_hooked_encoder.py and tests/integration/test_create_hooked_encoder.py certify HookedEncoder
Pitch
- Boot via
TransformerBridge.boot_transformers("bert-base-cased", device="cpu", dtype=torch.float32) and run a forward. Boot auto-detects BertForMaskedLM, so no model_class is needed for the MLM case.
- Assert bridge MLM logits match a raw HF
BertForMaskedLM forward via torch.testing.assert_close. A local fp32 check on bert-base-cased currently gives a max abs difference of exactly 0.0.
- Don't call
enable_compatibility_mode() in the parity test – Compatibility mode applies HookedTransformer's default weight processing (including unembedding centering), which shifts logits away from raw HF.
- Assert
run_with_cache activations using bridge cache such as embed.hook_out, blocks.0.hook_resid_pre, blocks.0.attn.hook_q, ln_final.hook_normalized, unembed.hook_out.
- Model on the pythia-70m template; do not straight-copy the HT suite
Acceptance:
Checklist
Proposal
Base on
dev-4.x. Addtests/integration/model_bridge/test_bridge_vs_hf_bert_parity.py: a bridge-vs-HF numerical parity test for a BERT checkpoint (e.g.bert-base-cased).Motivation
The bridge's BERT path has no numerical certification anywhere in CI. The only BERT coverage that exists today is either structural or
HookedEncoder-side:tests/unit/model_bridge/supported_architectures/test_bert_adapter.pyasserts component-mapping shape, weight-conversion patterns, and config flags. It never runs a forward pass.tests/acceptance/test_hooked_encoder.pyandtests/integration/test_create_hooked_encoder.pycertifyHookedEncoderPitch
TransformerBridge.boot_transformers("bert-base-cased", device="cpu", dtype=torch.float32)and run a forward. Boot auto-detectsBertForMaskedLM, so nomodel_classis needed for the MLM case.BertForMaskedLMforward viatorch.testing.assert_close. A local fp32 check onbert-base-casedcurrently gives a max abs difference of exactly0.0.enable_compatibility_mode()in the parity test – Compatibility mode applies HookedTransformer's default weight processing (including unembedding centering), which shifts logits away from raw HF.run_with_cacheactivations using bridge cache such asembed.hook_out,blocks.0.hook_resid_pre,blocks.0.attn.hook_q,ln_final.hook_normalized,unembed.hook_out.Acceptance:
run_with_cacheassertion using correct bridge hook namestests/integration/model_bridge/, not skippedmake unit-testpassesuv run mypy .passesChecklist