Skip to content

feat(train): Add SequenceLength support for SFT, DPO, RLVR, RLAIF trainers#5965

Open
guanweim wants to merge 10 commits into
aws:masterfrom
guanweim:context_length
Open

feat(train): Add SequenceLength support for SFT, DPO, RLVR, RLAIF trainers#5965
guanweim wants to merge 10 commits into
aws:masterfrom
guanweim:context_length

Conversation

@guanweim

@guanweim guanweim commented Jun 22, 2026

Copy link
Copy Markdown

Issue #, if available:

Description of changes:

  • Add optional sequence_length parameter to SFTTrainer, DPOTrainer, RLVRTrainer, and RLAIFTrainer for specifying context length in serverless training jobs

  • Recipes are filtered by SequenceLength field, picking the smallest recipe with context length >= the requested value

  • Add SequenceLength to service-2.json and regenerate shapes via codegen

  • Unit tests for _parse_context_length helper (K suffix, lowercase, integer, None, empty)

  • Unit tests for recipe filtering by sequence length

  • Unit tests for ValueError when no sufficient context length exists

  • Unit tests for each trainer passing sequence_length through

  • Unit tests for _create_serverless_config with/without sequence_length

  • Integ test for sft recipe with different context length

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Previous pr that were not merged #5898

guanweim added 9 commits June 22, 2026 19:52
…iners

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
… 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.
…h not provided

Keep the existing `next(...)` logic untouched for the default case (no
sequence_length). Only build the candidates list and filter when
sequence_length is explicitly requested, ensuring zero behavioral change
for existing callers.
…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)
Use Optional[str] = None instead of hardcoded "SageMakerPublicHub" default,
letting get_sagemaker_hub_name() resolve it at runtime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants