Skip to content

Added Ouro architecture adapter and integration tests for OuroForCausalLM#1488

Merged
jlarson4 merged 4 commits into
TransformerLensOrg:devfrom
Canonik:add-Ouro-LoopLM-looped-depth-adapter-(OuroForCausalLM)
Jul 8, 2026
Merged

Added Ouro architecture adapter and integration tests for OuroForCausalLM#1488
jlarson4 merged 4 commits into
TransformerLensOrg:devfrom
Canonik:add-Ouro-LoopLM-looped-depth-adapter-(OuroForCausalLM)

Conversation

@Canonik

@Canonik Canonik commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a TransformerBridge architecture adapter for OuroForCausalLM (ByteDance Ouro / LoopLM), a looped-depth "Universal Transformer" decoder: one weight-tied stack of 24 physical layers is applied total_ut_steps=4 times per forward pass, with a learned early-exit gate scored alongside the LM head.

What"s included:

  • "supported_architectures/ouro.py, including a prepare_loadingpatch for two transformers-v5 incompatibilities in the Ouro remote code (written against 4.55): the removedROPE_INIT_FUNCTIONS["default"]entry, and the missingcompute_default_rope_parametersstatic method that the v5_init_weightsmachinery expects on rotary classes. Both patches are scoped to the importedmodeling_ouro` module; the shared transformers dict is untouched.
  • Four-site registration, an "ouro" model_type fallback in sources/transformers.py, and a "ByteDance/Ouro-" entry in _BRIDGE_REMOTE_CODE_PREFIXES in verify_models.py so registry verification auto-enables trust_remote_code.
  • A ByteDance/Ouro-1.4B registry row (status 0, null scores).
  • Unit adapter test (23 structural tests, runs in CI) and a gated integration test (slow + skipif(CI), QUARANTINES.md row) asserting logit parity against an independently loaded HF eager model at 1e-3, delegation identities, and the per-step hook firing count.

Verified locally on real Ouro-1.4B weights: 11/11 integration tests pass. Loading requires trust_remote_code=True; no new package dependencies.

Note for reviewers: plain AutoModelForCausalLM.from_pretrained on Ouro is currently broken under transformers v5 regardless of TransformerLens (the upstream remote code reads config.pad_token_id, which v5 no longer materializes). The bridge load path already shims this generically; the reference fixture in the integration test mirrors the same shim.

Fixes #1470

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

Comment thread tests/QUARANTINES.md Outdated
| [`unit/model_bridge/supported_architectures/test_gemma2_adapter.py`:49](unit/model_bridge/supported_architectures/test_gemma2_adapter.py) | "Network/disk fetch of tiny Gemma2" |
| [`integration/model_bridge/test_bridge_integration.py`:801](integration/model_bridge/test_bridge_integration.py) | "Skip Gemma2 in CI to avoid timeout" |
| [`acceptance/model_bridge/compatibility/test_hook_completeness.py`:156](acceptance/model_bridge/compatibility/test_hook_completeness.py) | "Gemma2 too large for CI" |
| [`integration/model_bridge/test_ouro_adapter.py`](integration/model_bridge/test_ouro_adapter.py) module-level (+ `slow` marker) | "ByteDance/Ouro-1.4B: 2.8GB download + ~11GB RAM, too large for CI" |

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.

Incredibly tiny nitpick, apologies, can you add the line number for the test to the link text similar to the other lines in this table?

@jlarson4

jlarson4 commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

This looks pretty good @Canonik! Just a couple small notes:

  1. Missing supports_fold_ln = False – compat mode corrupts the UT loop. Ouro applies model.norm (mapped as ln_final, a weighted RMSNorm) after EVERY UT pass, with the normed output feeding the next pass and the early-exit gate (modeling_ouro.py:592-608), it is not a final-only norm. The adapter leaves supports_fold_ln at the default True, so enable_compatibility_mode() / verify_models Phase 3 folds ln_final.w into W_U, resets the norm weight to ones in the live HF module the loop reuses, and corrupts passes 1..N-1.]. The fix is one line plus a comment: self.supports_fold_ln = False in __init__Related docstring note: ln_final hooks fire total_ut_steps× per forward and run_with_cache keeps only the last pass, worth a comment alongside the existing per-block note.

  2. Run verify_models on a sample model, if possible – no models have been verified thus far. The error documented above would've been caught by a verification pass. If you can't run the verification suite on your machine, no worries, just let me know and I can run the verification run & push the results.

  3. Surface total_ut_steps (and possibly early_exit_threshold) on bridge.cfg per the config-attr propagation rule. Then the integration test won't have to reach into hf_eager.config for it.

@Canonik

Canonik commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Thanks I’ll address these in a small follow-up commit.

For verify_models, I’ll try running it locally on the sample Ouro model and report back if I hit an OOM or any local machine limitation. I think I should be able to fit it cleanly, but I’ll confirm with the actual run.

…fication updates. Chore: formatting updates in .MD
@Canonik

Canonik commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author
  • 'verify_models' ran clean (Ouro-1.4B, P1-P4 = 100/100/100/95.9).
  • I applied the 'supports_fold_ln = False' fix with a unit test covering it.
  • Reworked the integration tests as requested: loop config attrs now read off bridge.cfg, plus a propagation test.
  • Fixed the QUARANTINES.md line anchor.

Should be ready to merge :)

@Canonik Canonik marked this pull request as ready for review July 8, 2026 10:01
@jlarson4

jlarson4 commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Looks awesome! Thank you @Canonik, merging now

@jlarson4 jlarson4 merged commit 8d01cbd into TransformerLensOrg:dev Jul 8, 2026
25 checks passed
@Canonik

Canonik commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Glad to hear 😊

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