Repository navigation
feat(lfm3): add LFM3, LFM3-VL and LFM3-Omni quantization support - #3496
Merged
Merged
Conversation
Add model definitions for the LiquidAI LFM3 family: - `lfm3` (LFM3-1.7B): tri-hybrid decoder that alternates depthwise short-conv, full-attention and sliding-attention layers. - `lfm3_vl` (LFM3-VL-2B): LFM3 text decoder plus vision tower and multimodal projector. - `lfm3_omni` (LFM3-Omni-2B): LFM3 text decoder plus audio encoder, codebook embedding, depth decoder, vision tower and projectors. Only the text decoder's linear projections are quantized. The depthwise conv kernel, RMSNorm weights and the per-head sigmoid `gate_proj` keep their checkpoint dtype, as do the vision/audio towers and projectors. LFM3 builds one `position_embeddings` and one mask per `layer_type` in the outer `Lfm3Model.forward`, so isolated decoder replay has to rebuild them. A forward pre-hook on the text model captures the raw `attention_mask`/`position_ids`; `prepare_layer_replay_kwargs` then regenerates the rotary state and the matching `create_recurrent_attention_mask` / `create_causal_mask` / `create_sliding_window_causal_mask` result, naming the first layer of each type the way the checkpoint's `create_masks_by_layer_type` does. The checkpoints ship as remote-code (`auto_map`) models, so the definitions require `trust_remote_code=True`. Tests: `tests/test_lfm3_support.py` covers model-type dispatch, the module tree, the multimodal base modules and the conv-vs-attention replay kwargs. `tests/models/test_lfm3*.py` add `ModelTest` eval baselines (arc_challenge) plus an image-description check for the VL model. No quantization math, packer or inference kernel changes; no dense or expanded weight cache is introduced.
ZX-ModelCloud
marked this pull request as ready for review
November 3, 2026 05:15
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add quantization support for the LiquidAI LFM3 family:
LiquidAI/LFM3-1.7B— model typelfm3LiquidAI/LFM3-VL-2B— model typelfm3_vlLiquidAI/LFM3-Omni-2B— model typelfm3_omniLFM3 is a tri-hybrid decoder that interleaves depthwise short-conv layers,
full-attention layers and sliding-window-attention layers. GPT-QModel already
handles hybrid stacks for other families, but LFM3 has two properties that need
new plumbing:
position_embeddingsand one mask perlayer_typein the outerLfm3Model.forward, not inside each decoder layer. Layer-by-layerquantization replay therefore has to rebuild them.
auto_map) models. Neithertransformers 5.20 nor 5.22 has native LFM3 classes, so the definitions
require
trust_remote_code=True.What Changed
gptqmodel/models/definitions/lfm3.py—LFM3QModelforLiquidAI/LFM3-1.7B.A forward pre-hook on the text model captures the raw
attention_mask/position_ids;prepare_layer_replay_kwargsthenregenerates the rotary state and the matching
create_recurrent_attention_mask/create_causal_mask/create_sliding_window_causal_maskresult, naming the first layer of eachtype the way the checkpoint's
create_masks_by_layer_typedoes.gptqmodel/models/definitions/lfm3_vl.py—LFM3VLQModel(LFM3 text decoder + vision tower + multimodal projector).
gptqmodel/models/definitions/lfm3_omni.py—LFM3OmniQModel(LFM3 text decoder + audio encoder + codebook embedding + depth decoder +
vision tower/projectors).
gptqmodel/models/auto.py,gptqmodel/models/definitions/__init__.py—register
lfm3,lfm3_vl,lfm3_omni.README.md— add the LFM3 row to the supported-models table.tests/— see below.Quantized surface: only the text decoder's linear projections. The
depthwise conv kernel, RMSNorm weights and the per-head sigmoid
gate_projkeep their checkpoint dtype, as do the vision/audio towers and projectors.
Behavior changes: none for existing models.
LFM3*requirestrust_remote_code=True, matching how the upstream checkpoints are published.Out of scope: no new quantization kernels or backends; no changes to
packer, config or eval framework.
Tests
tests/test_lfm3_support.py, 17 tests).ModelTestbaselines onarc_challenge(INT4,marlinbackend, 20 calibrationsamples, slow seat
floor_pct: 0.05):Non-quantized
LFM3-1.7Barc_challenge baseline (no chat template):0.3404 / 0.3567 — the slow-mode INT4 score is within ~1.4 pt of that, i.e. no
quantization regression. The VL test additionally asserts the decoded image
description mentions "snow" (test image
tests/models/ovis/10016.jpg).Smoke runs on ROCm (AMD R9700, 4×, GPUs 2-3 only, env
gp_314t_rocm):quantize → save → reload → generate works for all three models
(
LFM3-1.7Banswers "Paris"; VL and Omni describe the snow mountains).Tokenizer parity: chat-template render and resulting input IDs are identical to
AutoTokenizerfor all three checkpoints; no Tokenicer change was needed.Review Requirements
Kernel Accuracy Requirements
change. This PR only adds model definitions (module tree, layer replay
behavior, eval baselines). No dense/dequantized weight cache is added or
retained; quantized inference storage is unchanged.
Notes
causal_conv1dhas no wide kernelfor that shape, so the torch fallback path is used on Ampere/Ada
(verified on RTX 4090).
generateforLFM3-OmnireturnsLfm3OmniGenerateOutput; index[0]toreach the tensor. The tests do this.
The model weights are not tiedwarning appears at load time;embedding and
lm_headare tied at the checkpoint level. This is pre-existingbehavior, not introduced here.
auto.check_and_get_model_definitionrequirestrust_remote_code=Trueto bepassed explicitly for these checkpoints.