Skip to content

Add GLM-5 DSA TransformerBridge adapter#1430

Merged
jlarson4 merged 5 commits into
TransformerLensOrg:devfrom
zeotrix:fix/issue-1406
Jun 24, 2026
Merged

Add GLM-5 DSA TransformerBridge adapter#1430
jlarson4 merged 5 commits into
TransformerLensOrg:devfrom
zeotrix:fix/issue-1406

Conversation

@zeotrix

@zeotrix zeotrix commented Jun 22, 2026

Copy link
Copy Markdown

Adds TransformerBridge support for GlmMoeDsaForCausalLM / GLM-5 DSA.

This adds a GLM-MoE-DSA architecture adapter, including a dedicated DSA attention bridge for MLA-style latent attention plus learned top-k sparse-token selection. The adapter is
registered in the required architecture factory and model-registry surfaces, and tiny-random/glm-5.1 is added and verified in the Bridge registry.

Fixes #1406

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots

Not applicable.

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

Validation

Ran:

.venv/bin/pycln --all . --exclude "__init__.py"
.venv/bin/isort --check-only transformer_lens/model_bridge/generalized_components/glm_moe_dsa_attention.py transformer_lens/model_bridge/supported_architectures/glm_moe_dsa.py tests/
unit/model_bridge/supported_architectures/test_glm_moe_dsa_adapter.py tests/integration/model_bridge/test_glm_moe_dsa_adapter.py
.venv/bin/mypy .
.venv/bin/python -m pytest tests/unit/model_bridge/supported_architectures/test_glm_moe_dsa_adapter.py tests/integration/model_bridge/test_glm_moe_dsa_adapter.py tests/unit/tools/
test_model_registry.py -k 'TestGlmMoeDsa or TestGlmMoeDsaBridge or TestRegistrySyncedWithFactory' -q

Result: 11 passed.

Model registry verification:

.venv/bin/python -m transformer_lens.tools.model_registry.verify_models --model tiny-random/glm-5.1

The benchmark reported:

VERIFIED: P1=100.0%, P2=100.0%, P3=85.0%, P4=70.0%

Notes:

- make format and uv run mypy . are blocked locally by a resolver/build issue in the default jupyter dependency group: jupyter-ydoc -> y-py==0.6.2.
- The direct .venv tools above pass.
- verify_models updated supported_models.json and verification_history.json, then exited nonzero during cleanup due to an existing torch.mps.synchronize() call on a machine without an
MPS backend.
- black hung locally even when run only on the touched Python files, so I interrupted it.

@jlarson4

jlarson4 commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for putting this together! A couple small adapter notes:

  • Please set supports_fold_ln=False on the adapter. The default for adapters is supports_fold_ln=True. MLA latent projections can't fold, so right now folding is attempted and P3 fails (layer_norm_folding/value_bias_folding/weight_modification). Setting it to false skips those tests and resolves the "verified with failing phase" status.
  • test_forward_matches_hf uses seq_len=4 with index_topk=4. The top-k selector picks every token and the DSA mask is a no-op. The test validates dense MLA, but never the sparse path. Please bump the sequence length above index_topk (e.g. seq 8, top-k 4) so the mask actually drops tokens and a sparse-masking bug can be caught.

Also, just a heads up, make sure you pull before you make edits. I merged the latest dev into your branch to ensure you have all the latest changes and to resolve any conflicts with supported_models

@zeotrix

zeotrix commented Jun 24, 2026

Copy link
Copy Markdown
Author

Thanks @jlarson4, addressed both notes.

  • Set supports_fold_ln = False on GlmMoeDsaArchitectureAdapter and added a unit assertion for it.
  • Updated the GLM-MoE-DSA integration coverage to use seq_len=8 with index_topk=4, so the DSA sparse path is exercised. I also added cache assertions that hook_topk_indices keeps
    top-k size 4 and that hook_dsa_mask contains both masked -inf entries and unmasked zero entries.

Validation: git diff --check passes locally. Focused pytest is still blocked in my local env by dependency setup issues, but the changes are limited to the requested adapter flag and sparse-path test coverage.

@jlarson4 jlarson4 merged commit f02aaef into TransformerLensOrg:dev Jun 24, 2026
25 checks passed
@jlarson4

Copy link
Copy Markdown
Collaborator

Looks great! Merged. Thanks @zeotrix

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