Skip to main content

Overview

Qwen fine-tuning expects training data in JSON format with a specific conversation structure. The data format follows a message-based approach compatible with the ChatML template.

File Structure

Training data should be a JSON file containing an array of conversation examples:

Conversation Format

Each training example is an object with a conversations key:
array
required
Array of message objects representing a multi-turn conversation

Message Object

Each message in the conversation has two fields:
string
required
Role of the message sender:
  • "user": User/human message
  • "assistant": Model response
string
required
Content of the message

Simple Example

Single-turn conversation:

Multi-turn Example

Conversation with context:

Complete Dataset Example

Token Processing

During preprocessing, conversations are converted to the ChatML format:

Training Targets

The model is trained to predict only the assistant’s responses:
  • User messages: Masked with IGNORE_TOKEN_ID (not included in loss)
  • Assistant messages: Used for loss calculation
  • System message: Masked (not predicted)
This is handled automatically by the preprocess() function in finetune.py.

Data Loading

Standard Loading

Lazy Loading

For large datasets, use lazy preprocessing:
This loads and processes examples on-demand rather than all at once.

Validation

Required Fields

Data Quality Checks

Common Mistakes

Incorrect: Missing conversations wrapper

Correct: Wrapped in conversations array

Incorrect: Starting with assistant

Correct: Always start with user

Creating Training Data

From Existing Conversations

From CSV