Instructions to use unsloth/LFM2-1.2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use unsloth/LFM2-1.2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="unsloth/LFM2-1.2B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("unsloth/LFM2-1.2B") model = AutoModelForCausalLM.from_pretrained("unsloth/LFM2-1.2B") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use unsloth/LFM2-1.2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "unsloth/LFM2-1.2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/LFM2-1.2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/unsloth/LFM2-1.2B
- SGLang
How to use unsloth/LFM2-1.2B with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "unsloth/LFM2-1.2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/LFM2-1.2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "unsloth/LFM2-1.2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "unsloth/LFM2-1.2B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use unsloth/LFM2-1.2B with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/LFM2-1.2B to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for unsloth/LFM2-1.2B to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for unsloth/LFM2-1.2B to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="unsloth/LFM2-1.2B", max_seq_length=2048, ) - Docker Model Runner
How to use unsloth/LFM2-1.2B with Docker Model Runner:
docker model run hf.co/unsloth/LFM2-1.2B
Upload folder using huggingface_hub
Browse files
README.md
CHANGED
|
@@ -21,10 +21,6 @@ tags:
|
|
| 21 |
- lfm2
|
| 22 |
- edge
|
| 23 |
---
|
| 24 |
-
> [!NOTE]
|
| 25 |
-
> Includes our **chat template fixes**! <br> For `llama.cpp`, use `--jinja`
|
| 26 |
-
>
|
| 27 |
-
|
| 28 |
<div>
|
| 29 |
<p style="margin-top: 0;margin-bottom: 0;">
|
| 30 |
<em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves superior accuracy & outperforms other leading quants.</em>
|
|
@@ -161,6 +157,10 @@ The candidate with ID 12345 is currently in the "Interview Scheduled" stage for
|
|
| 161 |
|
| 162 |
## 🏃 How to run LFM2
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
To run LFM2, you need to install Hugging Face [`transformers`](https://github.com/huggingface/transformers) from source (v4.54.0.dev0).
|
| 165 |
You can update or install it with the following command: `pip install "transformers @ git+https://github.com/huggingface/transformers.git@main"`.
|
| 166 |
|
|
@@ -209,6 +209,10 @@ print(tokenizer.decode(output[0], skip_special_tokens=False))
|
|
| 209 |
|
| 210 |
You can directly run and test the model with this [Colab notebook](https://colab.research.google.com/drive/1_q3jQ6LtyiuPzFZv7Vw8xSfPU5FwkKZY?usp=sharing).
|
| 211 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
## 🔧 How to fine-tune LFM2
|
| 213 |
|
| 214 |
We recommend fine-tuning LFM2 models on your use cases to maximize performance.
|
|
|
|
| 21 |
- lfm2
|
| 22 |
- edge
|
| 23 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
<div>
|
| 25 |
<p style="margin-top: 0;margin-bottom: 0;">
|
| 26 |
<em><a href="https://docs.unsloth.ai/basics/unsloth-dynamic-v2.0-gguf">Unsloth Dynamic 2.0</a> achieves superior accuracy & outperforms other leading quants.</em>
|
|
|
|
| 157 |
|
| 158 |
## 🏃 How to run LFM2
|
| 159 |
|
| 160 |
+
You can run LFM2 with transformers and llama.cpp. vLLM support is coming.
|
| 161 |
+
|
| 162 |
+
### 1. Transformers
|
| 163 |
+
|
| 164 |
To run LFM2, you need to install Hugging Face [`transformers`](https://github.com/huggingface/transformers) from source (v4.54.0.dev0).
|
| 165 |
You can update or install it with the following command: `pip install "transformers @ git+https://github.com/huggingface/transformers.git@main"`.
|
| 166 |
|
|
|
|
| 209 |
|
| 210 |
You can directly run and test the model with this [Colab notebook](https://colab.research.google.com/drive/1_q3jQ6LtyiuPzFZv7Vw8xSfPU5FwkKZY?usp=sharing).
|
| 211 |
|
| 212 |
+
### 2. Llama.cpp
|
| 213 |
+
|
| 214 |
+
You can run LFM2 with llama.cpp using its [GGUF checkpoint](https://huggingface.co/LiquidAI/LFM2-1.2B-GGUF). Find more information in the model card.
|
| 215 |
+
|
| 216 |
## 🔧 How to fine-tune LFM2
|
| 217 |
|
| 218 |
We recommend fine-tuning LFM2 models on your use cases to maximize performance.
|