You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2c7775e
Browse filesBrowse the repository at this point in the historyBrowse files
feat(train): Add SequenceLength support for SFT, DPO, RLVR, RLAIF trainers (#5965)
* feat(train): Add SequenceLength support for SFT, DPO, RLVR, RLAIF trainers
Add optional sequence_length parameter to all four trainers that enables
customers to specify their desired context length for serverless training
jobs. The parameter is passed in ServerlessJobConfig for recipe filtering.
During trainer initialization, _get_fine_tuning_options_and_model_arn
filters recipes by SequenceLength field, picking the smallest recipe
with context length >= the requested value. Raises ValueError if no
sufficient recipe exists or if recipes lack SequenceLength metadata.
Changes:
- ServerlessJobConfig: add sequence_length field
- _parse_context_length: parse values like '8K' to integers
- _get_fine_tuning_options_and_model_arn: filter by SequenceLength
- _create_serverless_config: conditionally include sequence_length
- SFTTrainer, DPOTrainer, RLVRTrainer, RLAIFTrainer: accept and
thread sequence_length through init and train methods
- Unit tests for all new functionality
* fix: use codegen for SequenceLength shape instead of manual shapes.py edit
Add SequenceLength to service-2.json and regenerate shapes.py via codegen
(python -m sagemaker.core.tools.codegen) instead of editing shapes.py manually.
* fix: correct test imports and mock setup for sequence_length tests
* address PR review: sequence_length as recipe pre-filter and simplify config
- Move sequence_length filtering above recipe selection to reduce
recipes_with_template before existing logic runs
- Always pass sequence_length to ServerlessJobConfig (no None guard)
* test: add integration test for SFT trainer with sequence_length
* Regenerate code via codegen and remove hardcoded path in data_extractor.py
* comment out gpu testing flag
* fix: reject bare integer inputs in _parse_context_length
Bare integers like "128" were silently parsed as token counts (128),
causing every recipe to pass the >= filter and silently selecting the
shortest recipe instead of failing. Now raises ValueError with an
actionable message for any input not ending in 'K'.
* Validate customer sequence lengths against the recipe's SequenceLength
Enforce that customer-selected lengths fit the recipe's supported sequence length:
- RL: max_prompt_length + max_response_length <= SequenceLength
- SFT/DPO: max_length (dataset_max_len) <= SequenceLength
FineTuningOptions.validate_length_constraints() checks this and is wired into the
RL/base trainers. The ceiling comes from the recipe's SequenceLength metadata
('<n>K'), parsed to an int via _parse_context_length; no-op when absent.
(Recipes side unified on the SequenceLength metadata field; the former
ContextLength field was dropped, so read SequenceLength here.)
* Rename context_length to sequence_length; exact-match recipe filter
Recipes vend only SequenceLength, so use that name throughout the fine-tuning
options and validation path (context_length -> sequence_length,
_parse_context_length -> _parse_sequence_length).
Filter recipes by exact SequenceLength match and keep all candidates at that
length, so _select_recipe_by_training_type picks the right recipe when LORA and
FULL variants share the same sequence length. The client sends only descriptors
in ServerlessJobConfig (including SequenceLength); the selectable-length cap is
derived from the recipe catalog rather than a hardcoded enum.
* Enforce SFT/DPO sequence-length ceiling on dataset_max_len
validate_length_constraints() checked only the RL prompt+response sum, so the
single-example ceiling for SFT/DPO recipes was never enforced. verl and llmft
recipes vend that ceiling as dataset_max_len; check it against the recipe's
SequenceLength so an over-limit value is rejected client-side.
Verified against the recipe catalog: dataset_max_len is the param verl/llmft
SFT/DPO recipes actually render (max_context_length appears in Nova overrides
but is never rendered into a recipe body; max_length is Nova-RFT only).
* test: point sequence_length integ tests at qwen3-5-9b verl recipes
The SFT sequence_length test targeted llama-3-2-1b-instruct, which only
offers a 4K recipe, so requesting 8K failed recipe selection. Point it at
huggingface-vlm-qwen3-5-9b and use 16K, which has a matching verl SFT recipe.
Add a matching RLVR sequence_length test on the same model at 8K.
---------
Co-authored-by: Mohamed Zeidan <81834882+mohamedzeidan2021@users.noreply.github.com>
0 commit comments