--- library_name: peft base_model: LiquidAI/LFM2.5-1.2B-Instruct tags: - lora - sft - trl - code-agent - smolagents license: apache-2.0 language: - en pipeline_tag: text-generation --- # LFM25-1.2B-CodeAgent-opus4-terse A LoRA fine-tuned adapter for [LiquidAI/LFM2.5-1.2B-Instruct](https://huggingface.co/LiquidAI/LFM2.5-1.2B-Instruct) trained to follow the [smolagents](https://github.com/huggingface/smolagents) CodeAgent format. ## Model Description This adapter teaches LFM2.5-1.2B-Instruct to respond in the structured Thought + Code format required by smolagents CodeAgent: ```` Thought: I need to calculate this. ```python result = 2 + 2 final_answer(result) ``` ```` ### Key Features - **Base Model**: LiquidAI/LFM2.5-1.2B-Instruct (1.2B parameter) - **Format Compliance**: N/A with minimal prompt - **Answer Accuracy**: N/A on evaluation tasks - **Adapter Size**: ~47MB (LoRA rank=16, alpha=32) ## Training Details ### Training Data - **130 successful CodeAgent trajectories** generated using Claude Opus 4.5 (terse prompt) as the teacher model - Tasks include mathematical reasoning, string manipulation, and general problem-solving - Each trajectory demonstrates the Thought → Code → Observation → final_answer pattern ### Training Configuration | Parameter | Value | | -------------------- | ------------------ | | LoRA Rank | 16 | | LoRA Alpha | 32 | | Target Modules | w1, w2, w3, q_proj, k_proj, v_proj, out_proj, in_proj | | Trainable Parameters | ~25M | | Training Steps | 3 epochs | | Learning Rate | 1e-4 | | Batch Size | 2 (grad accum 4) | | Max Sequence Length | 8192 | | Hardware | GPU | | Training Time | see ablation report | ### Training Framework - [TRL](https://github.com/huggingface/trl) SFTTrainer - [PEFT](https://github.com/huggingface/peft) for LoRA ## Evaluation Results ### Prompt Mode Comparison | Prompt Mode | Format Compliance | Answer Accuracy | | ----------- | --------------------------- | ------------------------- | | **Minimal** | N/A | N/A | | Default | N/A | N/A | | None | N/A | N/A | The model performs best with the **minimal prompt** (~95 tokens), demonstrating successful prompt distillation. ### Minimal Prompt Template ````text You are a CodeAgent that solves tasks by writing and executing Python code. Always respond with Thought + Python code block. Example: Thought: I need to calculate this. ```python result = 2 + 2 final_answer(result) ``` Call final_answer(result) when done. Now Begin! ```` ## Usage ### With PEFT ```python from transformers import AutoModelForCausalLM, AutoTokenizer from peft import PeftModel # Load base model base_model = AutoModelForCausalLM.from_pretrained( "LiquidAI/LFM2.5-1.2B-Instruct", device_map="auto", torch_dtype="bfloat16", ) tokenizer = AutoTokenizer.from_pretrained("LiquidAI/LFM2.5-1.2B-Instruct") # Load LoRA adapter model = PeftModel.from_pretrained(base_model, "krzysztofwos/LFM25-1.2B-CodeAgent-opus4-terse") # Generate messages = [{"role": "user", "content": "What is 15 * 23?"}] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) inputs = tokenizer(prompt, return_tensors="pt").to(model.device) outputs = model.generate( **inputs, max_new_tokens=512, temperature=0.3, min_p=0.15, ) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` ### With smolagents ```python from smolagents import CodeAgent, FinalAnswerTool, TransformersModel model = TransformersModel( model_id="LiquidAI/LFM2.5-1.2B-Instruct", peft_model="krzysztofwos/LFM25-1.2B-CodeAgent-opus4-terse", ) agent = CodeAgent( tools=[FinalAnswerTool()], model=model, ) result = agent.run("What is 15 * 23?") print(result) ``` ## Intended Use - Code-assisted problem solving - Mathematical reasoning tasks - Automated code generation following structured formats - Research into prompt distillation and small model fine-tuning ## Limitations - **Requires specific prompt format**: Works best with minimal prompt template - **Limited reasoning depth**: 1.2B parameter model has constrained reasoning capabilities compared to larger models - **English only**: Trained on English-language tasks ## Citation If you use this model, please cite: ```bibtex @misc{lfm25_1.2b_codeagent_opus4_terse, author = {krzysztofwos}, title = {LFM25-1.2B-CodeAgent-opus4-terse}, year = {2025}, publisher = {Hugging Face}, url = {https://huggingface.co/krzysztofwos/LFM25-1.2B-CodeAgent-opus4-terse} } ``` ## Acknowledgments - [LiquidAI](https://www.liquid.ai/) for the LFM2.5-1.2B-Instruct base model - [Hugging Face](https://huggingface.co/) for smolagents, TRL, and PEFT - Training performed as part of CodeAgent prompt distillation research