Repository navigation
Add LiquidAI LFM2.5 hybrid model support - #462
Conversation
Performance Comparison
|
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
There was a problem hiding this comment.
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
lfm2model 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.
There was a problem hiding this comment.
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.revisionis parsed, buttests/e2e_golden_test.py::_build_model_packagecallsbuild(case.model_id, ...)without using it, andbuild()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 throughbuild) 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
buildandwrite_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)
|
Can you set stash type for the RMS norm op? We would prefer fused ops. |
justinchuby
left a comment
There was a problem hiding this comment.
Reviewed the current diff. No additional high-confidence findings beyond the existing unresolved block_auto_adjust_ff_dim MLP-width thread.
e69eccb to
4356c24
Compare
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]>
4356c24 to
1d66402
Compare
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]>
|
Shared inplace buffer support will need to be added to ort-genai. |
## 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]>
Summary
lfm2support forLiquidAI/LFM2.5-230Mfollowing upstream Transformerscom.microsoft::CausalConvWithState, and residualSkipSimplifiedLayerNormalizationfusionsUpstream references:
Architecture fidelity
B*x -> causal depthwise conv -> C*conv -> out_projw2(Swish(w1(x)) * w3(x))RMSNormalization(stash_type=FLOAT)matches Transformers exactly: normalize in fp32, cast normalized activations to input dtype, then apply gammaFused graph
Weighted optimized graph counts:
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
CUDA profile for the fused convolution: 8
CausalConvWithStateevents, all assigned toCUDAExecutionProvider, 0 Memcpy. Outputs were finite.Quality checklist
lintrunner -aRemaining infrastructure limitations