Skip to content

Add LFM2.5 (Liquid Foundation Model 2.5) support#3400

Merged
EricLBuehler merged 6 commits into
huggingface:mainfrom
Jacqkues:add-lfm2-model
Jun 8, 2026
Merged

Add LFM2.5 (Liquid Foundation Model 2.5) support#3400
EricLBuehler merged 6 commits into
huggingface:mainfrom
Jacqkues:add-lfm2-model

Conversation

@Jacqkues

@Jacqkues Jacqkues commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add candle-transformers/src/models/lfm2.rs: model implementation for LiquidAI's LFM2.5 hybrid architecture (attention + short convolution layers)
  • Add candle-examples/examples/lfm2/: example for text generation with LFM2.5-1.2B and LFM2.5-1.2B-Thinking variants
  • Register lfm2 module in candle-transformers/src/models/mod.rs

Model details

LFM2.5 is a hybrid architecture from LiquidAI that interleaves full attention layers with short convolution layers. Key features:

  • Per-head QK normalization with RoPE
  • Depthwise short convolution with B/C/X gating
  • SwiGLU MLP with computed intermediate size
  • KV cache (attention) + conv state cache (convolution) for efficient generation

Test plan

  • Compiles with cargo build --example lfm2 --release
  • Tested inference with LFM2.5-1.2B-Thinking on CPU (Apple Silicon) — generates coherent text at ~5.9 tokens/s

Supported models

Jacqkues and others added 2 commits March 9, 2026 19:33
Add model implementation and example for LiquidAI's LFM2.5 hybrid
architecture that combines attention and short convolution layers.

Supports LFM2.5-1.2B and LFM2.5-1.2B-Thinking variants.
@AYastrebov

Copy link
Copy Markdown

Any progress on this?

@EricLBuehler EricLBuehler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey @Jacqkues! Thanks for the PR.

This looks great, and I added a few small comments.

Comment thread candle-transformers/src/models/lfm2.rs Outdated
})
}

fn mask(&mut self, t: usize) -> Result<Tensor> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This caches masks only by t and builds a square (seq_len, seq_len) mask. But after a prefix cache, attention has shape (batch, heads, seq_len, index_pos + seq_len).

This will either fail to broadcast or apply the wrong mask for chunked continuation/prefix-cache use. As such, this should mirror existing Llama/quantized LFM2 behavior where we key by (seq_len, kv_len) and use crate::utils::build_causal_mask(seq_len, index_pos, device), with cache.mask(seq_len, index_pos) at the call site.

Comment thread candle-examples/examples/lfm2/main.rs Outdated
impl Which {
fn model_id(&self) -> &'static str {
match self {
Which::Lfm2_5_1_2B => "LiquidAI/LFM2.5-1.2B",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I dont see this model on HF Hub, but I did see LiquidAI/LFM2.5-1.2B-Instruct. Perhaps this is a typo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah yes it was a typo !

@Jacqkues Jacqkues requested a review from EricLBuehler June 8, 2026 15:14
Jacqkues and others added 2 commits June 8, 2026 18:30
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@EricLBuehler EricLBuehler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @Jacqkues!

@EricLBuehler EricLBuehler merged commit 3d3d9c4 into huggingface:main Jun 8, 2026
11 checks passed
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