Skip to content

Update lfm2 moe to use correct bridge elements - #1670

Open
TensorCruncher wants to merge 1 commit into
TransformerLensOrg:devfrom
TensorCruncher:update-lfm2-moe
Open

Update lfm2 moe to use correct bridge elements#1670
TensorCruncher wants to merge 1 commit into
TransformerLensOrg:devfrom
TensorCruncher:update-lfm2-moe

Conversation

@TensorCruncher

Copy link
Copy Markdown
Contributor

Description

Updated Lfm2MoE to use correct bridge elements so as to expand hook coverage.

The verify model test fails two tests, both due to the mlp/moe components.

Lfm2 MoE uses dense mlp for first two layers and moe for the remaining. This seems to be causing issues in certain tests. Forward parity passes though.

I will attach results of verify model run.

@TensorCruncher

Copy link
Copy Markdown
Contributor Author
adil@Syeds-MacBook-Pro TransformerLens % uv run python -m transformer_lens.tools.model_registry.verify_models \
  --model "LiquidAI/LFM2.5-8B-A1B" \
  --max-memory 29 \
  --device cpu \
  --dtype bfloat16 \
  --no-ht-reference  
Model list mode: 1 model(s)
Selected 1 models for verification
2026-08-14 13:15:47,700 [INFO] HTTP Request: HEAD https://huggingface.co/gpt2/resolve/main/config.json "HTTP/1.1 200 OK"
Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
2026-08-14 13:15:47,701 [WARNING] Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.
2026-08-14 13:15:47,925 [INFO] HTTP Request: HEAD https://huggingface.co/gpt2/resolve/main/tokenizer_config.json "HTTP/1.1 200 OK"
2026-08-14 13:15:48,142 [INFO] HTTP Request: GET https://huggingface.co/api/models/gpt2/tree/main/additional_chat_templates?recursive=false&expand=false "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:15:48,354 [INFO] HTTP Request: GET https://huggingface.co/api/models/openai-community/gpt2/tree/main/additional_chat_templates?recursive=false&expand=false "HTTP/1.1 404 Not Found"
2026-08-14 13:15:48,568 [INFO] HTTP Request: GET https://huggingface.co/api/models/gpt2/tree/main?recursive=true&expand=false "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:15:48,785 [INFO] HTTP Request: GET https://huggingface.co/api/models/openai-community/gpt2/tree/main?recursive=true&expand=false "HTTP/1.1 200 OK"
2026-08-14 13:15:49,236 [INFO] HTTP Request: HEAD https://huggingface.co/gpt2/resolve/main/config.json "HTTP/1.1 200 OK"
Loading weights: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████| 148/148 [00:00<00:00, 11489.54it/s]
2026-08-14 13:15:49,645 [INFO] HTTP Request: HEAD https://huggingface.co/gpt2/resolve/main/generation_config.json "HTTP/1.1 200 OK"
Pre-loaded GPT-2 scoring model for Phase 4

======================================================================
[1/1] LiquidAI/LFM2.5-8B-A1B (Lfm2MoeForCausalLM)
======================================================================
2026-08-14 13:15:49,862 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:15:49,875 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
  Estimated parameters: 6,303,514,624
  Estimated benchmark memory: 28.2 GB (limit: 29.0 GB)
  Running phases None in a single benchmark call...

================================================================================
Running TransformerBridge Benchmark Suite
Model: LiquidAI/LFM2.5-8B-A1B
Device: cpu
================================================================================


================================================================================
PHASE 1: HuggingFace + TransformerBridge (unprocessed)
================================================================================

Detecting model configuration...
2026-08-14 13:15:50,156 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:15:50,172 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:17:37,545 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:17:37,559 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:17:37,840 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/tokenizer_config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:17:37,856 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/tokenizer_config.json "HTTP/1.1 200 OK"
2026-08-14 13:17:37,873 [INFO] HTTP Request: GET https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/tokenizer_config.json "HTTP/1.1 200 OK"
tokenizer_config.json: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 315/315 [00:00<00:00, 2.50MB/s]
2026-08-14 13:17:38,110 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B/tree/main/additional_chat_templates?recursive=false&expand=false "HTTP/1.1 404 Not Found"
2026-08-14 13:17:38,336 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B/tree/main?recursive=true&expand=false "HTTP/1.1 200 OK"
2026-08-14 13:17:38,556 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/tokenizer.json "HTTP/1.1 302 Found"
2026-08-14 13:17:38,888 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B/xet-read-token/b9aebfcbe28b6cb374042f495d733037550ab146 "HTTP/1.1 200 OK"
tokenizer.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 17.9M/17.9M [00:02<00:00, 7.93MB/s]
2026-08-14 13:17:41,428 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/tokenizer.model "HTTP/1.1 404 Not Found"
2026-08-14 13:17:41,646 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/added_tokens.json "HTTP/1.1 404 Not Found"
2026-08-14 13:17:41,881 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/special_tokens_map.json "HTTP/1.1 404 Not Found"
2026-08-14 13:17:42,093 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/chat_template.jinja "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:17:42,107 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/chat_template.jinja "HTTP/1.1 200 OK"
2026-08-14 13:17:42,124 [INFO] HTTP Request: GET https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/chat_template.jinja "HTTP/1.1 200 OK"
chat_template.jinja: 4.76kB [00:00, 5.48MB/s]
2026-08-14 13:17:43,086 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B "HTTP/1.1 200 OK"
✓ Detected attn_implementation=eager
Loading HuggingFace reference model...
Using attn_implementation=eager
2026-08-14 13:17:44,559 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:17:44,574 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:17:44,791 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:17:44,806 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:17:45,025 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:17:45,041 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:17:45,261 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/model.safetensors "HTTP/1.1 302 Found"
model.safetensors: 100%|███████████████████████████████████████████████████████████████████████████████████████████████| 16.9G/16.9G [05:45<00:00, 49.0MB/s]
Loading weights: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 234/234 [00:18<00:00, 12.65it/s]
2026-08-14 13:23:49,691 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/generation_config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:23:49,706 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/generation_config.json "HTTP/1.1 200 OK"
2026-08-14 13:23:49,725 [INFO] HTTP Request: GET https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/generation_config.json "HTTP/1.1 200 OK"
generation_config.json: 100%|██████████████████████████████████████████████████████████████████████████████████████████████| 318/318 [00:00<00:00, 1.33MB/s]
Detected dtype=torch.bfloat16
✓ HuggingFace model loaded
Loading TransformerBridge (unprocessed)...
2026-08-14 13:23:49,948 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:23:49,965 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
Loading weights: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 234/234 [00:32<00:00,  7.24it/s]
2026-08-14 13:24:22,687 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/generation_config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:24:22,700 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/generation_config.json "HTTP/1.1 200 OK"
2026-08-14 13:24:22,930 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:24:22,943 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:24:23,162 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/tokenizer_config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:24:23,178 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/tokenizer_config.json "HTTP/1.1 200 OK"
2026-08-14 13:24:23,414 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B/tree/main/additional_chat_templates?recursive=false&expand=false "HTTP/1.1 404 Not Found"
2026-08-14 13:24:23,650 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B/tree/main?recursive=true&expand=false "HTTP/1.1 200 OK"
2026-08-14 13:24:24,618 [INFO] HTTP Request: GET https://huggingface.co/api/models/LiquidAI/LFM2.5-8B-A1B "HTTP/1.1 200 OK"
✓ TransformerBridge loaded (unprocessed)

Running Phase 1 benchmarks...

1. Component-Level Benchmarks
❌ [FAIL] all_components: 22/152 components failed (22 critical)
  total_components: 152
  passed_components: 130
  failed_components: 22
  pass_rate: 85.52631578947368
  failures: {'blocks.2.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.3.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.4.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.5.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.6.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.7.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.8.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.9.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.10.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.11.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.12.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.13.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.14.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.15.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.16.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.17.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.18.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.19.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.20.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.21.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.22.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}, 'blocks.23.mlp.gate': {'max_diff': inf, 'mean_diff': inf, 'severity': 'critical', 'error': "LinearBridge.forward() missing 1 required positional argument: 'input'"}}
✗ 22/152 components failed (22 critical)

Capturing HF reference outputs to CPU...
2026-08-14 13:25:06,499 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:25:06,517 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
✓ Captured HF logits torch.Size([1, 28, 128000]), loss=3.1875

Cleaning up HuggingFace model...
2. Forward Pass Benchmarks
🟢 [PASS] forward_pass_logits: Tensors match within tolerance
  atol: 0.005
  rtol: 0.03
✓ Saved Phase 1 reference data (logits: torch.Size([1, 28, 128000]))

================================================================================
PHASE 2: TransformerBridge (unprocessed) + HookedTransformer (unprocessed)
================================================================================

Running Phase 2 benchmarks...

2026-08-14 13:25:28,975 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:25:28,989 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
1. Generation Benchmarks (unprocessed)
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:02<00:00,  4.18it/s]
🟢 [PASS] generation: Generation successful: 28 -> 38 tokens (176 -> 244 chars)
  input_tokens: 28
  output_tokens: 38
  input_chars: 176
  output_chars: 244
  max_new_tokens: 10
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 10/10 [00:02<00:00,  3.43it/s]
🟢 [PASS] generation_with_kv_cache: KV cache generation successful (221 chars)
  output_len: 221
  max_new_tokens: 10
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:02<00:00,  2.25it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:01<00:00,  3.05it/s]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 5/5 [00:01<00:00,  3.59it/s]
🟢 [PASS] multiple_generation_calls: All 3 generation calls successful
  prompt_count: 3
  max_new_tokens: 5
  output_lens: [43, 30, 47]
2. Running Unprocessed Model Comparison Benchmarks

2. Model Equivalence Benchmarks (Forward Pass)
⏭️ Skipped (no HookedTransformer reference)

⏭️ [SKIPPED] logits_equivalence: Skipped (HookedTransformer not available for this model)
⏭️ [SKIPPED] loss_equivalence: Skipped (HookedTransformer not available for this model)
3. Hook Registration Benchmarks
🟢 [PASS] hook_registry: Bridge has 738 registered hooks
  hook_count: 738
4. Forward Hook Functionality Benchmarks
🟡 [PASS] hook_functionality: Ablation had minimal effect: 0.000000
  effect: 0.0
🟢 [PASS] critical_forward_hooks: Bridge captured 8/14 critical hooks
  captured: 8
  expected: 14
🟡 [PASS] forward_hooks: 108/995 hooks didn't fire during forward pass
  captured: 887
  registered: 995
  didnt_fire: ['blocks.18.hook_mlp_in', 'blocks.21.mlp.hook_router_scores', 'blocks.21.attn.hook_attn_in', 'blocks.10.hook_mlp_in', 'blocks.22.hook_mlp_in', 'blocks.6.hook_q_input', 'blocks.14.hook_mlp_in', 'blocks.2.hook_v_input', 'blocks.3.hook_mlp_in', 'blocks.14.attn.hook_hidden_states']
🟢 [PASS] gated_hooks_fire: All gated hooks fired on their supporting layers (54 activations across 5 hook stems, 3 flags tested)
  fired_counts: {'hook_result': 6, 'hook_q_input': 12, 'hook_k_input': 12, 'hook_v_input': 12, 'hook_attn_in': 12}
  tested_flags: ['use_attn_result', 'use_split_qkv_input', 'use_attn_in']
  skipped: []
5. Activation Cache Benchmarks
🟢 [PASS] run_with_cache: run_with_cache successful with 887 cached activations
  cache_size: 887
🟢 [PASS] activation_cache: Activation cache created with 887 entries
  cache_size: 887
6. Backward Gradient Benchmarks
🟢 [PASS] gradient_computation: Gradients computed successfully
🟢 [PASS] critical_backward_hooks: Bridge captured 7/12 critical backward gradients
  captured: 7
  expected: 12
/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/normalization.py:175: UserWarning: Backward hooks on hook_scale/hook_normalized require grad-connected hook tensors; falling back from the native-autograd path to the python-norm path. Output numerics may differ from the unhooked forward at float-rounding scale.
  warnings.warn(NATIVE_PATH_BWD_FALLBACK_WARNING)
/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/benchmarks/backward_gradients.py:61: UserWarning: Full backward hook is firing when gradients are computed with respect to module outputs since no inputs require gradients. See https://docs.pytorch.org/docs/main/generated/torch.nn.Module.html#torch.nn.Module.register_full_backward_hook for more details.
  bridge_loss.backward()
🟢 [PASS] backward_hooks: Bridge captured 617 backward hook gradients
  gradient_count: 617
2026-08-14 13:31:33,144 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:31:33,157 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"
2026-08-14 13:31:33,379 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:31:33,395 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"

================================================================================
PHASE 2.5: Text Quality (GPT-2 perplexity scoring)
================================================================================

100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:10<00:00,  4.80it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:05<00:00,  8.37it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:05<00:00,  9.11it/s]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:05<00:00,  8.81it/s]
🟢 [PASS] text_quality: Text quality score: 86.2/100 (avg perplexity: 28.9, 4 prompts)
  score: 86.2
  avg_perplexity: 28.93
  avg_repetition_penalty: 0.87
  num_prompts: 4
  per_prompt: ppl=47.9 score=93.8 rep=0.97 | ppl=19.0 score=93.3 rep=0.93 | ppl=9.1 score=68.8 rep=0.69 | ppl=39.7 score=88.8 rep=0.90
  scoring_model: gpt2
  max_new_tokens: 50
  generated_text: Natural language processing tasks, such as question answering, machine translation, reading comprehension, and summarization, are typically approached with supervised learning. Many of these tasks require labeled data,, i.e., data with pairs of text and labels. supervised language models are models that that have been trained on text and labeled data ... [truncated]

Next, I will discuss the role of
2026-08-14 13:32:02,457 [INFO] HTTP Request: HEAD https://huggingface.co/LiquidAI/LFM2.5-8B-A1B/resolve/main/config.json "HTTP/1.1 307 Temporary Redirect"
2026-08-14 13:32:02,474 [INFO] HTTP Request: HEAD https://huggingface.co/api/resolve-cache/models/LiquidAI/LFM2.5-8B-A1B/b9aebfcbe28b6cb374042f495d733037550ab146/config.json "HTTP/1.1 200 OK"

================================================================================
PHASE 3: TransformerBridge (processed) + HookedTransformer (processed)
================================================================================

Processing weights on existing bridge (reusing Phase 1 instance)...
✓ TransformerBridge compatibility mode enabled (processed)

Running Phase 3 benchmarks...

1. Weight Processing Benchmarks (Foundation)
🟢 [PASS] no_nan_inf: No NaN or Inf values found in weights
  num_tensors_checked: 166
🟢 [PASS] weight_magnitudes: All weight magnitudes in reasonable ranges
  min_threshold: 1e-06
  max_threshold: 1000.0
🟡 [FAIL] layer_norm_folding: Layer norm weights not identity after folding: ln1 (mean=0.197266), ln2 (mean=0.105469)
  not_folded: ['ln1', 'ln2']
🟢 [PASS] attention_output_centering: Attention output centering verified (worst_mean=0.000351) (6/24 blocks have attention)
  mean: 0.0003509521484375
  tolerance: 0.01
  n_attn_blocks: 6
🟢 [PASS] mlp_output_centering: MLP output centering verified (mean=0.000256)
  mean: 0.000255584716796875
  tolerance: 0.01
🟢 [PASS] unembed_centering: Unembed centering verified (mean=0.000001)
  mean: 1.1995434761047363e-06
  tolerance: 0.01
  key: unembed.weight
🟢 [PASS] value_bias_folding: Skipped for GQA models (n_key_value_heads != n_heads)
  is_gqa: True
  n_heads: 32
  n_kv_heads: 8
⏭️ weight_processing and weight_sharing skipped (no HT reference)
⏭️ [SKIPPED] weight_processing: Skipped (HookedTransformer not available for this model)
⏭️ [SKIPPED] weight_sharing: Skipped (HookedTransformer not available for this model)
❌ [FAIL] weight_modification: Weight modification check failed: 
2. Model Equivalence Benchmarks (Forward Pass)
Using saved Phase 1 bridge reference for equivalence comparison
✗ Phase 1 reference comparison failed: 

3. Hook Registration Benchmarks
🟢 [PASS] hook_registry: Bridge has 995 registered hooks
  hook_count: 995
4. Forward Hook Functionality Benchmarks
❌ [FAIL] hook_functionality: Hook functionality check failed: 
  error_type: AssertionError
  error_message: 
  traceback: Traceback (most recent call last):
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/benchmarks/hook_registration.py", line 699, in benchmark_hook_functionality
    bridge_original = bridge(test_text, return_type="loss")
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/bridge.py", line 2077, in forward
    output = self.original_model(input_ids, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 911, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 714, in forward
    outputs: BaseModelOutputWithPast = self.model(
                                       ^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 1040, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/output_capturing.py", line 252, in wrapper
    outputs = func(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 651, in forward
    hidden_states = decoder_layer(
                    ^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/block.py", line 223, in forward
    output = self.original_component(*args, **filtered_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/modeling_layers.py", line 93, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1882, in _call_impl
    return inner()
           ^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1830, in inner
    result = forward_call(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 551, in forward
    hidden_states = hidden_states + self.feed_forward(self.ffn_norm(hidden_states))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/gated_mlp.py", line 107, in forward
    assert self._processed_W_in is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

❌ [FAIL] critical_forward_hooks: Critical hooks check failed: 
  error_type: AssertionError
  error_message: 
  traceback: Traceback (most recent call last):
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/benchmarks/hook_registration.py", line 513, in benchmark_critical_forward_hooks
    _ = bridge(test_text)
        ^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/bridge.py", line 2077, in forward
    output = self.original_model(input_ids, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 911, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 714, in forward
    outputs: BaseModelOutputWithPast = self.model(
                                       ^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 1040, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/output_capturing.py", line 252, in wrapper
    outputs = func(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 651, in forward
    hidden_states = decoder_layer(
                    ^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/block.py", line 223, in forward
    output = self.original_component(*args, **filtered_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/modeling_layers.py", line 93, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1882, in _call_impl
    return inner()
           ^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1830, in inner
    result = forward_call(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 551, in forward
    hidden_states = hidden_states + self.feed_forward(self.ffn_norm(hidden_states))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/gated_mlp.py", line 107, in forward
    assert self._processed_W_in is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

❌ [FAIL] forward_hooks: Forward hooks check failed: 
❌ [FAIL] gated_hooks_fire: Gated-hook check failed: 
5. Activation Cache Benchmarks
❌ [FAIL] run_with_cache: run_with_cache failed: 
❌ [FAIL] activation_cache: Activation cache check failed: 
6. Backward Gradient Benchmarks
❌ [FAIL] gradient_computation: Gradient computation failed: 
❌ [FAIL] critical_backward_hooks: Critical backward hooks check failed: 
  error_type: AssertionError
  error_message: 
  traceback: Traceback (most recent call last):
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/benchmarks/backward_gradients.py", line 314, in benchmark_critical_backward_hooks
    bridge_output = bridge(test_text)
                    ^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/bridge.py", line 2077, in forward
    output = self.original_model(input_ids, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 911, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 714, in forward
    outputs: BaseModelOutputWithPast = self.model(
                                       ^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 1040, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/output_capturing.py", line 252, in wrapper
    outputs = func(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 651, in forward
    hidden_states = decoder_layer(
                    ^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/block.py", line 223, in forward
    output = self.original_component(*args, **filtered_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/modeling_layers.py", line 93, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1882, in _call_impl
    return inner()
           ^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1830, in inner
    result = forward_call(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 551, in forward
    hidden_states = hidden_states + self.feed_forward(self.ffn_norm(hidden_states))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/gated_mlp.py", line 107, in forward
    assert self._processed_W_in is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

❌ [FAIL] backward_hooks: Backward hooks check failed: 
  error_type: AssertionError
  error_message: 
  traceback: Traceback (most recent call last):
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/benchmarks/backward_gradients.py", line 59, in benchmark_backward_hooks
    bridge_output = bridge(test_text)
                    ^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/bridge.py", line 2077, in forward
    output = self.original_model(input_ids, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 911, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 714, in forward
    outputs: BaseModelOutputWithPast = self.model(
                                       ^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/generic.py", line 1040, in wrapper
    output = func(self, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/utils/output_capturing.py", line 252, in wrapper
    outputs = func(self, *args, **kwargs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 651, in forward
    hidden_states = decoder_layer(
                    ^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/block.py", line 223, in forward
    output = self.original_component(*args, **filtered_kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/modeling_layers.py", line 93, in __call__
    return super().__call__(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1882, in _call_impl
    return inner()
           ^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1830, in inner
    result = forward_call(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/transformers/models/lfm2_moe/modeling_lfm2_moe.py", line 551, in forward
    hidden_states = hidden_states + self.feed_forward(self.ffn_norm(hidden_states))
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1776, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/.venv/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1787, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/adil/Desktop/Open_Source/TransformerLens/transformer_lens/model_bridge/generalized_components/gated_mlp.py", line 107, in forward
    assert self._processed_W_in is not None
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

Cleaning up TransformerBridge (processed)...

================================================================================
BENCHMARK SUMMARY
================================================================================

Phase 1: 2 tests run
  Passed: 1/2 (50.0%)
  Failed: 1/2 (50.0%)

Phase 2: 13 tests run
  Passed: 13/13 (100.0%)
  Failed: 0/13 (0.0%)
  Skipped: 2

Phase 3: 18 tests run
  Passed: 7/18 (38.9%)
  Failed: 11/18 (61.1%)
  Skipped: 2

Phase 4: 1 tests run
  Passed: 1/1 (100.0%)
  Failed: 0/1 (0.0%)

Overall:
Total: 38 tests
Run: 34 tests
Skipped: 4 tests
Passed: 22/34 (64.7%)
Failed: 12/34 (35.3%)
================================================================================
  FAILED: Below threshold: P1=50.0% < 100.0% (failed: all_components); P3=38.9% < 75.0% (failed: layer_norm_fo — 22/152 components failed (22 critical)
  Partial scores saved: P1=50.0%, P2=100.0%, P3=38.9%, P4=86.2%, P7=None%, P8=None%, P9=None%

======================================================================
Verification Summary
======================================================================
  Total tested:  1
  Verified:      0
  Provisional:   0
  Skipped:       0
  Failed:        1

  Failed models:
    - LiquidAI/LFM2.5-8B-A1B

Total time: 992.2s
Checkpoint cleared (run complete)

@TensorCruncher

Copy link
Copy Markdown
Contributor Author

Compatibility checks are failing because unit tests have not been updated. Will do that once I have clarity on the test failures for verify model

@TensorCruncher

Copy link
Copy Markdown
Contributor Author

From the lfm2 moe modelling file in transformers we can see that the gate is not a linear nn module. Could this be the reason for the first test failure? The test fails on blocks > 2, so the first two dense mlps don't error.

class Lfm2MoeTopKRouter(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.top_k = config.num_experts_per_tok
        self.num_experts = config.num_experts
        self.norm_topk_prob = config.norm_topk_prob
        self.hidden_dim = config.hidden_size
        self.weight = nn.Parameter(torch.zeros(self.num_experts, self.hidden_dim))
        self.routed_scaling_factor = config.routed_scaling_factor
        self.use_expert_bias = config.use_expert_bias

    def forward(self, hidden_states, expert_bias=None):
        router_logits = F.linear(hidden_states, self.weight)
        routing_weights = router_logits.sigmoid()
        if self.use_expert_bias:
            scores_for_routing = routing_weights + expert_bias
            _, selected_experts = torch.topk(scores_for_routing, k=self.top_k, dim=-1)
            routing_weights = torch.gather(routing_weights, dim=1, index=selected_experts).type_as(router_logits)
        else:
            routing_weights, selected_experts = torch.topk(routing_weights, k=self.top_k, dim=-1)

        if self.norm_topk_prob:
            routing_weights = routing_weights / (routing_weights.sum(dim=-1, keepdim=True) + 1e-6)
        routing_weights = routing_weights * self.routed_scaling_factor
        return router_logits, routing_weights, selected_experts


class Lfm2MoeSparseMoeBlock(nn.Module):
    def __init__(self, config):
        super().__init__()
        self.experts = Lfm2MoeExperts(config)
        self.gate = Lfm2MoeTopKRouter(config)
        self.use_expert_bias = config.use_expert_bias
        if self.use_expert_bias:
            self.expert_bias = nn.Buffer(torch.zeros(config.num_experts, dtype=torch.float32))

    def forward(self, hidden_states: torch.Tensor) -> tuple[torch.Tensor, torch.Tensor]:
        batch_size, sequence_length, hidden_dim = hidden_states.shape
        hidden_states_reshaped = hidden_states.view(-1, hidden_dim)
        expert_bias = self.expert_bias if self.use_expert_bias else None
        _, routing_weights, selected_experts = self.gate(hidden_states_reshaped, expert_bias)
        final_hidden_states = self.experts(hidden_states_reshaped, selected_experts, routing_weights)
        return final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)

@jlarson4 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking this on @TensorCruncher! Decomposing LFM2-MoE into real components is an improvement over the current system and I was able to reproduce the forward parity result on my end. A couple comments below, including the answer to your question:

"out": LinearBridge(name="out_proj"),
},
),
"mlp": MoEBridge(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To answer your question: Your diagnosis is right, the structure of the benchmarks system is creating an error message that is masking the real problem. Lfm2MoeTopKRouter takes (hidden_states, expert_bias=None) and returns a 3-tuple, but the deeper problem is that use_expert_bias=True and expert_bias lives on the parent Lfm2MoeSparseMoeBlock. Calling the router with only hidden_states raises unsupported operand type(s) for +: 'Tensor' and 'NoneType'. The benchmark then retries with hidden_states= as a keyword, and that second attempt is what generates the LinearBridge.forward() missing 1 required positional argument: 'input' error.

This should be fixable by subclassing the existing MoERouterBridge and overriding get_random_inputs() to return {"args": (hidden_states, expert_bias)} with expert_bias=torch.zeros(num_experts). Pass config=self.cfg into the submodule too, without it d_model silently falls back to 768 and you'll get a shape error instead.

"mlp": MoEBridge(
name="feed_forward",
config=self.cfg,
submodules={"gate": LinearBridge(name="gate")},

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the dense layers get a GatedMLPBridge with a gate submodule while sparse layers use MoEBridge's gate for the router, blocks.0.mlp.gate.hook_out is w1 and blocks.2.mlp.gate.hook_out is the router in the same model. MoEBridge's DENSE_SUBMODULE_KEYS comment describes this per-layer semantic flip as the thing the dense_* keys exist to prevent.

There is an example of the shape you should use in laguna.py:78-88 / llada2_moe.py:110-121. Using this instead should resolve some of your errors. Let me know if you have any questions on this parts specifically.

Wrapping the HF layer as a whole preserves correct execution while avoiding
unresolved standard attention/MLP aliases on layers that do not have them.
"""
def set_original_component(self, original_component: Any) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently added per-layer dense binding to MoEBridge in #1666, so the set_original_component override on lines 27-42 should be safe to delete, as long as you have all the latest commits from dev. Run a git merge if you need to pull in the latest changes.

rope_parameters = getattr(cfg, "rope_parameters", None) or {}
rope_theta = rope_parameters.get("rope_theta") or getattr(cfg, "rope_theta", None)
if rope_theta is not None:
self.cfg.rotary_base = rope_theta

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TransformerBridgeConfig doesn't recover rotary_base from rope_parameters, so removing that block leaves cfg.rotary_base = 10000 instead of the model's 5,000,000. Forward parity hides it because RoPE is delegated to HF's model.pos_emb, but anything reading cfg.rotary_base now gets a value that's off by 500×. This deletion also drops default_prepend_bos = False, which changes tokenization on every string-input path.

Can you restore the rope_parameters/rope_theta propagation and the default_prepend_bos = False line? The other deletions in that block are fine, eps, num_experts, experts_per_token, moe_intermediate_size, and layer_types all still reach cfg without the explicit copies. test_norm_and_rope_config and test_default_prepend_bos_is_false are currently failing because they caught these two issues, please fix the adapter rather than updating those two tests.

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.

2 participants