Hugging Face、CPU での高速長文脈推論向けエンコーダー「LFM2.5」を公開
Liquid AI は Hugging Face Blog で、CPU 上で高速な長文脈推論を可能にする LFM2.5-Encoders を発表し、GPU 依存からの脱却とコスト削減への道筋を示した。
AI深層分析を開く2026年7月29日 00:23
AI深層分析
キーポイント
LFM2.5-Encoders の発表
Liquid AI が CPU 環境向けに最適化された LFM2.5-Encoders を公開し、長文脈処理の効率化を実現した。
CPU での高速推論の実現
同技術は GPU などの専用アクセラレータを必要とせず、汎用 CPU 上で高速な長文脈推論を可能にする。
コスト削減とアクセシビリティ向上
高価な GPU インフラへの依存度を下げることで、開発者や企業の AI 導入におけるコスト負担を軽減する。
マスク言語モデルとしての推論
コード例は、フランスの首都を予測するタスクでマスクトークンを埋めるMLM(Masked Language Model)としての使い方を示している。
下流タスクへの拡張性
下流タスクではエンコーダ本体を読み込み、分類や検索などの独自のヘッドを接続して利用することが可能である。
重要な引用
LFM2.5-Encoders for Fast Long-Context Inference on CPU
Back to Articles
For downstream tasks, load the encoder body and attach your own head (classification, token classification, regression, retrieval):
A base encoder gives you general-purpose representations, not task outputs. So you fine-tune it for each task.
編集コメントを表示
編集コメント
GPU 依存からの脱却を目指すこのアプローチは、インフラコストに悩む多くの開発者にとって朗報である。特に長文脈処理が必要なアプリケーションにおいて、CPU 環境での実用化が現実味を帯びてきたと言える。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
記事一覧に戻る
- 汎用エンコーダーを構築した理由
- エンコーダーの仕組み
- ベンチマーク結果
- CPU と GPU での推論速度
- LFM2.5-Encoder のデモ
- LFM2.5-Encoders の使い方とファインチューニング
- モデルのロードと実行
- タスク別ファインチューニング
- LFM2.5-Encoders の始め方
- 引用
本日、Hugging Face で新しいエンコーダーモデル 2 つを公開しました。LFM2.5-Encoder-230M と LFM2.5-Encoder-350M です。これらはより大規模なモデルに匹敵する品質を持ちながら、入力長が伸びても高速性を維持します。つまり、既存のハードウェア、CPU 上でもドキュメントレベルの処理を効率的に行えます。
主な特徴は以下の通りです:
- サイズに対して強力:GLUE や SuperGLUE、多言語タスクにおいて大規模なエンコーダーと同等かそれ以上の性能を発揮します。
- 8,192 トークンのコンテキスト長:入力長が伸びても遅延の増加は緩やかです。
- CPU で高速:長いコンテキストでは ModernBERT-base より約 3.7 倍速く動作します。
これらを活用すれば、意図ルーター、ポリシーリンター、PII(個人識別情報)検出器、テキスト分類器などを低コストで常時稼働させることが可能です。以下のライブデモをご覧ください。
汎用エンコーダーを構築した理由
先月、多言語検索向けに設計された「LFM2.5-Retrievers」をリリースしました。LFM2.5-Encoders も同じファミリーに属しますが、より幅広い用途を想定しています。
このエンコーダーはマスク付き言語モデルの目的で事前学習されているため、分類やトークンレベルのタスク、検索など、さまざまな用途に合わせてファインチューニングが可能です。検索はその機能の一つに過ぎません。そのため、既存のリトリーバーを流用するのではなく、汎用的なモデルとして新たに構築しました。
エンコーダーは、現代の生産環境における NLP アプリケーションを支える基盤です。分類器や意図ルーター、安全性フィルターなどがその代表例で、これらは CPU 上で長時間稼働し、入力長も年々伸びています。この種のモデルを確立したのは BERT であり、最近では ModernBERT が精度と速度、そしてコンテキストの長さにおいてさらに進化させました。
LFM2.5-Encoders は LFM2 アーキテクチャの次のステップです。入力長が増大してもコストが緩やかに上昇する設計となっています。
エンコーダーの構築方法
エンコーダーは、それぞれの LFM2 デコーダーバックボーンから初期化されます。具体的には LFM2.5-230M と LFM2.5-350M です。その後、いくつかの変更を加えることで、因果関係のあるデコーダーを双方向性のエンコーダーへと変換します。
- 双方向アテンションマスク:各トークンは、それ以前に存在するトークンだけでなく、前後のすべてのトークンを参照できるようになります。
- 非因果的な短距離畳み込み:対称的にパディングを行うことで、各トークンの畳み込み計算において、左右両側の近傍トークンを混合処理します。
マスキド言語モデリングでは、トレーニング中にトークンの 30% をマスクします。
両モデルは 2 つの段階で学習を行います。
- 汎用的な言語能力:1,024 トークンという短いコンテキストで、大規模なウェブコーパスを用いたマスキド言語タスクを学習します。
- 長文コンテキストへの適応:データセット全体を使用してコンテキスト長を 8,192 トークンに拡張し、事実性、法的知識、多言語能力を強化します。
ベンチマーク結果
各モデルはすべてのタスクに対してフルチューニングを行い、その結果のスコアを報告しています。表には GLUE、SuperGLUE、および多言語分類から抽出された 17 のタスクにおける 14 モデルの結果が含まれています。
5 つのホールドアウトシード(検証用データセット)での平均値を報告しており、ランごとの数値は安定しています。完全なフレームワークと生データは オープンソース として公開されています。
LFM2.5-Encoder-350M は 14 モデル中 4 位を記録しました。それより上位の 3 モデルはいずれもサイズが大きく、その中には LFM2.5-Encoder-350M の約 10 倍の規模を持つ 3.5B モデルも含まれています。一方、LFM2.5-Encoder-230M は ModernBERT-base やすべての EuroBERT モデルを上回る性能を示しながら、それらの多くよりも小型です。両モデルとも、当社の LFM2.5-Retrievers よりもはるかに高いスコアを記録しています。
CPU および GPU における推論速度
本エンコーダーは、LFM2 バックボーンが持つ高速な推論機能を継承しています。両エンコーダーと ModernBERT はいずれも 8,192 トークンのコンテキストをサポートしているため、全範囲にわたる速度を測定しました。
エンコーダーの最大の強みは CPU 上でのパフォーマンスです。LFM2.5-Encoder-230M は、あらゆるシーケンス長において最速を誇ります。短い入力では、より小さなモデルである ModernBERT-base をも凌駕します。
入力長が増えるにつれて ModernBERT のスループットは急激に低下する一方、LFM2.5-Encoders は中堅クラスへと上昇し、その後緩やかに落ち着きます。8,192 トークンという長さでは、ModernBERT-base は順次処理に 1 分半以上を要しますが、LFM2.5-Encoder-230M は約 28 秒で完了します。これは約 3.7 倍の速度差です。
開発者にとって、これはラップトップの CPU で契約書や議事録、あるいは長いサポートスレッドを 30 秒未満でスキャンまたは分類できることを意味します。
GPU 上でも同様の傾向が見られますが、その差は CPU に比べると小さくなります。Apple GPU では約 1,000 トークン未満の領域で ModernBERT-base がリードしますが、LFM2.5-Encoders は約 2,000 トークンから逆転して優位に立ちます。つまり、長い入力テキストを扱う場合、LFM2.5-Encoders がより高速な選択肢となるのです。特に CPU で動作させる場合は、その差が顕著になります。
LFM2.5-Encoder のデモ
以下のデモは、ファインチューニングされた LFM2.5-Encoders を使用して構築しました。いずれも CPU 専用の Hugging Face Space で実行可能です。
- ゼロショットプロンプトラウティング:ルーティングの経路を自由テキストで定義できます。モデルは一度のパスで、入力全体を各経路に対してスコアリングします。
- ゼロショットポリシーリンティング:企業のルールを自由テキストとして記述し、その内容と照合してチェックできます。すべてのトークンをすべてのルールに対して一度にスコアリングします。
- スペルチェック:誤字をトークン単位で修正します。
- PII 検出:16 か国語にわたる 40 種類の個人情報を特定・除去します。
- マスク付き拡散テキスト生成(ボーナス機能):エンコーダーをチャットボットとして実行し、左から右へ順に処理するのではなく、反復的にマスクを解除することでテキストを生成します。
LFM2.5-Encoder の使い方とファインチューニング
分類、ルーティング、抽出、スコアリングなど、高頻度で継続して実行され、かつ低コスト・高速性が求められる理解タスクには、LFM2.5-Encoder が最適です。こうした用途では、生成モデルである LLM と比較して、ファインチューニング済みのエンコーダーの方がサイズが小さく処理も速く、既存の CPU 環境でも安価に稼働できます。
2 つのモデルサイズから選ぶ際の目安は以下の通りです。
- LFM2.5-Encoder-350M:精度を最優先する場合に選択してください。
- LFM2.5-Encoder-230M:ハードウェア制約が厳しい場合や、スループットを最大化したい場合に適しています。
数行のコードで始められます。transformers ライブラリを使ってモデルを読み込み、そのままマスクされたトークンの予測を実行するか、独自のヘッドを追加してタスクに合わせてファインチューニングしてください。
モデルの読み込みと実行
最新の transformers をインストールします:
pip install -U transformers
マスク付きトークン予測を実行するコード例:
from transformers import AutoModelForMaskedLM, AutoTokenizer
import torch
model_id = "LiquidAI/LFM2.5-Encoder-230M" # または "LiquidAI/LFM2.5-Encoder-350M"
tok = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
mlm = AutoModelForMaskedLM.from_pretrained(model_id, trust_remote_code=True)
text = f"フランスの首都は {tok.mask_token} です。"
enc = tok(text, return_tensors="pt")
with torch.no_grad():
logits = mlm(**enc).logits
pos = (enc["input_ids"][0] == tok.mask_token_id).nonzero()[0].item()
print([tok.decode([t]).strip() for t in logits[0, pos].topk(5).indices.tolist()])
-> ['Paris', 'Strasbourg', 'Paris', 'Lyon', 'Versailles']
下流タスクでは、エンコーダー本体を読み込み、独自のヘッド(分類、トークン分類、回帰、検索)を接続します。
from transformers import AutoModel
body = AutoModel.from_pretrained(model_id, trust_remote_code=True)
GPU が Flash Attention 2 をサポートしている場合は、最高効率で利用できます。
pip install flash-attn
タスク向けファインチューニング
ベースとなるエンコーダーは汎用的な表現を提供するものであり、タスク固有の出力を直接生成するものではありません。そのため、各タスクに合わせてファインチューニングを行う必要があります。当社の ファインチューニングチュートリアル では、8k のコンテキスト長を持つ法律文書を用いたファインチューニングの手順を詳しく解説しています。
LFM2.5-Encoders の活用開始
両方のエンコーダーはオープンウェイトであり、本日すぐに Hugging Face で利用可能です。
- ダウンロード: Hugging Face で「LFM2.5-Encoder-230M」と「LFM2.5-Encoder-350M」を入手できます。
- 試す: 上記のデモをブラウザで実行可能で、セットアップは不要です。
- ファインチューニング: 当社のファインチューニングチュートリアルを用いて、エンコーダーを各タスクに合わせて適応させることができます。
皆様の実装に期待しています。
引用
本成果を利用する場合は、リリースブログを引用してください。
Liquid AI が公開した「LFM2.5-Encoders」は、CPU 上でも高速な長文コンテキスト処理を実現するエンコーダーです。
@article{liquidAI2026Encoders,
author = {Liquid AI},
title = {LFM2.5-Encoders: Fast at Long Context, Even on CPU},
journal = {Liquid AI Blog},
year = {2026},
note = {www.liquid.ai/blog/lfm2-5-encoders},
}
原文を表示
- Why we built a general-purpose encoder
- How the encoders are built
- Benchmark Results
- Inference speed on CPU and GPU
- LFM2.5-Encoder demos
- How to use and fine-tune LFM2.5-Encoders Load and run the model
- Fine-tuning for your task
- Get started with LFM2.5-Encoders
- Citation
Today, we release two new encoder models on Hugging Face: LFM2.5-Encoder-230M and LFM2.5-Encoder-350M. They match the quality of larger models but stay fast as inputs get longer. This means you can run document-scale jobs on the hardware you already have, even on CPU.
Here's what you get:
- Strong for their size: match or beat larger encoders on GLUE, SuperGLUE, and multilingual tasks.
- 8,192-token context with latency that grows slowly as inputs get longer.
- Fast on CPU: about 3.7× faster than ModernBERT-base at long context.
With these, you can build intent routers, policy linters, PII detectors, and text classifiers that run cheaply, all day. See the live demos below.
Why we built a general-purpose encoder
Last month we released LFM2.5-Retrievers, built for multilingual search. LFM2.5-Encoders come from the same family but serve a broader purpose. They're pre-trained with a masked-language objective, so you can fine-tune them for classification, token-level tasks, and search alike. Search is just one thing an encoder enables. That's why we built a general-purpose model instead of reusing the retrievers.
Encoders power many modern production NLP applications: classifiers, intent routers, safety filters. These jobs run all day, usually on CPU, on ever-longer inputs. BERT established this class of model, and recently ModernBERT pushed its accuracy, speed, and context further. LFM2.5-Encoders take the next step on the LFM2 architecture, where cost grows slowly as inputs grow.
How the encoders are built
We initialize the encoders from their respective LFM2 decoder backbones: LFM2.5-230M and LFM2.5-350M. Then we turn each causal decoder into a bidirectional encoder with a few changes:
- Bidirectional attention mask: each token now sees the tokens on both sides, not just the ones before it.
- Non-causal short convolutions: we pad them symmetrically so each token's convolution mixes in its neighbors on both sides.
- Masked language modeling: we mask 30% of the tokens during training.
We train both models in two stages:
- General language competence: a short-context masked-language objective on a large web corpus at a 1,024-token context.
- Long-context adaptation: extending context to 8,192 tokens on the full data mix, strengthening factual, legal, and multilingual competence.
Benchmark Results
We fine-tune each model fully on every task and report the resulting score. Across the table, that's 14 models on 17 tasks pulled from GLUE, SuperGLUE, and multilingual classification.
We report the mean across five held-out seeds, so the numbers are stable run to run. The full framework and raw results are open-sourced.
LFM2.5-Encoder-350M ranks fourth of the 14 models. The three ahead of it are all larger, including a 3.5B model nearly 10 times its size. LFM2.5-Encoder-230M beats ModernBERT-base and every EuroBERT model, while being smaller than most of them. Both also score well above our own LFM2.5-Retrievers here.
Inference speed on CPU and GPU
Our encoders inherit the LFM2 backbone's fast inference. Since both our encoders and ModernBERT support an 8,192-token context, we measure speed across the full range.
Our encoders show their biggest edge on CPU. Here, LFM2.5-Encoder-230M is the fastest at every sequence length (even faster than the smaller ModernBERT-base for short inputs). With increasing input length, throughput decreases sharply for ModernBERT, while our LFM2.5-Encoders rise into the mid-range before tapering. At 8,192 tokens, ModernBERT-base takes over a minute and a half per forward pass versus about 28s for LFM2.5-Encoder-230M. This is about 3.7x faster. For developers, that means you can scan or classify a full contract, transcript, or long support thread in under 30 seconds on a laptop CPU.
On GPU, a similar pattern holds with a smaller margin: ModernBERT-base leads below ~1K tokens on the Apple GPU. Our encoders take the lead from about 2K tokens. This shows that for long inputs, LFM2.5-Encoders are the faster choice, and if you're running on CPU, dramatically so.
LFM2.5-Encoder demos
We built the demos below from fine-tuned LFM2.5-Encoders. Each one runs in a CPU-only Hugging Face space:
- Zero-shot prompt routing: define your own routing lanes as free text. The model scores the whole prompt against every lane in one pass.
- Zero-shot policy linting: check text against your company's rules, written as free text. It scores every token against every rule in one pass.
- Spell checking: correct misspellings token by token.
- PII detection: spot and remove 40 kinds of personal information across 16 languages.
- Masked-diffusion text generation (bonus): run the encoder as a chatbot that generates text by iteratively unmasking instead of left to right.
How to use and fine-tune LFM2.5-Encoders
Reach for an LFM2.5-Encoder when you have a high-volume understanding task, such as classification, routing, extraction, or scoring, that runs constantly and has to stay cheap and fast. For jobs like these, a fine-tuned encoder is smaller, faster, and far cheaper to run than a generative LLM, and it fits on the CPUs you already have.
Between the two encoder sizes:
- LFM2.5-Encoder-350M: choose it when accuracy matters most.
- LFM2.5-Encoder-230M: choose it for tighter hardware or higher throughput.
You can start in a few lines. Load a model with transformers. Then run it directly for masked-token prediction, or attach your own head and fine-tune it for your task.
Load and run the model
Install the latest version of transformers:
pip install -U transformers
Run masked-token prediction:
from transformers import AutoModelForMaskedLM, AutoTokenizer
import torch
model_id = "LiquidAI/LFM2.5-Encoder-230M" # or "LiquidAI/LFM2.5-Encoder-350M"
tok = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
mlm = AutoModelForMaskedLM.from_pretrained(model_id, trust_remote_code=True)
text = f"The capital of France is {tok.mask_token}."
enc = tok(text, return_tensors="pt")
with torch.no_grad():
logits = mlm(**enc).logits
pos = (enc["input_ids"][0] == tok.mask_token_id).nonzero()[0].item()
print([tok.decode([t]).strip() for t in logits[0, pos].topk(5).indices.tolist()])
# -> ['Paris', 'Strasbourg', 'Paris', 'Lyon', 'Versailles']
For downstream tasks, load the encoder body and attach your own head (classification, token classification, regression, retrieval):
from transformers import AutoModel
body = AutoModel.from_pretrained(model_id, trust_remote_code=True)
If your GPU supports it, use Flash Attention 2 for the highest efficiency:
pip install flash-attn
Fine-tuning for your task
A base encoder gives you general-purpose representations, not task outputs. So you fine-tune it for each task. Our fine-tuning tutorial walks through fine-tuning on long legal documents with an 8k context.
Get started with LFM2.5-Encoders
Both encoders are open-weight and available on Hugging Face today:
- Download: LFM2.5-Encoder-230M and LFM2.5-Encoder-350M on Hugging Face.
- Try: run the demos above in your browser, no setup needed.
- Fine-tune: adapt an encoder to your task with our fine-tuning tutorial.
We can't wait to see what you build.
Citation
If you use this work, please cite the release blog:
@article{liquidAI2026Encoders,
author = {Liquid AI},
title = {LFM2.5-Encoders: Fast at Long Context, Even on CPU},
journal = {Liquid AI Blog},
year = {2026},
note = {www.liquid.ai/blog/lfm2-5-encoders},
}
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み