Repository navigation
Conversation
syangx39
force-pushed
the
tpu-static-micro-batch-lens
branch
from
November 22, 2026 02:47
b509bcd to
b08e548
Compare
syangx39
marked this pull request as ready for review
November 23, 2026 06:24
syangx39
requested review from
heavyrain-lzy and
physics31415926
as code owners
November 23, 2026 06:24
…e-bucket overflow cliffs Adds engine_kwargs.tpu.static_micro_batch_lens (sorted, deduplicated positive token tiers such as [20480, 32768] or '20480,32768') so each packed micro-batch snaps to the smallest tier >= its bucketed length (or keeps its bucketed length above the highest tier). With single-tier static_micro_batch_len=32768, spilling a step from 1 micro-batch to 2 micro-batches pads both micro-batches to 32,768 tokens (65,536 total). Dual-tier [20480, 32768] snaps 2-MB spill steps to 2 x 20,480 = 40,960 padded tokens (-37.5%) with zero extra peak HBM while keeping XLA compilations bounded to one shape per tier. Also fixes a single-process bug in align_micro_batch_shapes_across_ranks: without gdn_row_slot_len, the single-process path previously assigned static_padded regardless of actual length, even when a micro-batch was longer than static_micro_batch_len. It now uses max(bucket_length(n_tokens), static_padded), matching the multi-rank path. Aligned with verl-project#171 and verl-project#172: - Mutually exclusive with static_micro_batch_len; preserves existing single-tier multi-rank behavior when static_micro_batch_lens is unset. - Validates every tier >= gdn_auto_row_slot_len and divisible by gdn_auto_row_slot_len when gdn_auto_row_slot_len is set, and suppresses the missing-static-len warning when static_micro_batch_lens is configured. - static_log_prob_micro_batch_len overrides static_micro_batch_lens on forward_only passes. - Shared resolve_static_micro_batch_len helper keeps sort_micro_batches_for_slots and align_micro_batch_shapes_across_ranks consistent across tiers, static gdn_row_slot_len, and num_seqs_bucketing. - TpuGraphTrainer validation rejects multi-tier static_micro_batch_lens clearly while accepting a single-tier list. Signed-off-by: Summer Yang <xiaotongyang@google.com>
syangx39
force-pushed
the
tpu-static-micro-batch-lens
branch
from
November 29, 2026 07:56
b08e548 to
ede35f6
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.
Status
Rebased onto latest
main(7c97a49) and aligned with #171, #172, #188, and #193. The live TPU A/B is complete; results are below.Motivation
With a single
engine_kwargs.tpu.static_micro_batch_len(e.g.32768), any mini-batch underuse_dynamic_bsz=Truewhose packed tokens slightly exceed32,768splits into 2 micro-batches (e.g. ~18k tokens each) and pads both micro-batches all the way up to32,768(65,536padded tokens total — 2× the compute for a ~10% token increase).In our 32-chip Qwen3.5-35B-A3B RL runs on an older plugin revision (
1bfe7fbd, #127, before #171/#172):+7%increase in response length jumped single-tier32,768overflow steps from1/28to18/28, adding+3.88 s/step(+48%) toupdate_actor.static_micro_batch_lens: [20480, 32768], normal 1-MB steps still snap to32,768, while 2-MB overflow steps (~18k tokens per MB,36,000tokens total) snap each micro-batch to20,480(2 × 20,480 = 40,960padded tokens instead of2 × 32,768 = 65,536, a-37.5%reduction in padded tokens) with no increase in peak HBM in our A/B below (79.34 GiB vs 83.18 GiB; the largest tier still bounds the shape) and XLA compilations bounded to one shape per tier.Summary of Changes
verl_hardware_plugin/accelerators/tpu/options.py):TPUEngineOptions.static_micro_batch_lens: Optional[tuple[int, ...]]withStaticMicroBatchLens.parse()accepting a non-empty list/tuple/OmegaConfListConfigor comma-separated string of positive integers, normalizing to a sorted deduplicatedtuple[int, ...].static_micro_batch_lenandstatic_micro_batch_lens; existing multi-rankstatic_micro_batch_lenbehavior is unchanged whenstatic_micro_batch_lensis unset.gdn_auto_row_slot_len): Whengdn_auto_row_slot_lenis set, validates that every tier instatic_micro_batch_lensis>= gdn_auto_row_slot_lenand divisible bygdn_auto_row_slot_len, raising a clearValueErrornaming any offending tier(s).verl_hardware_plugin/accelerators/tpu/engines/tpu_utils.py,torchtitan_tpu.py):resolve_static_micro_batch_len()and extendedalign_micro_batch_shapes_across_ranks(..., static_lens=...)so each micro-batch snaps its cross-rank MAX-reduced bucket length to the smallest tier>= resolved(or retainsresolvedabove the highest tier), rounding tiers up tolcm(bucket_size, gdn_row_slot_len)when staticgdn_row_slot_lenis active and preserving [TPU] fix: stop per-micro-batch XLA recompiles in the PPO loss path (0-D batch_num_tokens, bucketed loss rows, cached CP restore indices) #171'snum_seqs_bucketingall-reduce.torch.distributedwas uninitialized orworld_size == 1with nogdn_row_slot_len,align_micro_batch_shapes_across_ranksassignedtpu_padded_seq_len = static_paddedregardless of the micro-batch's actual length, under-reportingtpu_padded_seq_lenwhenever a micro-batch exceededstatic_micro_batch_len. It now assignsmax(bucket_length(n_tokens), static_padded), matching the multi-rank path.static_micro_batch_lensinTorchTitanTPUEngine.forward_backward_batch, allowingstatic_log_prob_micro_batch_len([TPU] perf: CP full positions, dynamic GDN row-slot scheduling, fused GDN projections & slot sorting via TPUEngineOptions #172) to override it onforward_only=Truepasses, supporting single-tierstatic_micro_batch_lensin FFD bin-packing ([TPU] perf: 64K TpuGraphTrainer CP/bypass-REINFORCE+IS/RS, FFD bin-packing, and async micro-batching #188) while letting multi-tier fall back toprepare_micro_batches, and suppressing the missing-static-length warning whengdn_auto_row_slot_lenis paired withstatic_micro_batch_lens.gdn_slot_schedule.py,graph_trainer_mode.py,train_step_precompile.py):sort_micro_batches_for_slots([TPU] perf: CP full positions, dynamic GDN row-slot scheduling, fused GDN projections & slot sorting via TPUEngineOptions #172) to estimate padded lengths withresolve_static_micro_batch_lenso tier snapping and slot classification always agree.validate_graph_trainer_engineto reject multi-tierstatic_micro_batch_lensexplicitly (sinceTpuGraphTrainertraces one sequence shape) while accepting a single-tier list and enforcinggdn_row_slot_lendivisibility on it ([TPU] perf: 64K TpuGraphTrainer CP/bypass-REINFORCE+IS/RS, FFD bin-packing, and async micro-batching #188).precompile_engine_train_step([TPU] perf: opt-in graph-trainer step precompile during initial rollout (VERL_TPU_PRECOMPILE_TRAIN_STEP=1) #193) to resolve single-tierstatic_micro_batch_lensidentically tostatic_micro_batch_len.docs/accelerators/tpu/engine.md,docs/accelerators/tpu/README.md):static_micro_batch_lensalongsidestatic_micro_batch_len,static_log_prob_micro_batch_len, andgdn_auto_row_slot_len.Testing (CPU)
test_tpu_options.py,test_tpu_engine.py,test_tpu_gdn_slot_schedule.py,test_tpu_graph_trainer_mode.py, andtest_tpu_train_step_precompile.pycovering:list,tuple, string list, comma-separated string, OmegaConfListConfig), rejection of empty/non-positive/non-int/invalid inputs, and mutual exclusivity withstatic_micro_batch_len.gdn_auto_row_slot_lendivisibility and>=checks (valid multi-tier and rejecting smaller or non-divisible tiers).test_align_micro_batch_shapes_single_process_exceeds_static_len): verifies micro-batches longer thanstatic_micro_batch_lenreceivetpu_padded_seq_len >= bucket_length(n_tokens)for both uninitializedtorch.distributedandworld_size == 1.36,000-token 2-MB overflow savings (40,960vs65,536,-37.5%), single-tier equivalence withstatic_micro_batch_len,num_seqs_bucketing,gdn_row_slot_len,sort_micro_batches_for_slots,static_log_prob_micro_batch_lenoverride onforward_only=True, FFD bin-packing ([TPU] perf: 64K TpuGraphTrainer CP/bypass-REINFORCE+IS/RS, FFD bin-packing, and async micro-batching #188),TpuGraphTrainervalidation, andprecompile_train_step([TPU] perf: opt-in graph-trainer step precompile during initial rollout (VERL_TPU_PRECOMPILE_TRAIN_STEP=1) #193).test_tpu_options.py,test_tpu_gdn_slot_schedule.py,test_tpu_graph_trainer_mode.py,test_tpu_engine.py): 229 passed.tests/accelerators/tpu/suite: 589 passed, 1 skipped (excluding the 5 pre-existingverl#8663core-verl boolean-indexing tests in untouchedtest_tpu_loss_inputs.pydue to the local environment's installedverlversion; verified in CI viatpu-loss-core-sha).ruff check,ruff format --check,mypy, license, copyright, naming, andcompileallchecks all passed.Live TPU A/B (32 chips, Qwen3.5-35B-A3B GRPO)
Setup: TPU v7x, 32 chips (16 trainer + 16 rollout), verl
453954b3, the same image andSEED=101in both arms, 30 steps each, both started with empty compile caches. Single tier =main(ffe8860) withstatic_micro_batch_len=32768; this PR =b08e548withstatic_micro_batch_lens=[20480, 32768]. Both runs completed all 30 steps with 240/240 weight-sync parity checks passing and no tracebacks.32768[20480, 32768][32768, 32768][20480, 20480]update_actor, steady state (no new programs)update_actor7.94 s vs 7.92 s.log_ppl_abs_diff0.00201 vs 0.00230, IS ESS 0.99793 vs 0.99782.update_actor). Rollout dominates step time in this configuration, so that is −3.4% of step time.