#Llama3.1 fine tuned model finetuning

6 messages · Page 1 of 1 (latest)

little socketBOT
#

For finetuning a Llama3.1-based instruct model with Unsloth, you should use the "llama-3.1" chat template provided by Unsloth. This template matches the format in your example and is specifically designed for Llama 3.1 instruct models. Apply it using:

from unsloth.chat_templates import get_chat_template
tokenizer = get_chat_template(tokenizer, chat_template="llama-3.1")

For inference, use tokenizer.apply_chat_template with add_generation_prompt=True as in your code. This ensures prompts are formatted correctly for both training and inference. For more details and examples, see the official Unsloth Llama3.1 Conversational notebook and Unsloth documentation.

Would you like a step-by-step example for dataset formatting and training?

Sources:

pearl pendant
#

@little socket my examples are like so, is this correct? "<|begin_of_text|><|start_header_id|>system<|end_header_id|>\n\nCutting Knowledge Date: December 2023\nToday Date: 26 July 2024\n\n<|eot_id|><|start_header_id|>user<|end_header_id|>\n\nБерілген заң мәтінін қысқаша мазмұндаңыз.\nЗаң атауы: ХАЛЫҚ ДЕНСАУЛЫҒЫ ЖӘНЕ ДЕНСАУЛЫҚ САҚТАУ ЖҮЙЕСІ ТУРАЛЫ\nТақырып: 128-бап. Медициналық көмек көрсетудің интеграцияланған моделі\nМәтін:\n['1. Медициналық көмек көрсетудің интеграцияланған моделі - өмір сүру ұзақтығын арттыру мақсатында аурудың асқынуының алдын алу, уақтылы анықтау, емдеу және өршу тәуекелін азайту үшін адамның өмір бойына медициналық және әлеуметтік қызметтер кешенін көрсетуді ұйымдастыру моделі.'\n '2. Медициналық көмек көрсетудің интеграцияланған моделі медициналық көмек көрсету стандарттары мен қағидаларына сәйкес мультипәндік тәсіл арқылы іске асырылады.']<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n['1. Медициналық көмек көрсетудің интеграцияланған моделі - өмір сүру ұзақтығын арттыру мақсатында аурудың асқынуының алдын алу, уақтылы анықтау, емдеу және өршу тәуекелін азайту үшін адамның өмір бойына медициналық және әлеуметтік қызметтер кешенін көрсетуді ұйымдастыру моделі.'\n '2. Медициналық көмек көрсетудің интеграцияланған моделі медициналық көмек көрсету стандарттары мен қағидаларына сәйкес мультипәндік тәсіл арқылы іске асырылады.']<|eot_id|>"

little socketBOT
#

Yes, your example matches the correct Llama 3.1 instruct chat template format: it starts with <|begin_of_text|>, includes system, user, and assistant blocks, and uses <|eot_id|> to separate turns. This is the expected structure for both training and inference with Unsloth's Llama 3.1 models, as shown in official Unsloth notebooks and documentation.

If you use this format for your dataset and apply the same chat template during training and inference, your setup is correct.

Would you like a code example for dataset preparation or further clarification?

Sources:

pearl pendant
#

@little socket what if i have a conversation
messages = [
{"role": "system", "content": "reasoning language: English\n\nYou are a helpful assistant that can helps to learn kazakh language kazakh, russian and english speakers."},
{"role": "user", "content": "Сәлем, қалың қалай достым?"},
{"role": "system", "content": "Сәлем! Қалайсыңыз?"},
{"role": "user", "content": "Жақсы, мына сөйлемді дұрысташы: сенин атым берик."},
]

little socketBOT
#

Yes, you can have multi-turn conversations in your dataset. For Llama 3.1 instruct models, structure each message as a list of dicts with "role" and "content", as in your example. The Unsloth chat template will correctly format these for training and inference (see docs).

Just ensure you use the same chat template ("llama-3.1") for both training and inference, and Unsloth will handle the multi-turn formatting automatically.

Would you like a code example for applying the chat template to such conversations?

Sources:

pearl pendant
#

@little socket provide code for applying chat template to such conversations