Skip to content

Add LFM2 hybrid model support#2410

Open
ykhrustalev wants to merge 1 commit intomicrosoft:mainfrom
ykhrustalev:ykhrustalev/lfm2
Open

Add LFM2 hybrid model support#2410
ykhrustalev wants to merge 1 commit intomicrosoft:mainfrom
ykhrustalev:ykhrustalev/lfm2

Conversation

@ykhrustalev
Copy link
Copy Markdown

Describe your changes

Add LFM2 hybrid model support. LFM2 interleaves attention and conv layers — conv layers lack self_attn.

wrapper.py: Add "lfm2" submodule name mappings to LayerWrapper (layer norms, MLP, attention output) and ModelWrapper (PRE_HEAD_LAYERNORM). LFM2 uses non-standard names (operator_norm, ffn_norm, feed_forward, w1/w2/w3, out_proj, embedding_norm).

rotate.py: Skip fuse_ln_linear when no linears are passed. Previously it reset layernorm weights to 1.0 even with an empty list, corrupting conv layer norms.

test_hf_wrapper.py: Add test using tiny-random/lfm2 — verifies both attention and conv layers resolve correctly.

Checklist before requesting a review

  • Add unit tests for this change.
  • Make sure all tests can pass.
  • Update documents if necessary. (No doc changes needed — no model list in docs.)
  • Lint and apply fixes to your code by running lintrunner -a
  • Is this a user-facing change? If yes, give a description of this change to be included in the release notes.

Release note: Added LFM2 hybrid model support for quantization passes (SelectiveMixedPrecision, QuaRot/SpinQuant).

(Optional) Issue link

N/A

@ykhrustalev
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree [company="{Liquid AI}"]

@ykhrustalev
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="Liquid AI"

LFM2 is a hybrid SSM+Attention model where conv layers lack self_attn.
The existing fail_on_not_found=False for attention (added for Qwen3.5)
handles the missing self_attn gracefully, but LFM2 needs its own
submodule name mappings since it uses non-standard names (operator_norm,
ffn_norm, feed_forward, w1/w2/w3, out_proj).

Also fix fuse_ln_linear in rotate.py to skip resetting layernorm weights
when no linear layers were fused (prevents corrupting conv layer norms
in hybrid models).
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.

1 participant