# SFT / instruction tuning

EN: **Supervised fine-tuning** · id `sft`

Path: [AI Atlas](https://aiatlasgraph.com/llms.txt) › [Trenowanie i dostrajanie](https://aiatlasgraph.com/t/training.md) › [Post-training](https://aiatlasgraph.com/t/posttraining.md) › SFT / instruction tuning

## Description

- PL: Dostrajanie na przykładach oczekiwanej odpowiedzi.
- EN: Fine-tuning on examples of the expected answer.

## In one sentence

- PL: To dostrajanie modelu na przykładach pokazujących, jaką odpowiedź powinien dać na dane polecenie.
- EN: This adapts a model using examples of the response it should give to a particular instruction.

## Problem it solves

- PL: Model nie zna oczekiwanego sposobu wykonania zadania, choć potrafi tworzyć ogólny tekst.
- EN: A model can generate general text but does not know your expected way of completing the task.

## What it does

- PL: Trening przewiduje kolejne fragmenty wzorcowej odpowiedzi i poprawia ustawienia, żeby częściej odtwarzać pokazane zachowanie.
- EN: Training predicts successive elements of reference responses and updates parameters to reproduce the demonstrated behaviour more often.

## Everyday example

- PL: Pokazujesz modelowi przykłady zamiany zgłoszeń w krótkie notatki z problemem i następnym krokiem.
- EN: You show a model examples of turning requests into brief notes containing the problem and next step.

## This concerns you if you…

- PL: potrafisz przygotować wzorcowe odpowiedzi
- PL: chcesz nauczyć model powtarzalnego sposobu działania
- EN: can prepare reference responses
- EN: want to teach a model a repeatable behaviour

## Keywords

instruction-response pairs · completion-only loss · response masking · TRL SFTTrainer · sequence packing · teacher forcing · negative log-likelihood

## How it works

- PL: Przykłady serializuje się jako wejście i oczekiwaną odpowiedź, oznaczając pozycje objęte stratą. Minimalizacja ujemnej log-wiarygodności zwiększa prawdopodobieństwo demonstracji, dostosowując parametry do zadań, stylu i formatu danych.
- EN: Examples are serialised as inputs and desired responses, marking positions included in the loss. Minimising negative log-likelihood increases demonstration probabilities, adapting parameters to tasks, style and data format.

## Limits

- PL: Model naśladuje również błędy oraz przypadkowe cechy demonstracji. Pokrycie przykładów ogranicza uogólnianie; maskowanie straty i format rozmowy muszą odpowiadać zamierzonemu zachowaniu.
- EN: Models also imitate demonstration errors and incidental features. Example coverage limits generalisation; loss masking and conversation formats must match the intended behaviour.

## Key terms

- PL: **maska straty**: Oznaczenie tokenów, które uczestniczą w obliczeniu celu treningowego.
- PL: **demonstracja wzorcowa**: Odpowiedź stanowiąca przykład zachowania, którego model ma się nauczyć.
- EN: **loss mask**: A marking of tokens included in the training objective.
- EN: **target demonstration**: A response exemplifying the behaviour a model should learn.

## Know first

- [Tokenizacja tekstu (BPE, WordPiece, SentencePiece) (Text tokenisation (BPE, WordPiece, SentencePiece))](https://aiatlasgraph.com/t/tokenization.md)
- [Funkcje straty (entropia krzyżowa, MSE) (Loss functions (cross-entropy, MSE))](https://aiatlasgraph.com/t/lossfunctions.md)

## Examples

- PL: Przykłady instrukcja–odpowiedź
- EN: Instruction–response pairs

## Subtopics (1 direct, 1 in total)

- [Dostrajanie do wywoływania funkcji i narzędzi (Function-calling and tool-use fine-tuning)](https://aiatlasgraph.com/t/toolcallingft.md): Fine-tuning a model on examples whose answer is a correct, structured tool call with arguments.

## Related topics

Untyped, symmetric "see also" links.

- [Generowanie danych instrukcyjnych przez LLM (LLM-generated instruction data)](https://aiatlasgraph.com/t/instructiongen.md)
- [Selekcja danych do dostrajania (Selecting data for fine-tuning)](https://aiatlasgraph.com/t/finetuneselection.md)
- [SFT na długich łańcuchach myśli (Long chain-of-thought fine-tuning)](https://aiatlasgraph.com/t/longcotsft.md)

## Sources

- [Stanford CS336 · Language Modeling from Scratch (2025)](<https://cs336.stanford.edu/spring2025/>) `cs336` · reference: Budowa modeli, dane, trening, systemy, inferencja i post-training.

---

AI Atlas revision 122 (2026-10-30) · HTML: https://aiatlasgraph.com/t/sft · index: https://aiatlasgraph.com/llms.txt · everything: https://aiatlasgraph.com/llms-full.txt · updated 2026-10-30
