Views
No views yet
unsloth/LFM2.5-1.2B-Instruct, trained with TRL's SFT trainer on mlabonne/FineTome-100k.Note: this repo contains the LoRA adapter only (adapter_model.safetensors+adapter_config.json), not a full standalone model. Load it on top of the base model withpeft, or merge it once and use it as a regular causal LM (see below).
pip install -U torch transformers peft accelerate1from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
2from peft import PeftModel
3
4base_id = "unsloth/LFM2.5-1.2B-Instruct"
5adapter_id = "MenemAI/lfm-finetuned"
6
7tokenizer = AutoTokenizer.from_pretrained(adapter_id, trust_remote_code=True)
8base = AutoModelForCausalLM.from_pretrained(
9 base_id,
10 torch_dtype="auto",
11 device_map="cuda",
12 trust_remote_code=True,
13)
14model = PeftModel.from_pretrained(base, adapter_id)
15model.eval()
16
17generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
18
19question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"
20output = generator(
21 [{"role": "user", "content": question}],
22 max_new_tokens=512,
23 return_full_text=False,
24)[0]
25print(output["generated_text"])device_map="cuda" and pass device_map="cpu" (or "auto"); generation will be slow but works.hf jobs uv run. The PEP 723 header makes uv install the right deps inside the job.1# /// script
2# requires-python = ">=3.10"
3# dependencies = [
4# "torch",
5# "transformers",
6# "peft",
7# "accelerate",
8# ]
9# ///
10from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
11from peft import PeftModel
12
13base_id = "unsloth/LFM2.5-1.2B-Instruct"
14adapter_id = "MenemAI/lfm-finetuned"
15
16tokenizer = AutoTokenizer.from_pretrained(adapter_id, trust_remote_code=True)
17base = AutoModelForCausalLM.from_pretrained(
18 base_id, torch_dtype="auto", device_map="cuda", trust_remote_code=True
19)
20model = PeftModel.from_pretrained(base, adapter_id).eval()
21
22generator = pipeline("text-generation", model=model, tokenizer=tokenizer)
23print(generator(
24 [{"role": "user", "content": "Hello!"}],
25 max_new_tokens=512,
26 return_full_text=False,
27)[0]["generated_text"])hf jobs uv run --flavor a10g-small ./test.pypeft at inference time):1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3
4base = AutoModelForCausalLM.from_pretrained(
5 "unsloth/LFM2.5-1.2B-Instruct", torch_dtype="auto", trust_remote_code=True
6)
7merged = PeftModel.from_pretrained(base, "MenemAI/lfm-finetuned").merge_and_unload()
8merged.save_pretrained("lfm-merged")
9AutoTokenizer.from_pretrained("MenemAI/lfm-finetuned", trust_remote_code=True).save_pretrained("lfm-merged")pipeline("text-generation", model="./lfm-merged", device="cuda") or push it to a new repo with hf upload <your-user>/lfm-merged ./lfm-merged.unsloth/LFM2.5-1.2B-Instructmlabonne/FineTome-100k1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}