CoolFace
Modelpublic

codelion/Llama-3.2-1B-Instruct-tool-calling-lora

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
5likes104downloads
Model Card

codelion/Llama-3.2-1B-Instruct-tool-calling-lora

๐Ÿ› ๏ธ Tool Calling LoRA with Magpie

This LoRA adapter enhances meta-llama/Llama-3.2-1B-Instruct with tool calling capabilities for code exploration and manipulation. Trained using a hybrid Magpie + real execution approach on diverse coding scenarios.

๐ŸŽฏ Key Features

  • โ€”Tool Calling: Teaches models to use development tools effectively
  • โ€”Code Exploration: Navigate and understand unfamiliar codebases
  • โ€”Real Execution: Training data generated from actual tool execution
  • โ€”OpenAI Format: Compatible with OpenAI function calling format
  • โ€”Multi-Tool Sequences: Learns to chain multiple tools for complex tasks

๐Ÿ“Š Performance Metrics

  • โ€”Base Model: meta-llama/Llama-3.2-1B-Instruct
  • โ€”Training Method: Standard LoRA fine-tuning
  • โ€”LoRA Rank: 64
  • โ€”LoRA Alpha: 128
  • โ€”Training Samples: 1000
  • โ€”Sequence Success Rate: 80.0%
  • โ€”Tool Call Accuracy: 80.0%
  • โ€”Average Tools per Sequence: 4.0

๐Ÿ”ง Usage

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel

# Load base model and tokenizer
model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Llama-3.2-1B-Instruct",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-1B-Instruct")

# Load tool calling LoRA adapter
model = PeftModel.from_pretrained(model, "codelion/Llama-3.2-1B-Instruct-tool-calling-lora")

# Example: Use with tool calling prompt
prompt = '''You have access to the following tools:
- list_directory: List contents of a directory
- search_files: Search for files containing specific content
- read_file: Read a single file's contents
- get_file_info: Get file metadata

User: Help me understand how user authentication works in this Flask application
Response:

inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.7)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)

๐Ÿ“ˆ Expected Output Format

The model will generate tool calling sequences in OpenAI format:

json
{
  "tool_calls": [
    {
      "id": "call_1",
      "type": "function",
      "function": {
        "name": "search_files",
        "arguments": "{\"query\": \"auth\", \"file_types\": [\".py\"]}"
      }
    },
    {
      "id": "call_2",
      "type": "function",
      "function": {
        "name": "read_file",
        "arguments": "{\"path\": \"app.py\"}"
      }
    }
  ]
}

๐Ÿงช Training Details

  • โ€”Method: Standard LoRA fine-tuning with tool calling data
  • โ€”Data Generation: Magpie scenarios + real tool execution
  • โ€”Tool Execution: Safe sandbox environment for code exploration
  • โ€”Scenario Types: Code exploration, bug hunting, feature addition, refactoring
  • โ€”Quality Validation: Minimum tool usage and success rate thresholds

๐Ÿ“š Available Tools

The model is trained to use these development tools:

  1. 1.list_directory: Browse project structure
  2. 2.Parameters: path (directory to list)
  1. 1.search_files: Find files containing specific content
  2. 2.Parameters: query, path, file_types, regex
  1. 1.read_file: Read complete file contents
  2. 2.Parameters: path (file to read)
  1. 1.read_multiple_files: Read multiple files at once
  2. 2.Parameters: paths (list of files)
  1. 1.get_file_info: Get file metadata
  2. 2.Parameters: path (file or directory)
  1. 1.create_file: Create new files (if safety mode disabled)
  2. 2.Parameters: path, content
  1. 1.edit_file: Modify existing files (if safety mode disabled)
  2. 2.Parameters: path, changes

๐ŸŽญ Tool Usage Patterns Learned

  • โ€”Exploration First: Start with list_directory to understand structure
  • โ€”Search Before Read: Use search_files to find relevant files
  • โ€”Batch Operations: Use read_multiple_files for related files
  • โ€”Progressive Refinement: Start broad, then focus on specific files

๐Ÿ”ฌ Evaluation

The adapter was evaluated on diverse coding scenarios:

  • โ€”Sequence success rate: 80.0%
  • โ€”Tool call accuracy: 80.0%
  • โ€”Average tools per sequence: 4.0
  • โ€”Successful executions: 4/5

๐Ÿท๏ธ Tool Usage Distribution

Most frequently used tools during evaluation:

  • โ€”get_file_info: 5 uses
  • โ€”list_directory: 5 uses
  • โ€”read_multiple_files: 5 uses
  • โ€”search_files: 5 uses

๐Ÿท๏ธ Related


This adapter is part of the [Ellora project](https://github.com/codelion/ellora) - standardized recipes for enhancing LLM capabilities.