Skip to content

Add LiquidAI LFM2.5 hybrid model support - #462

Merged
justinchuby merged 10 commits into
mainfrom
justinchuby-add-lfm2-5-support
Aug 13, 2026
Merged

justinchuby merged 10 commits into
mainfrom
justinchuby-add-lfm2-5-support

Conversation

@justinchuby

@justinchuby justinchuby commented Aug 7, 2026 •

Copy link
Copy Markdown
Member

Summary

  • add lfm2 support for LiquidAI/LFM2.5-230M following upstream Transformers
  • implement mixed double-gated short-convolution and QK-normalized GQA layers
  • use native ONNX Swish, com.microsoft::CausalConvWithState, and residual SkipSimplifiedLayerNormalization fusions
  • wire hybrid KV/convolution cache, weight preprocessing, registry/config extraction, CLI export, and ORT GenAI
  • add representative L1, real-checkpoint L2, synthetic/real-weight L3, and pinned L4/L5 coverage

Upstream references:

Architecture fidelity

  • 14 decoder layers: 8 convolution + 6 full GQA
  • convolution: B*x -> causal depthwise conv -> C*conv -> out_proj
  • MLP: w2(Swish(w1(x)) * w3(x))
  • attention: per-head Q/K RMSNorm before RoPE, 16 query / 8 KV heads
  • tied token embedding / LM head
  • RMSNormalization(stash_type=FLOAT) matches Transformers exactly: normalize in fp32, cast normalized activations to input dtype, then apply gamma

Fused graph

Weighted optimized graph counts:

dtype / EP nodes Swish CausalConvWithState SkipSimplifiedLayerNormalization GroupQueryAttention plain Conv
fp32 / default 305 14 8 28 0 0
fp16 / CUDA 290 14 8 28 6 0

The fused causal-conv op uses the exact K-1 recurrent history, supports prefill/decode, executes on CUDA, and produced 0 Memcpy events in profiling. Cache-slot counting is graph-derived as max(past_key_values layer index)+1, covering KV-sharing and hybrid recurrent-cache models without a model-type condition.

Validation

lintrunner -a
# no issues

python -m pytest src/mobius/integrations/ort_genai/genai_config_test.py src/mobius/integrations/ort_genai/auto_export_test.py -q
# 152 passed

python -m pytest src/mobius/models/lfm2_test.py src/mobius/components/_short_conv_test.py tests/build_graph_test.py tests/synthetic_parity_test.py -k lfm2 -q
# 10 passed

python -m pytest tests/integration_test.py -m integration_fast -k 'lfm2.5-230m' -q
# 3 passed

python -m pytest tests/e2e_golden_test.py -m 'golden or generation' --models lfm2 -q
# 2 passed

python -m pytest tests/ort_genai_test.py -m integration_slow -k lfm2 -q
# 1 passed

$env:MOBIUS_TEST_DEVICE='cuda'
python -m pytest tests/integration_test.py -m integration -k 'lfm2.5-230m' -q
# 3 passed (CUDA prefill, cached decode, 20-token generation)

CUDA profile for the fused convolution: 8 CausalConvWithState events, all assigned to CUDAExecutionProvider, 0 Memcpy. Outputs were finite.

Quality checklist

  • architecture/config/weight mapping and hybrid cache behavior
  • L1/L2/L3 and pinned L4/L5
  • real-weight prefill, cached decode, and deterministic generation
  • fp32/fp16/bf16 and actual CUDA EP validation
  • ORT GenAI load/generation
  • full lintrunner -a
  • graph simplicity/fusion audit
  • no protobuf APIs

Remaining infrastructure limitations

  • Foundry Local and Olive are not installed in this environment; those deployment/quantization smoke tests remain deferred.

@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 7, 2026 23:51
Comment thread src/mobius/models/lfm2.py Fixed
Comment thread src/mobius/models/lfm2.py Fixed
@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing 0ea089b → 9b462db

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 105 105 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 54 54 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 60 60 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 56 56 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 94 94 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 58 58 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 54 54 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 60 60 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 264 264 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 126 126 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 428 428 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@github-actions

github-actions Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 0ea089b → 9b462db

Model Sub-model Changes Status
bert (feature-extraction) model 0 ⚪
falcon model 0 ⚪
gemma2 model 0 ⚪
gemma4 (gemma4) decoder 0 ⚪
gemma4 (gemma4) embedding 0 ⚪
gemma4 (gemma4) vision_encoder 0 ⚪
gemma4_text model 0 ⚪
gpt2 model 0 ⚪
llama model 0 ⚪
llama (static-cache) model 0 ⚪
mamba (ssm-text-generation) model 0 ⚪
phi3 model 0 ⚪
phi3 (static-cache) model 0 ⚪
qwen model 0 ⚪
qwen (static-cache) model 0 ⚪
qwen2 model 0 ⚪
qwen2 (static-cache) model 0 ⚪
qwen2_moe model 0 ⚪
qwen2_moe (static-cache) model 0 ⚪
qwen3 model 0 ⚪
qwen3 (static-cache) model 0 ⚪
qwen3_5_moe (hybrid-text-generation) model 0 ⚪
qwen3_5_text (hybrid-text-generation) model 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) decoder 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) embedding 0 ⚪
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0 ⚪
qwen3_moe model 0 ⚪
qwen3_moe (static-cache) model 0 ⚪
qwen3_next (hybrid-text-generation) model 0 ⚪
t5 (seq2seq) decoder 0 ⚪
t5 (seq2seq) encoder 0 ⚪
whisper (speech-to-text) decoder 0 ⚪
whisper (speech-to-text) encoder 0 ⚪

No architecture changes detected. ✅


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds first-class support for LiquidAI’s LFM2.5 hybrid Conv+GQA architecture to mobius, including its hybrid cache contract and ORT GenAI packaging metadata, plus multi-tier validation coverage and goldens.

Changes:

  • Introduces an lfm2 model implementation with mixed short-convolution and full-attention layers, plus weight key remapping for upstream naming differences.
  • Adds a reusable double-gated depthwise short convolution component with a full-kernel recurrent cache (aligned to ORT GenAI’s LFM2 cache contract).
  • Extends test/config/registry + ORT GenAI config generation to recognize LFM2 hybrid cache I/O and validate deterministic generation.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/synthetic_parity_test.py Adds HF config translation for lfm2 and filters conv-specific config keys for synthetic parity.
tests/ort_genai_test.py Adds an integration test that exports LFM2.5 and validates deterministic ORT GenAI generation.
tests/integration_test.py Extends feed construction to handle per-layer conv_state inputs/outputs for conv layers.
tests/build_graph_test.py Verifies hybrid-cache output naming for conv layers (present.{i}.conv_state).
tests/_test_configs.py Adds a representative tiny lfm2 config for graph-build/unit coverage.
testdata/golden/causal-lm/lfm2_5-230m.json Adds pinned golden logits/top-k snapshot for LFM2.5-230M.
testdata/golden/causal-lm/lfm2_5-230m_generation.json Adds pinned deterministic 20-token generation golden for LFM2.5-230M.
testdata/cases/causal-lm/lfm2_5-230m.yaml Adds an L4/L5 real-checkpoint case pinned to a specific HF revision.
src/mobius/tasks/_cache_utils.py Updates hybrid cache input shapes for conv layers to store a full kernel-wide window.
src/mobius/models/lfm2.py Implements Lfm2CausalLMModel + mixed conv/attention decoder layers and projection key remapping.
src/mobius/models/init.py Exports Lfm2CausalLMModel.
src/mobius/integrations/ort_genai/genai_config.py Adds LFM2-specific decoder metadata (layer_types/conv cache) and disables share-buffer mode.
src/mobius/integrations/ort_genai/genai_config_test.py Tests that LFM2 genai_config declares hybrid conv cache fields correctly.
src/mobius/integrations/ort_genai/auto_export.py Maps mobius lfm2 to ORT GenAI model type lfm2.
src/mobius/components/_short_conv.py Adds GatedShortConv implementing the double-gated depthwise causal short-conv with recurrent state.
src/mobius/components/_short_conv_test.py Adds a unit test to ensure the short-conv component builds a stateful graph and exposes expected params.
src/mobius/components/init.py Exports GatedShortConv via the public components API.
src/mobius/_testing/torch_reference.py Extends HF reference execution to support opaque hybrid Cache objects for conv/hybrid models.
src/mobius/_registry.py Registers lfm2 model type, test model id, and dashboard family/category mappings.
src/mobius/_configs/_base.py Adds short-conv config fields and extracts them from HF configs (conv_L_cache/conv_bias), plus lfm2 defaults.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Suppressed comments (2)

testdata/cases/causal-lm/lfm2_5-230m.yaml:3

  • This SHA does not actually pin the L4/L5 run: GoldenTestCase.revision is parsed, but tests/e2e_golden_test.py::_build_model_package calls build(case.model_id, ...) without using it, and build() has no revision parameter. The golden tests therefore load the repository's current default revision and can drift from these committed logits/tokens. Resolve this revision to a local snapshot before building (or thread a revision argument through build) so the advertised pinned coverage is real.
revision: "13a53837c4906b4f7405932532ba85d182bb013b"

tests/ort_genai_test.py:233

  • This deterministic exact-token test resolves both weights and tokenizer artifacts from the Hub's current default revision, so an upstream update can invalidate the hard-coded sequence. Use the same pinned checkpoint revision as the golden case and pass its local snapshot to both build and write_ort_genai_config.
    model_id = "LiquidAI/LFM2.5-230M"
    pkg = build(model_id, dtype="f32", load_weights=True)
    output_dir = str(tmp_path / "lfm2")
    pkg.save(output_dir)
    write_ort_genai_config(pkg, output_dir, hf_model_id=model_id)

Comment thread src/mobius/_configs/_base.py Resolved
@justinchuby

Copy link
Copy Markdown
Member Author

Can you set stash type for the RMS norm op? We would prefer fused ops.

@justinchuby justinchuby left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reviewed the current diff. No additional high-confidence findings beyond the existing unresolved block_auto_adjust_ff_dim MLP-width thread.

Comment thread src/mobius/_configs/_base.py Fixed
@justinchuby
justinchuby force-pushed the justinchuby-add-lfm2-5-support branch from e69eccb to 4356c24 Compare August 13, 2026 20:42
justinchuby and others added 9 commits August 13, 2026 14:12
Implement the hybrid double-gated short-convolution and QK-normalized GQA architecture, including recurrent cache and ORT GenAI wiring. Add synthetic and real-weight parity, pinned L4/L5 goldens, CLI/runtime coverage, and dtype validation.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Compute LFM2 RMS variance in float32 before casting back for gamma, matching Transformers for decoder, final, and QK norms. This restores deterministic fp16 CUDA generation parity.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Use only the K-1 cached values required by causal convolution so Conv emits exactly the current token span. Replace dynamic length arithmetic with equivalent negative slices and equal splitting, removing redundant shape, subtraction, slicing, and constant nodes while preserving the K-wide ORT GenAI cache contract.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Use the public INT64_MAX component constant for all LFM2 short-convolution slices, removing duplicated magic bounds identified during the optimized-graph audit.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Keep config-only changes conservative, but let new model implementations use import-graph affected-model selection. This prevents LFM2 PRs from running the entire GPU golden catalog while preserving run-all behavior for standalone test config and unmapped task changes.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Match Transformers by applying the two-thirds scale, configured multiplier, and block rounding before constructing LFM2 MLP projections. Exercise the default auto-adjust path in synthetic parity and cover the 6656-to-4608 width mapping.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Use a noun-phrase property docstring so Ruff D421 accepts the effective FFN width accessor.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Apply the current Ruff formatter to the reviewed effective FFN width calculation.

Co-authored-by: Copilot <[email protected]>
Signed-off-by: justinchuby <[email protected]>
Keep ORT GenAI's LFM2 layer count aligned with global decoder indices after main introduced KV-only cache counting for KV-sharing models.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby
justinchuby force-pushed the justinchuby-add-lfm2-5-support branch from 4356c24 to 1d66402 Compare August 13, 2026 21:16
Use RMSNormalization stash_type for faithful fp32 accumulation and residual skip-norm fusion. Replace the decomposed short convolution with CausalConvWithState and derive global cache slots directly from graph input indices.

Co-authored-by: Copilot App <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
@justinchuby

Copy link
Copy Markdown
Member Author

Shared inplace buffer support will need to be added to ort-genai.

@justinchuby
justinchuby merged commit a2e0ab7 into main Aug 13, 2026
21 of 22 checks passed
@justinchuby
justinchuby deleted the justinchuby-add-lfm2-5-support branch August 13, 2026 21:50
justinchuby added a commit that referenced this pull request Aug 14, 2026
## Summary

- distill post-single-shot lessons from the Parakeet CTC, Mage-VL,
Nemotron Parse, LFM2.5, Moonshine, MiniCPM-V, Qwen Image Edit, and Muse
Glimmer integrations
- tighten source/config/revision fidelity, real processor and runtime
contracts, semantic multi-dtype validation, exact golden testing, and
weighted graph optimization evidence
- add precise CI baseline triage, targeted GPU validation, linear
rebase/worktree guidance, quantization schema checks, and executable
diffusion pipeline requirements
- shorten the duplicated multimodal float32 input section and resolve
contradictory encoder/component import guidance

## Sources

Direct agent retrospectives plus commit/review history for merged PRs
#462-#465, #471-#473, and #475.

## Validation

- documentation diff is whitespace-clean
- initialized repository-pinned Ruff/lintrunner tooling
- independent rubber-duck review found no blocking issues; follow-up
consistency suggestions were applied

No runtime code is changed.

---------

Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
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.

3 participants