Skip to content

Let the dist_rl rollout node load MaxText checkpoints without weight sync - #3416

Open
susanbao wants to merge 16 commits into
mainfrom
sanbao/rollout-maxtext-ckpt-eval
Open

susanbao wants to merge 16 commits into
mainfrom
sanbao/rollout-maxtext-ckpt-eval

Conversation

@susanbao

@susanbao susanbao commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

With weight_sync_config.mode: none (evaluation), a MaxText vLLM rollout had no way to get real weights: the resolver required Raiden weight sync. It can now load a checkpoint:

  • Unscanned: vllm_config.engine_kwargs.additional_config.maxtext_config.load_parameters_path. vLLM's MaxTextForCausalLM already loads it, so only the resolver check changes.
  • Scanned: the new rollout_model_config.scanned_checkpoint_path. For an inprocess_vllm rollout, the node builds the engine on random weights (sampler.initialize()), then loads the checkpoint over them with maxtext.integration.vllm.scanned_checkpoint_loader.load_scanned_checkpoint (AI-Hypercomputer/maxtext#6584). This happens before serve_worker, so the worker registers only once it serves the real weights.
    • scanned_checkpoint_loader.resolve_scanned_checkpoint checks the path before engine initialization (file I/O only), so a bad path fails fast.
    • The loader detects the checkpoint layout itself from Orbax metadata: the parameter item directory (items, default or model_params), OCDBT/Zarr3 storage, pre-fused MoE wi vs wi_0/wi_1, and flat-cycle decoder.layers.layer_<i> vs nested local_layers/global_layer blocks.
    • Merged additional_config is snapshotted before sampler.initialize() so MaxTextForCausalLM's in-place rollout-padding mutations do not leak into the maxtext_config passed to the loader.
  • Pathways persistence for the rollout: the new cluster_config.pathways.rollout.persistence (default false) makes k8s.sh set ENABLE_PATHWAYS_PERSISTENCE=1 on a jobset.pathways.yaml rollout, mirroring cluster_config.pathways.trainer.persistence. With it, Orbax's CloudPathwaysArrayHandler reads a plain Zarr v2 scanned checkpoint directly onto the TPU workers; without it, the whole restore is staged through the controller's host memory (on the 397B checkpoint this OOM-killed a 120G rollout container). It is opt-in because the persistence handler does not read OCDBT/Zarr3. resolve_config still rejects the variable in roles.rollout.env; the error now points at both settings.
  • MaxText pin: split out to Bump MaxText pin to 1bfed67f7f0f #3479. The scanned path needs a MaxText pin that includes Detect scanned checkpoint layout in the vLLM scanned checkpoint loader AI-Hypercomputer/maxtext#6584 (load_scanned_checkpoint / resolve_scanned_checkpoint).

The resolver changes (resolve_config.py):

  • A MaxText vLLM rollout without Raiden is now accepted only with weight_sync_config.mode: none and one of the two checkpoint sources set (load_parameters_path is also rejected when paired with mode: raiden). With neither, it is still rejected, and the error message now names both sources.
  • scanned_checkpoint_path is rejected, with one error that lists every problem, if: weight_sync_config.mode is not none (e.g. raiden, which would replace the loaded weights), weight_sync_config.in_flight_weight_updates is true (partial_rollout skips KV cache reallocation after loading), the rollout is not model_source: maxtext on rollout_engine: inprocess_vllm, vllm_config.init_with_random_weights is explicitly false, or maxtext_config.load_parameters_path is also set.
  • With scanned_checkpoint_path set, a null init_with_random_weights resolves to true.
  • The existing engine_kwargs guard still rejects scan_layers (and the other node-owned keys) in maxtext_config. It is unchanged.

Origin

This puts the worker-side checkpoint loading from #2504 (deepswe_dist/eval_worker.py on atwigg/mlperf, plus #2703) on the stock rollout node, minus the MLPerf-specific parts. The ported pieces are _METADATA storage/pre-fused-MoE detection, composite-directory resolution, and loading the scanned checkpoint in memory; all three now live in MaxText's maxtext.integration.vllm.scanned_checkpoint_loader (AI-Hypercomputer/maxtext#6497, layout detection in AI-Hypercomputer/maxtext#6584). Two behaviours change from #2504:

  • Errors raise instead of being logged and swallowed.
  • There are no getattr fallbacks.

Data/expert parallelism and DP attention from #2579 already work through rollout_model_config.mesh and vllm_config.engine_kwargs.

Merge notes

  • A rollout-seeding change for the same files is in flight: rollout.py, rollout_test.py, resolve_config.py, base_dist_config.yaml and the rollout constructor goldens. Whichever PR lands second needs a small merge. The goldens should be regenerated rather than hand-merged.

TPU verification

Run on TPU7x (96 GiB HBM per device) with a real Qwen3.5-397B-A17B BF16 scanned checkpoint (396.35B params / 740.39 GiB, Zarr v2, pre-fused MoE wi, flat-cycle decoder.layers.layer_0..3). Stock rollout.main, weight_sync_config.mode=none + scanned_checkpoint_path, inprocess_vllm, EP=16, TP=1, with AI-Hypercomputer/maxtext#6584 and ENABLE_PATHWAYS_PERSISTENCE=1. Per-device HBM was sampled from jax.live_arrays() through observation-only wrappers, with no loader or model changes.

Max live HBM per device (GiB):

Step 2x2x4 (16 chips / 32 devices), DP=2 + DP attention, hbm_utilization=0.84 2x2x2 (8 chips / 16 devices), DP=1, 0.84 2x2x2, DP=1, 0.54
sampler.initialize() (random weights + KV cache) 80.64 80.64 51.84
after delete_cache() 54.25 46.42 46.42
after freeing placeholder params 0.00 0.00 0.00
scanned restore (from_pretrained) 23.08 46.15 46.15
peak across the 66 conversion groups 53.36 53.92 53.92
after conversion, before KV reinit 54.25 46.42 46.42
after reinitialize_cache() / after eval 80.64 80.64 51.84
run-wide peak 80.64 80.64 53.92
load time: total (restore + convert) 175 s (59 s + 105 s) 148 s (100 s + 38 s) 183 s (102 s + 71 s)
  • There is never a second full copy of the weights. The conversion transient is at most one scanned slot: 46.42 + 7.50 = 53.92 GiB/device on 16 devices. At 0.84 the run-wide peak equals the configured cap.
  • Each run generated 64/64 GSM8K test samples with 0 errors. 49/64 were correct on 2x2x4. That is a lower bound: the stock raw chat parser does not stop at EOS, and 25 samples hit the 1024-token cap.
  • Controller RSS peaked at about 20 GiB.

Limitations

  • The persistence path covers Zarr v2 checkpoints. An OCDBT/Zarr3 scanned checkpoint on a Pathways rollout is still restored through the controller's host memory, so the rollout container needs a memory limit sized for the checkpoint (or a non-Pathways rollout).
  • The scanned path supports only rollout_engine: inprocess_vllm. The vllm (AsyncEngineArgs) engine runs vLLM out of process, so the node cannot reach its weights.

Test plan

  • JAX_PLATFORMS=cpu python -m pytest tests/dist_rl/launch/
    • resolve_config_test.py: cluster_config.pathways.rollout.persistence defaults to false, is exported as K8S_ROLLOUT_ENABLE_PATHWAYS_PERSISTENCE, and must be a bool; unscanned and scanned sources are accepted with mode none; load_parameters_path with raiden and each invalid scanned_checkpoint_path combination (including in_flight_weight_updates=True and whitespace-only paths) are rejected; the no-source rejection is unchanged.
    • launch_test.py: a jobset.pathways.yaml rollout gets ENABLE_PATHWAYS_PERSISTENCE=1 only with cluster_config.pathways.rollout.persistence=true; other rollout templates ignore it.
    • rollout_test.py:
      • resolve_scanned_checkpoint runs before the engine is built, so a bad path fails fast.
      • initialize() runs before load_scanned_checkpoint, which gets the path, the sampler and the merged maxtext_config; in-place maxtext_config mutations during initialize() do not leak into it.
      • A scanned path without a maxtext_config fails before initialize().
      • No load happens when the path is unset.
    • constructor_goldens_test.py: a new rollout/maxtext_scanned_eval.json golden (regenerated against main); the existing goldens are unchanged.
  • python scripts/check_cl_complexity.py --strict --rev origin/main

- Free scanned sources, sliced wi_0/wi_1 halves, and pre-fused wi only
  after the last conversion group reading them finishes (for inhomogeneous
  local_layers cycle slots).
- Forward-compatibly pass free_sources=True when MaxTextToMaxTextConverter
  supports it directly, and document the private hook fallback TODO.
- Drop jax.clear_caches() after update_params().
- Move LoadAndConvertScannedCheckpointTest above the single __main__ guard
  and add shared-source local_index 0/1, native free_sources, and
  clear_caches test coverage.
@susanbao
susanbao force-pushed the sanbao/rollout-maxtext-ckpt-eval branch from ae1793e to 9511f74 Compare November 23, 2026 21:17
@susanbao
susanbao changed the base branch from sanbao/eval-scanned-ckpt-loader to main November 23, 2026 22:39
@susanbao
susanbao marked this pull request as ready for review November 23, 2026 22:50
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enables MaxText vLLM rollout nodes to load model weights from checkpoints when weight synchronization is disabled (mode: none). By supporting both unscanned and scanned checkpoint paths, the rollout node can now initialize with random weights and subsequently load the actual model parameters before serving. This change includes necessary infrastructure for detecting checkpoint layouts, managing storage settings, and integrating with the updated MaxText scanned checkpoint loader, while also updating the MaxText pin to support these features.

Highlights

  • Checkpoint Loading: Enabled MaxText vLLM rollout nodes to load checkpoints directly without requiring Raiden weight sync, supporting both unscanned and scanned checkpoint formats.
  • Scanned Checkpoint Support: Added rollout_model_config.scanned_checkpoint_path to allow in-process vLLM rollouts to load scanned checkpoints over random weights at startup.
  • MaxText Dependency Update: Bumped MaxText and maxtext-vllm-adapter dependencies to commit 1bfed67f7 to integrate the new scanned checkpoint loader.
  • Configuration Validation: Updated resolve_config.py to enforce strict validation for the new checkpoint loading modes, ensuring incompatible configurations are rejected with descriptive errors.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for loading scanned MaxText checkpoints at startup in inprocess_vllm rollout nodes when weight synchronization is disabled. It includes configuration updates, validation logic, layout resolution from Orbax metadata, and loading integration, along with comprehensive unit and golden tests. Feedback is provided to ensure the Orbax metadata parsing fails loud and fast with a clear ValueError if the format is invalid. A suggestion to use a defensive .get() fallback was removed as it violates the repository's style guide against speculative fallbacks.

Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved

@tianshub tianshub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed description. I read the production changes (config, resolver, rollout.py) and did not find a logic bug, and the CPU checks are green. I have not read the test files or the golden JSON, and did not run anything locally.

I would hold off merging as is, for two reasons, plus a layering suggestion; details inline:

  1. The feature has not run on a real TPU yet (as the description says), and the part mocks cannot cover is exactly the risky part: peak HBM when a checkpoint is loaded over an already-initialized engine.
  2. The MaxText pin bump is 154 commits and affects every MaxText path, and tunix_tpu_unit_tests was skipped on this PR, so the new pin has not been through the TPU smoke tests.
  3. About 100 lines of rollout.py encode MaxText checkpoint-format knowledge that would be better owned by the MaxText loader.

One broader question: there is also the standalone eval entry point (eval_deepswe.py), which builds its own InprocessVllmSampler. With this PR the stock rollout node becomes a second evaluation path. Is the plan to keep both? If so, it would be good to make sure checkpoint loading does not end up maintained in two places.

Comment thread requirements/maxtext_requirements.txt Resolved
Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved
Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved
Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved
Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved
Restore `requirements/maxtext_requirements.txt` and the deepswe_dist
Dockerfile's `DEFAULT_MAXTEXT_COMMIT` to main's aee266d40071. Per review, the
bump to 1bfed67f7f0f goes in separately (branch `sanbao/bump-maxtext-pin`) so
TPU CI runs on it alone; this PR depends on that landing first.
@susanbao susanbao mentioned this pull request Nov 25, 2026
6 tasks done
- `_load_scanned_checkpoint` now requires `layout`; production always passes
  it, so the fallback that re-read `_scanned_checkpoint_layout` is removed.
- `_create_inprocess_vllm_sampler` raises a ValueError naming the config keys
  before `sampler.initialize()` when the merged vLLM `additional_config` has no
  `maxtext_config` mapping, instead of a bare KeyError after the engine is
  built. Validated configs always have one (`scanned_checkpoint_path` requires
  a MaxText rollout, whose base `additional_config` carries `maxtext_config`,
  and `engine_kwargs` overrides must be mappings), so this guards the invariant.
Per review (r4689803839), the rollout node no longer encodes MaxText
checkpoint-format knowledge. It calls
`scanned_checkpoint_loader.resolve_scanned_checkpoint(path)` (file I/O only)
before building the engine, so a bad path still fails before JAX or vLLM
start, and `load_scanned_checkpoint(path, sampler, maxtext_config)` after
`sampler.initialize()`. MaxText now finds the Orbax parameter directory, the
OCDBT/Zarr3 storage flags, whether MoE gate/up are pre-fused, the TP for their
re-layout, and `fp8_moe` itself.

- Remove `_scanned_checkpoint_layout`, `_CHECKPOINT_PARAM_SUBDIRS` and
  `_load_scanned_checkpoint` (TP derivation, `fp8_moe` pop, storage merge).
- Keep config validation, the pre-`initialize()` `maxtext_config` snapshot and
  its missing-config ValueError.
- Drop the layout tests (now covered by MaxText's real-format tests) and the TP
  subtests; regenerate the `maxtext_scanned_eval` golden.

Requires a MaxText pin that includes AI-Hypercomputer/maxtext#NNNN.
Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved
Add `cluster_config.pathways.rollout.persistence` (default false), mirroring
`pathways.trainer.persistence`: `k8s.sh` sets `ENABLE_PATHWAYS_PERSISTENCE=1`
on a `jobset.pathways.yaml` rollout when it is true. Orbax then reads a plain
Zarr v2 `scanned_checkpoint_path` directly onto the TPU workers instead of
staging the whole restore through the rollout container's memory, which
OOM-killed a 120G container on a 397B checkpoint. It is opt-in because the
persistence handler does not read OCDBT/Zarr3 checkpoints, and
`roles.rollout.env` still rejects the variable.

@tianshub tianshub left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second pass, this time over the test files and the golden, which I skipped before (read at a8def96; suite not run). The inline comments are about trimming tests and one dead branch.

Comment thread tunix/dist_rl/launch/nodes/rollout.py Resolved
- Drop the unreachable missing-`maxtext_config` check in
  `_create_inprocess_vllm_sampler` and snapshot
  `copy.deepcopy(additional["maxtext_config"])` directly.
- Return string checkpoint paths as-is in `_optional_checkpoint_path`
  instead of stripping whitespace.
- Pin the `copy.deepcopy` snapshot on a no-override subtest in
  `rollout_test.py`, fold `create_mesh` ordering into `calls`, drop the
  redundant fail-fast and missing-`maxtext_config` tests, and shrink the
  `maxtext.integration.vllm` `sys.modules` stubs in `rollout_test.py` and
  `constructor_goldens_test.py`.
- Split and deduplicate `resolve_config_test.py` checkpoint accept/reject
  cases, and drop the `ENABLE_PATHWAYS_PERSISTENCE=0` assertion in
  `launch_test.py`.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants