feat: add --sft-assistant-turns option for multi-turn SFT - #313
Open
Liu14159 wants to merge 1 commit into
Open
Conversation
Liu14159
force-pushed
the
feat/sft-assistant-turns
branch
6 times, most recently
from
August 4, 2026 03:21
c701277 to
5654897
Compare
Liu14159
force-pushed
the
feat/sft-assistant-turns
branch
from
August 28, 2026 02:45
729e814 to
a303c89
Compare
Liu14159
force-pushed
the
feat/sft-assistant-turns
branch
from
August 28, 2026 02:48
a303c89 to
c8c8d83
Compare
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
Add
--sft-assistant-turns [all|last]option for multi-turn SFT, allowing users to train on every assistant turn (defaultall) or only the final assistant turn (last). Earlier assistant turns inlastmode are treated as context. User, system, and tool-result tokens are always excluded from the loss.Usage
Multi-turn data format (JSONL, one conversation per line):
{"messages": [{"role": "user", "content": "What is 2+2?"}, {"role": "assistant", "content": "4"}, {"role": "user", "content": "And 3+3?"}, {"role": "assistant", "content": "6"}]}Related issue
Fixes #224
Type of change
What changed
areno/api/trainer_config.pysft_assistant_turnsfield with__post_init__validationareno/api/data_utils.pymessages_to_tokens_and_mask()withlast_assistant_onlysupportareno/api/trainers/sft.pymessagesformat +sft_assistant_turnspassthrough into_record_to_train_sequenceareno/cli/train.py--sft-assistant-turnsCLI option, config summary, dashboard settingstests/test_trainer_dataset_utils_cpu.pyMultiTurnSFTMaskTest)docs/cli/training.rstdocs/cli/dataset_loaders.rstmessagesformat documentationexamples/sft/multiturn/README.md+dataset_loader.pyEdge cases handled
{"messages": None}None(filtered out){"messages": []}None(empty, no trainable tokens)None(nothing to train)sft_assistant_turnsvalueValueErrorwith clear messageprompt/responserowssft_assistant_turnshas no effectmessagesnorprompt/responseValueErrorwith schema hintlastmode with single assistant turnallmodeDesign decisions
True= do not train (context),False= train (assistant response). Matches existingprompt_response_to_tokens_and_maskcontract.all: preserves backward compatibility — existing single-turn SFT runs are unaffected.messages[:i+1]) to attribute tokens to individual turns. O(N) calls toapply_chat_templatefor N messages; acceptable for typical SFT data (2-10 turns).chat_template, concatenatesrole: contentper turn.data_utils,tokenizer, andTrainerConfigcontracts.How was it tested?
Tested on Kaggle (Python 3.12, T4 GPU,
ARENO_BUILD_EXT=0):25 tests collected, all passed. Config validation and CLI option verified separately:
Checklist
pytest tests/ -k cpu).