-
Notifications
You must be signed in to change notification settings - Fork 599
Add RL sequence-packing and vLLM block-size knobs #5100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -436,6 +436,18 @@ def create_rl_components( # pylint: disable=too-many-positional-arguments | |
|
|
||
| rl_rollout_engine = functools.partial(MaxTextVllmRollout, maxtext_config=trainer_config) | ||
|
|
||
| rollout_vllm_kwargs = { | ||
| "hf_overrides": trainer_config.vllm_hf_overrides, | ||
| "enable_expert_parallel": sampler_config.enable_expert_parallel, | ||
| "enable_prefix_caching": rollout_prefix_caching_enabled(trainer_config), | ||
| # Ensures vLLM model initializes with correct dtype (not float32 default) | ||
| "dtype": trainer_config.weight_dtype.value, | ||
| } | ||
| if trainer_config.vllm_block_size is not None: | ||
| # Pin the KV-cache page size; left unset, the backend derives it from the | ||
| # engine shape, so unrelated engine changes can move it. | ||
| rollout_vllm_kwargs["block_size"] = trainer_config.vllm_block_size | ||
|
Comment on lines
+439
to
+449
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When sequence packing is enabled ( if trainer_config.max_seq_token_per_tpu > 0 and trainer_config.max_seq_token_per_tpu < trainer_config.max_target_length:
raise ValueError(
f"max_seq_token_per_tpu ({trainer_config.max_seq_token_per_tpu}) must be greater than or equal to "
f"max_target_length ({trainer_config.max_target_length}) when sequence packing is enabled."
)
rollout_vllm_kwargs = {
"hf_overrides": trainer_config.vllm_hf_overrides,
"enable_expert_parallel": sampler_config.enable_expert_parallel,
"enable_prefix_caching": rollout_prefix_caching_enabled(trainer_config),
# Ensures vLLM model initializes with correct dtype (not float32 default)
"dtype": trainer_config.weight_dtype.value,
}
if trainer_config.vllm_block_size is not None:
# Pin the KV-cache page size; left unset, the backend derives it from the
# engine shape, so unrelated engine changes can move it.
rollout_vllm_kwargs["block_size"] = trainer_config.vllm_block_size |
||
|
|
||
| cluster_config = rl_cluster_lib.ClusterConfig( | ||
| role_to_mesh={ | ||
| rl_cluster_lib.Role.ACTOR: actor_mesh, | ||
|
|
@@ -456,6 +468,7 @@ def create_rl_components( # pylint: disable=too-many-positional-arguments | |
| mini_batch_size=trainer_config.batch_size, | ||
| train_micro_batch_size=train_micro_batch_size, | ||
| rollout_micro_batch_size=rollout_micro_batch_size, | ||
| max_seq_token_per_tpu=trainer_config.max_seq_token_per_tpu or None, | ||
| metrics_logging_options=metrics_logging_options, | ||
| profiler_options=profiler_options, | ||
| checkpoint_root_directory=checkpoint_dir, | ||
|
|
@@ -484,13 +497,7 @@ def create_rl_components( # pylint: disable=too-many-positional-arguments | |
| rollout_vllm_async_scheduling=trainer_config.async_scheduling, | ||
| rollout_vllm_server_mode=trainer_config.rl.use_agentic_rollout, | ||
| rollout_vllm_reshard_chunk_size=trainer_config.rl.reshard_chunk_size, | ||
| rollout_vllm_kwargs={ | ||
| "hf_overrides": trainer_config.vllm_hf_overrides, | ||
| "enable_expert_parallel": sampler_config.enable_expert_parallel, | ||
| "enable_prefix_caching": rollout_prefix_caching_enabled(trainer_config), | ||
| # Ensures vLLM model initializes with correct dtype (not float32 default) | ||
| "dtype": trainer_config.weight_dtype.value, | ||
| }, | ||
| rollout_vllm_kwargs=rollout_vllm_kwargs, | ||
| rollout_vllm_sampling_kwargs={ | ||
| "stop": trainer_config.stop_strings, | ||
| "detokenize": trainer_config.stop_strings is not None, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vLLM block sizes must be powers of 2 (typically 8, 16, 32, 64, 128, 256). Adding a field validator ensures that any invalid non-power-of-2 block size is caught early during configuration validation rather than causing a startup failure in vLLM.