feat: MultiturnSFTDataset - #2315
Open
ysjprojects wants to merge 1 commit into
Open
Conversation
ysjprojects
requested review from
andyland,
k223kim,
lianakoleva and
t-vi
as code owners
August 30, 2026 23:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
MultiturnSFTDataset, a training-data counterpart toSFTDatasetforsupervised finetuning on multi-turn conversations. Builds on the multi-turn
apply()support landed in #<PR number of 62ffd7b> (ChatML/Llama3/R1Base +add_generation_prompt).Motivation
litgpt's SFT pipeline (
SFTDataset) only supports single-turninstruction/output pairs — one prompt string in, one response string out,
with a single masked prefix span. There's no way to train on a full
conversation (multiple user/assistant turns) with per-turn loss masking:
every assistant turn should contribute to the loss while prior turns stay as
context, not get flattened into independent single-turn examples the way
deita.py/lima.pycurrently do.What's included
MultiturnSFTDataset(litgpt/data/base.py): takes a list ofconversations (
list[list[{"role", "content"}]]), and producesinput_ids/labelswith masking applied per-turn instead of a singleprefix boundary.
mask_prompt=False: oneapply()+encode()call overthe whole conversation.
mask_prompt=True: sincePromptStyle.apply()only returns a flatstring with no turn-boundary info, turn boundaries are recovered by
re-rendering growing prefixes of the conversation
(
apply(messages[:k], add_generation_prompt=False)) and diffingtokenized lengths —
bosis applied consistently across every prefix sothe diff stays aligned.
prompt_style.supports_multiturn; raises a clearValueErrorat construction otherwise.
assistantturn (the trainingtarget); raises otherwise.
token_countsreports bothraw(plain per-turn content, no templateoverhead) and
raw_plus_prompt_template(actual sequence length),matching
SFTDataset's existing convention used by the finetuningperformance report.
litgpt.dataalongsideSFTDataset.tests/data/test_base.py: parametrized coverage mirroringtest_sft_dataset(mask_prompt / ignore_index / max_seq_length), adedicated regression test for a longer alternating-turn conversation
(catches a real bug found during development where inconsistent
boshandling across prefixes corrupted turn boundaries), and both
ValueErrorguard paths.
Out of scope (follow-up)
This PR is infrastructure only — no
DataModulewires upMultiturnSFTDatasetyet. A follow-up PR will add aJSONConversations(or similarly named)
DataModulesolitgpt finetunecan actually consumemulti-turn JSON data end-to-end. Also out of scope: inference-side
multi-turn support (
litgpt chathistory,LLM.generate(messages=...)).Test plan
pytest tests/data/test_base.py tests/test_prompts.py— all passing.ruff check/ruff format --checkclean.