Instructions to use trl-lib/LFM2.5-8B-A1B-SFT-function-calling with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use trl-lib/LFM2.5-8B-A1B-SFT-function-calling with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="trl-lib/LFM2.5-8B-A1B-SFT-function-calling") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("trl-lib/LFM2.5-8B-A1B-SFT-function-calling") model = AutoModelForCausalLM.from_pretrained("trl-lib/LFM2.5-8B-A1B-SFT-function-calling", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use trl-lib/LFM2.5-8B-A1B-SFT-function-calling with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "trl-lib/LFM2.5-8B-A1B-SFT-function-calling" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "trl-lib/LFM2.5-8B-A1B-SFT-function-calling", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/trl-lib/LFM2.5-8B-A1B-SFT-function-calling
- SGLang
How to use trl-lib/LFM2.5-8B-A1B-SFT-function-calling 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 "trl-lib/LFM2.5-8B-A1B-SFT-function-calling" \ --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": "trl-lib/LFM2.5-8B-A1B-SFT-function-calling", "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 "trl-lib/LFM2.5-8B-A1B-SFT-function-calling" \ --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": "trl-lib/LFM2.5-8B-A1B-SFT-function-calling", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use trl-lib/LFM2.5-8B-A1B-SFT-function-calling with Docker Model Runner:
docker model run hf.co/trl-lib/LFM2.5-8B-A1B-SFT-function-calling
LFM2.5-8B-A1B-SFT-function-calling
LiquidAI/LFM2.5-8B-A1B fine-tuned with TRL on the 60k xLAM samples of argilla/apigen-function-calling: a query, the tools it may use, and the one or several parallel calls that answer it. All weights are trained, with the loss on the assistant turn only. One epoch on 8 H100s, with the 32 experts split 8 ways (expert parallelism) and everything else FSDP-sharded. The training script is 1_sft.py.
938 steps in 16 minutes. The loss goes from 1.16 to 0.03 and the token accuracy from 90.5% to 99.3%.
Usage
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from trl.chat_template_utils import add_response_schema, parse_response
def get_weather(city: str, unit: str) -> str:
"""
Gets the current weather in a city.
Args:
city: The name of the city.
unit: The temperature unit, "celsius" or "fahrenheit".
"""
model_id = "trl-lib/LFM2.5-8B-A1B-SFT-function-calling"
tokenizer = add_response_schema(AutoTokenizer.from_pretrained(model_id))
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="cuda")
messages = [{"role": "user", "content": "Is it warmer in Lisbon or in Oslo right now? Answer in Fahrenheit."}]
prompt = tokenizer.apply_chat_template(messages, tools=[get_weather], add_generation_prompt=True)["input_ids"]
output = model.generate(torch.tensor([prompt], device="cuda"), max_new_tokens=128, do_sample=False)
print(parse_response(tokenizer, output[0, len(prompt) :].tolist(), prefix=prompt))
{'role': 'assistant', 'tool_calls': [{'type': 'function', 'function': {'name': 'get_weather', 'arguments': {'city': 'Lisbon', 'unit': 'fahrenheit'}}}, {'type': 'function', 'function': {'name': 'get_weather', 'arguments': {'city': 'Oslo', 'unit': 'fahrenheit'}}}], 'content': ''}
- Downloads last month
- 200
