mlabonne / llm-course

Course to get into Large Language Models (LLMs) with roadmaps and Colab notebooks.
https://mlabonne.github.io/blog/
Apache License 2.0
39.18k stars 4.14k forks source link

How to fine-tune Llama3.1 with Unsloth for tool calls/function calling? #88

Open asmith26 opened 2 months ago

asmith26 commented 2 months ago

Hi @mlabonne, Firstly, thanks very much for your article on Fine-tune Llama 3.1 Ultra-Efficiently with Unsloth!

I'm hoping to learn more about how to fine-tune Llama3.1 for tool calls/function calling - just wondering do you know if we have to change anything regarding unsloth or the dataset? In particular, I've used the standard chat format for finetuning before, e.g. something like:

messages =  [
    {"role": "user", "content": "Who wrote Harry Potter?"},
    {"role": "assistant", "content": "The answer is JK Rowling."},
]

Not sure if the data format changes regarding fine-tuning for function calling e.g. maybe something like:

messages =  [
    {"role": "user", "content": "Take the drone up 100 feet"},
    {
        "role": "assistant", 
        "content": None,  # or maybe could use `"content": "Done! Drone now at 100 feet."`?
        "function_call" : {
            "name": "takeoff_drone",
            "arguments": " {'altitude': 100},
        },
    }, 
]

Thanks for any help! :)

mlabonne commented 2 months ago

Hi @asmith26, thanks! I don't think that Unsloth supports this formatting but you can check in the code (https://github.com/unslothai/unsloth). I'd recommend manually formatting the expected answer (including JSON function calling) in the assistant's content.