> For the complete documentation index, see [llms.txt](https://unsloth.ai/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://unsloth.ai/docs/jp/moderu/tutorials/lfm2.5.md).

# Liquid LFM2.5: 実行とファインチューニングの方法

LFM2.5 InstructとVisionを自分のデバイスでローカル実行・ファインチューニングしましょう！

Liquid AI が LFM2.5 をリリース、その中には彼らの [instruct](#run-lfm2.5-1.2b-instruct) および [vision](#liquid-lfm2.5-1.2b-vl-guide) モデルが含まれます。LFM2.5-1.2B-Instruct は、 **2800億トークン** と RL で学習された、117億パラメータのハイブリッド推論モデルで、指示追従、ツール使用、エージェント的タスクにおいて 10億規模でクラス最高の性能を実現します。 [Hugging Face Jobs](/docs/jp/ji-ben/inference-and-deployment/deploying-llms-with-hugging-face-jobs.md) Codex を使って LFM を学習する方法を参照してください！

LFM2.5 は **1GB RAM 未満** で動作し、 **239 tok/s** のデコード速度を AMD CPU 上で達成します。さらに、 [**ファインチューニング** ローカルで実行する](#fine-tuning-lfm2.5-with-unsloth) ことも Unsloth を使ってできます。

<a href="/pages/56706e6412f8aee419d6c7850e9d0a63951b6c8f#run-lfm2.5-1.2b-instruct" class="button primary">テキスト LFM2.5-Instruct</a><a href="/pages/56706e6412f8aee419d6c7850e9d0a63951b6c8f#liquid-lfm2.5-1.2b-vl-guide" class="button primary">Vision LFM2.5-VL</a>

| Dynamic GGUF                                                                          | 16-bit Instruct                                                             |
| ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
| [LFM2.5-1.2B-Instruct-GGUF](https://huggingface.co/unsloth/LFM2.5-1.2B-Instruct-GGUF) | [LFM2.5-1.2B-Instruct](https://huggingface.co/unsloth/LFM2.5-1.2B-Instruct) |

**モデル仕様:**

* **パラメータ**: 1.17B
* **アーキテクチャ**: 16層（10個のダブルゲート LIV 畳み込みブロック + 6個の GQA ブロック）
* **学習予算**: 2800億トークン
* **コンテキスト長**: 32,768 トークン
* **語彙サイズ**: 65,536
* **言語**: 英語、アラビア語、中国語、フランス語、ドイツ語、日本語、韓国語、スペイン語

### ⚙️ 使用ガイド

Liquid AI は推論に次の設定を推奨しています:

* `temperature = 0.1`
* `top_k = 50`
* `top_p = 0.1`
* `repetition_penalty = 1.05`
* 最大コンテキスト長: `32,768`

#### チャットテンプレート形式

LFM2.5 は ChatML 風の形式を使用します:

```python
tokenizer.apply_chat_template([
    {"role": "system", "content": "あなたは Liquid AI によって学習された役立つアシスタントです。"},
    {"role": "user", "content": "C. elegans とは何ですか？"},
], add_generation_prompt=True, tokenize=False)
```

**LFM2.5 のチャットテンプレート:**

```
<|startoftext|><|im_start|>system
あなたは Liquid AI によって学習された役立つアシスタントです。<|im_end|>
<|im_start|>user
C. elegans とは何ですか？<|im_end|>
<|im_start|>assistant
```

#### ツール使用

LFM2.5 は特別なトークンによる関数呼び出しをサポートしています `<|tool_call_start|>` および `<|tool_call_end|>`。ツールはシステムプロンプト内で JSON オブジェクトとして提供してください:

```
<|startoftext|><|im_start|>system
ツール一覧: [{"name": "get_weather", "description": "現在の天気を取得します", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}}}]<|im_end|>
<|im_start|>user
パリの天気は？<|im_end|>
<|im_start|>assistant
<|tool_call_start|>[get_weather(city="Paris")]<|tool_call_end|>
```

### 🖥️ LFM2.5-1.2B-Instruct を実行

#### 📖 llama.cpp チュートリアル（GGUF）

**1. llama.cpp をビルドする**

最新の `llama.cpp` を [GitHub](https://github.com/ggml-org/llama.cpp)。変更してください `-DGGML_CUDA=ON` を `-DGGML_CUDA=OFF` GPU を持っていない場合。 **Apple Mac / Metal デバイスの場合**、次を設定して `-DGGML_CUDA=OFF` その後は通常どおり続けてください - Metal サポートは既定で有効です。

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggml-org/llama.cpp
cmake llama.cpp -B llama.cpp/build \\
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON -DLLAMA_CURL=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-server
cp llama.cpp/build/bin/llama-* llama.cpp
```

**2. Hugging Face から直接実行**

```bash
./llama.cpp/llama-cli \\
    -hf LiquidAI/LFM2.5-1.2B-Instruct-GGUF:Q4_K_M \
    --jinja --ctx-size 32768 \
    --temp 0.1 --top-k 50 --top-p 0.1 --repeat-penalty 1.05
```

**3. または、まずモデルをダウンロードします**

```python
import os
os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "1"
from huggingface_hub import snapshot_download
snapshot_download(
    repo_id="LiquidAI/LFM2.5-1.2B-Instruct-GGUF",
    local_dir="LiquidAI/LFM2.5-1.2B-Instruct-GGUF",
    allow_patterns=["*Q4_K_M*"],
)
```

**4. 会話モードで実行**

```bash
./llama.cpp/llama-cli \\
    --model LiquidAI/LFM2.5-1.2B-Instruct-GGUF/LFM2.5-1.2B-Instruct-Q4_K_M.gguf \
    --ctx-size 32768 \
    --n-gpu-layers 99 \\
    --seed 3407 \\
    --prio 2 \\
    --temp 0.1 \
    --top-k 50 \
    --top-p 0.1 \
    --repeat-penalty 1.05 \
    --jinja
```

### 🦥 Unsloth による LFM2.5 のファインチューニング

Unsloth は LFM2.5 モデルのファインチューニングをサポートしています。1.2B モデルは無料の Colab T4 GPU に十分収まります。学習速度は 2 倍速く、VRAM は 50% 少なくて済みます。

**無料 Colab ノートブック:**

* [LFM2.5-1.2B-Instruct SFT LoRA ノートブック](https://colab.research.google.com/drive/1vGRg4ksRj__6OLvXkHhvji_Pamv801Ss?usp=sharing)
* [LFM2.5-1.2B-Instruct GRPO LoRA ノートブック](https://colab.research.google.com/drive/1mIikXFaGvcW4vXOZXLbVTxfBRw_XsXa5?usp=sharing)
* [LFM2.5-1.2B-Base 継続事前学習（テキスト補完）ノートブック](https://colab.research.google.com/drive/10fm7eNMezs-DSn36mF7vAsNYlOsx9YZO?usp=sharing)
* [LFM2.5-1.2B-Base 継続事前学習（翻訳）ノートブック](https://colab.research.google.com/drive/1gaP8yTle2_v35Um8Gpu9239fqbU7UgY8?usp=sharing)

LFM2.5 は、エージェント的タスク、データ抽出、RAG、ツール使用に推奨されます。知識集約的なタスクやプログラミングには推奨されません。

#### LFM2.5 用 Unsloth 設定

```python
from unsloth import FastLanguageModel
import torch

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name="LiquidAI/LFM2.5-1.2B-Instruct",
    max_seq_length=4096,
    load_in_4bit=False,
)

model = FastLanguageModel.get_peft_model(
    model,
    r=16,
    target_modules = ["q_proj", "k_proj", "v_proj", "out_proj", "in_proj",
                      "w1", "w2", "w3"],
    lora_alpha=16,
    lora_dropout=0,
    bias="none",
    use_gradient_checkpointing="unsloth",
    random_state=3407,
)
```

#### 学習設定

```python
from trl import SFTTrainer
from transformers import TrainingArguments
from unsloth import is_bfloat16_supported

trainer = SFTTrainer(
    model=model,
    tokenizer=tokenizer,
    train_dataset=dataset,
    dataset_text_field="text",
    max_seq_length=4096,
    dataset_num_proc=2,
    packing=False,
    args=TrainingArguments(
        per_device_train_batch_size=2,
        gradient_accumulation_steps=4,
        warmup_steps=5,
        max_steps=60,
        learning_rate=2e-4,
        fp16=not is_bfloat16_supported(),
        bf16=is_bfloat16_supported(),
        logging_steps=1,
        optim="adamw_8bit",
        weight_decay=0.01,
        lr_scheduler_type="linear",
        seed=3407,
        output_dir="outputs",
    ),
)

trainer.train()
```

#### 保存とエクスポート

```python
# LoRA アダプタを保存
model.save_pretrained("lfm25_lora")
tokenizer.save_pretrained("lfm25_lora")

# 結合して 16bit で保存
model.save_pretrained_merged("lfm25_merged", tokenizer, save_method="merged_16bit")

# GGUF にエクスポート
model.save_pretrained_gguf("lfm25_gguf", tokenizer, quantization_method="q4_k_m")
```

### 🎉 llama-server による提供とデプロイ

OpenAI 互換 API で本番環境に LFM2.5 をデプロイするには:

```bash
./llama.cpp/llama-server \\
    --model LiquidAI/LFM2.5-1.2B-Instruct-GGUF/LFM2.5-1.2B-Instruct-Q4_K_M.gguf \
    --alias "LiquidAI/LFM2.5-1.2B-Instruct" \
    --threads -1 \
    --n-gpu-layers 99 \\
    --ctx-size 32768 \
    --port 8001 \\
    --temp 0.1 \
    --top-k 50 \
    --top-p 0.1 \
    --repeat-penalty 1.05 \
    --jinja
```

**OpenAI クライアントでテスト:**

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8001/v1",
    api_key="sk-no-key-required",
)

completion = client.chat.completions.create(
    model="LiquidAI/LFM2.5-1.2B-Instruct",
    messages=[{"role": "user", "content": "2+2 はいくつですか？"}],
)
print(completion.choices[0].message.content)
```

### 📊 ベンチマーク

LFM2.5-1.2B-Instruct は、10億規模でクラス最高の性能を発揮し、低メモリ使用量で高速な CPU 推論を提供します:

![](https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/dxnYF2fuLpulismtFSGFi.png) ![](https://cdn-uploads.huggingface.co/production/uploads/61b8e2ba285851687028d395/dbbI-15p9re2ROhAkqnZm.png)

## 💧 Liquid LFM2.5-1.2B-VL ガイド

LFM2.5-VL-1.6B は、 [LFM2.5-1.2B-Base](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Base) の上に構築された vision LLM で、より強い実世界性能向けに調整されています。現在、 **ファインチューニング** ローカルで Unsloth を使って実行する

<a href="/pages/56706e6412f8aee419d6c7850e9d0a63951b6c8f#run-lfm2.5-vl-1.6b" class="button primary">こともできます。</a><a href="/pages/56706e6412f8aee419d6c7850e9d0a63951b6c8f#fine-tuning-lfm2.5-with-unsloth-1" class="button primary">実行チュートリアル</a>

| Dynamic GGUF                                                            | 16-bit Instruct                                                      |
| ----------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [ファインチューニングチュートリアル](https://huggingface.co/unsloth/LFM2.5-VL-1.6B-GGUF) | [LFM2.5-VL-1.6B-GGUF](https://huggingface.co/unsloth/LFM2.5-VL-1.6B) |

**モデル仕様:**

* **LFM2.5-VL-1.6B**LM バックボーン
* **: LFM2.5-1.2B-Base**Vision エンコーダ
* **: SigLIP2 NaFlex 形状最適化 400M**: 32,768 トークン
* **コンテキスト長**: 65,536
* **言語**: 英語、アラビア語、中国語、フランス語、ドイツ語、日本語、韓国語、スペイン語
* **ネイティブ解像度処理**: 512×512 ピクセルまでの画像をアップスケーリングなしで処理し、非標準のアスペクト比も歪みなく保持します
* **タイル分割戦略**: 大きな画像を重なりのない 512×512 パッチに分割し、全体コンテキストのためにサムネイルエンコーディングを含めます
* **推論時の柔軟性**: 再学習なしで速度/品質のトレードオフを調整できるよう、ユーザーが最大画像トークン数とタイル数を設定可能

### :gear: 使用ガイド

Liquid AI は推論に次の設定を推奨しています:

* **テキスト**: `temperature=0.1`, `min_p=0.15`, `repetition_penalty=1.05`
* **Vision**: min\_image\_tokens=64, max\_image\_tokens=256, do\_image\_splitting=True

#### チャットテンプレート形式

LFM2.5-VL は ChatML 風の形式を使用します:

```python
tokenizer.apply_chat_template([
    {
        "role": "user",
        "content": [
            {"type": "image"},
            {"type": "text", "text": "この画像には何が写っていますか？"}
        ]
    },
    {"role": "assistant", "content": "ソファに座っている猫が見えます。"}
] , tokenize=False)
```

**LFM2.5-VL のチャットテンプレート:**

```
<|startoftext|><|im_start|>system
あなたは Liquid AI による役立つマルチモーダルアシスタントです。<|im_end|>
<|im_start|>user
<image>この画像を説明してください。<|im_end|>
<|im_start|>assistant
この画像は、線虫の一種である Caenorhabditis elegans（C. elegans）を示しています。<|im_end|>
```

### 🖥️  LFM2.5-VL-1.6B を実行

#### :book: llama.cpp チュートリアル（GGUF）

**1. llama.cpp をビルドする**

最新の llama.cpp を入手 [GitHub](https://github.com/ggml-org/llama.cpp)。変更してください `-DGGML_CUDA=ON` を `-DGGML_CUDA=OFF` GPU を持っていない場合。

```bash
apt-get update
apt-get install pciutils build-essential cmake curl libcurl4-openssl-dev -y
git clone https://github.com/ggml-org/llama.cpp
cmake llama.cpp -B llama.cpp/build \\
    -DBUILD_SHARED_LIBS=OFF -DGGML_CUDA=ON -DLLAMA_CURL=ON
cmake --build llama.cpp/build --config Release -j --clean-first --target llama-cli llama-server
cp llama.cpp/build/bin/llama-* llama.cpp
```

**2. Hugging Face から直接実行**

```bash
./llama.cpp/llama-cli \\
  -hf LiquidAI/LFM2.5-VL-1.6B-GGUF:Q4_0 \
  --image test_image.jpg \
  --image-max-tokens 64 \
  -p "この画像には何が写っていますか？" \
  -n 128
```

### :sloth: Unsloth による LFM2.5-VL のファインチューニング

Unsloth は LFM2.5 モデルのファインチューニングをサポートしています。1.6B モデルは無料の Colab T4 GPU に十分収まります。学習速度は 2 倍速く、VRAM は 50% 少なくて済みます。

**無料 Colab ノートブック:**

* [LFM2.5-VL-1.6B SFT LoRA ノートブック](https://colab.research.google.com/drive/1FaR2HSe91YDe88TG97-JVxMygl-rL6vB?usp=sharing)

#### LFM2.5 用 Unsloth 設定

```python
from unsloth import FastVisionModel
import torch

model, tokenizer = FastVisionModel.from_pretrained(
    model_name = "LiquidAI/LFM2.5-VL-1.6B",
    max_seq_length = 4096, 
    load_in_4bit = False, 
)

model = FastVisionModel.get_peft_model(
    model,
    finetune_vision_layers     = False, # 今は False に設定
    finetune_language_layers   = True, # 言語層をファインチューニングしない場合は False
    finetune_attention_modules = True, # 注意層をファインチューニングしない場合は False
    finetune_mlp_modules       = True, # MLP 層をファインチューニングしない場合は False
    r = 16,         
    lora_alpha = 16,
    lora_dropout = 0,
    bias = "none",
)
```

#### 学習設定

```python
from unsloth.trainer import UnslothVisionDataCollator
from trl import SFTTrainer, SFTConfig

FastVisionModel.for_training(model) # 学習を有効化！

trainer = SFTTrainer(
    model = model,
    tokenizer = tokenizer,
    data_collator = UnslothVisionDataCollator(model, tokenizer), # 必須！
    train_dataset = converted_dataset,
    args = SFTConfig(
        per_device_train_batch_size = 2,
        gradient_accumulation_steps = 4,
        warmup_steps = 5,
        max_steps = 30,# num_train_epochs = 1, # 完全な学習には max_steps の代わりにこれを設定
        learning_rate = 2e-4,
        logging_steps = 1,
        optim = "adamw_8bit",
        weight_decay = 0.001,
        lr_scheduler_type = "linear",
        seed = 3407,
        output_dir = "outputs",
        report_to = "none",     # Weights and Biases 用
        remove_unused_columns = False,
        dataset_text_field = "",
        dataset_kwargs = {"skip_prepare_dataset": True},
        max_length = 2048,
    ),
)

trainer.train()
```

#### 保存とエクスポート

```python
# LoRA アダプタを保存
model.save_pretrained("lfm25_lora")
tokenizer.save_pretrained("lfm25_lora")

# 結合して 16bit で保存
model.save_pretrained_merged("lfm25_merged", tokenizer, save_method="merged_16bit")

# GGUF にエクスポート
model.save_pretrained_gguf("lfm25_gguf", tokenizer, quantization_method="q4_k_m")
```

### :bar\_chart: ベンチマーク

LFM2.5-VL-1.6B はクラス最高の性能を発揮します:

| モデル                     | MMStar | MM-IFEval | BLINK | InfoVQA（Val） | OCRBench（v2） | RealWorldQA | MMMU（Val） | MMMB（平均） | 多言語 MMBench（平均） |
| ----------------------- | ------ | --------- | ----- | ------------ | ------------ | ----------- | --------- | -------- | --------------- |
| **LFM2.5-VL-1.6B-GGUF** | 50.67  | 52.29     | 48.82 | 62.71        | 41.44        | 64.84       | 40.56     | 76.96    | 65.90           |
| LFM2-VL-1.6B            | 49.87  | 46.35     | 44.50 | 58.35        | 35.11        | 65.75       | 39.67     | 72.13    | 60.57           |
| InternVL3.5-1B          | 50.27  | 36.17     | 44.19 | 60.99        | 33.53        | 57.12       | 41.89     | 68.93    | 58.32           |
| FastVLM-1.5B            | 53.13  | 24.99     | 43.29 | 23.92        | 26.61        | 61.56       | 38.78     | 64.84    | 50.89           |

### 📚 リソース

* [Liquid AI ブログ記事](https://www.liquid.ai/blog/introducing-lfm2-5-the-next-generation-of-on-device-ai)
* [LFM2 技術レポート（arXiv）](https://arxiv.org/abs/2511.23404)
* [Liquid AI ドキュメント](https://docs.liquid.ai/lfm)
* [Liquid Playground](https://playground.liquid.ai/)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://unsloth.ai/docs/jp/moderu/tutorials/lfm2.5.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
