Instruction Format › Multi-Turn Conversation Format
Language AI HandbookAll chapters Instruction Format › Multi-Turn Conversation FormatOne section · Sections in this chapter5 / 14 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Real conversations involve multiple exchanges between the user and the assistant. A single question and answer might suffice for simple tasks, but complex interactions require context to build over time. A multi-turn format must track the full conversation history while clearly marking each turn's boundaries and roles. This creates a cumulative context where each response can draw on everything that came before. This makes possible the model to resolve pronouns, follow up on previous statements, and maintain a coherent narrative across many exchanges.
Understanding multi-turn format is necessary because it determines how the model encodes conversational memory. The model does not have explicit memory; it has context. All prior turns are re-encoded on every generation step, and the model's responses are conditioned on the entire visible history. The format's job is to make that history unambiguously parseable so the model can correctly identify which content came from which speaker at each turn.
A simple multi-turn structure looks like:
User: What is the capital of France?
Assistant: The capital of France is Paris.
User: What's the population?
Assistant: Paris has a population of approximately 2.2 million in the city proper, or about 12 million in the greater metropolitan area.
The model processes the entire history when generating each new response. For the second question, it sees both the original question about France's capital, the assistant's response, and the follow-up question about population. This context allows it to resolve the ambiguous reference "What's the population?" to mean Paris's population. Without the conversation history, the model would have no way to know what "the population" refers to. Multi-turn formats let natural, contextual conversation instead of isolated question-answering.
Multi-turn training requires careful attention to what receives gradient updates. Typically, you only compute loss on the assistant turns, not user turns or the system message. Standard causal attention masking ensures only assistant tokens contribute to the loss, preventing the model from learning to predict user inputs. User turns give context that shapes the assistant's response, but they are not targets for prediction. This selective loss computation is what makes the model specialized for response generation rather than conversation modeling in the general sense.
The training loss objective for a multi-turn example can be written as follows. Let denote the full token sequence including system, user, and assistant tokens, and let denote the set of positions corresponding to assistant response tokens. The instruction-tuning loss is:
where:
- is the token at position
- is the full causal context up to position
- are the model parameters
- is the set of assistant-turn token positions
The key insight is that does not include all positions, only those belonging to assistant turns. Non-assistant positions are still present in the input and influence the attention computation through the conditioning context , but they do not contribute to the gradient signal. This means the model learns to generate good assistant responses while freely using system and user context to condition those responses.
The conversation format must handle several edge cases that arise in real-world applications. What happens if a user message is empty? What if there are consecutive user messages without assistant responses? How should the model handle extremely long conversation histories that exceed context length? Different formats and training procedures handle these cases differently, and your choice depends on your application's requirements. Some applications might truncate long histories, while others might summarize earlier turns, and still others might refuse to continue conversations that exceed certain lengths. None of these strategies is universally correct; each involves tradeoffs between context richness and computational feasibility.

Packing Multiple Examples Into a Single Sequence
An important efficiency technique for multi-turn training is sequence packing, where multiple independent conversations are concatenated into a single long sequence to maximize GPU utilization. Instead of padding short conversations to the maximum sequence length (wasting compute on padding tokens), you fit as many conversations as possible into each sequence up to the context limit.
Packing requires careful attention masking. Each packed conversation must attend only to its own tokens, not to tokens from other conversations in the same sequence. This is achieved through block-diagonal attention masks, where each conversation forms a diagonal block that sees only its own tokens. Without these masks, the model would "leak" context from one conversation into another, corrupting the training signal. Most modern training frameworks support packing with block-diagonal attention, and the speedup over naive padding can be substantial, often two to four times on datasets with variable-length conversations.