[Raiden Weight Sync 6/7] Integrate Raiden weight sync in MaxTextTrainingEngine with FFI support - #5171
[Raiden Weight Sync 6/7] Integrate Raiden weight sync in MaxTextTrainingEngine with FFI support#5171YixuanWang-99 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces several enhancements to weight synchronization, checkpointing, and configuration in MaxText. Key changes include adding rollout_backend and use_raiden_ffi configurations, integrating a weight converter, implementing a warning for replicated batch dimensions, and refining exception handling during checkpoint restoration. Additionally, new unit tests were added to verify the weight synchronization logic. The review feedback suggests raising a RuntimeError if FFI is explicitly requested but unavailable, logging a warning when running on Pathways without FFI, and adding inhomogeneous_layer_cycle_interval to the test mock configuration to avoid potential attribute errors.
| if config_use_ffi is not None: | ||
| use_raiden_ffi = config_use_ffi and ffi_available |
There was a problem hiding this comment.
If use_raiden_ffi is explicitly requested via configuration (use_raiden_ffi=True), but the FFI library is not available, the current implementation silently falls back to running without FFI. This can lead to silent performance degradation or out-of-memory (OOM) errors on Pathways. It is safer to raise a RuntimeError when an explicitly requested feature cannot be enabled.
| if config_use_ffi is not None: | |
| use_raiden_ffi = config_use_ffi and ffi_available | |
| if config_use_ffi is not None: | |
| if config_use_ffi and not ffi_available: | |
| raise RuntimeError( | |
| "Raiden FFI was explicitly requested (use_raiden_ffi=True), but " | |
| "weight_synchronizer_ffi is not available. Please ensure a compatible " | |
| "tpu_raiden_jax wheel with FFI support is installed." | |
| ) | |
| use_raiden_ffi = config_use_ffi |
| if is_pathways and not use_raiden_ffi: | ||
| get_ffi = getattr(raiden_synchronizer, "_get_raiden_ffi", None) | ||
| ffi_available = (get_ffi() is not None) if get_ffi else False | ||
| if not ffi_available: | ||
| raise RuntimeError( | ||
| "Under Pathways (JAX_PLATFORMS=proxy), Raiden weight synchronization " | ||
| "requires weight_synchronizer_ffi (from tpu_raiden_jax) to avoid client host OOM " | ||
| "and proxy staging timeouts. However, _raiden_ffi is not available in " | ||
| "tunix.experimental.weight_sync.raiden_synchronizer. Please ensure a " | ||
| "compatible tpu_raiden_jax wheel with FFI support is installed." | ||
| ) |
There was a problem hiding this comment.
When running under Pathways with use_raiden_ffi disabled, but ffi_available is True, the code proceeds without FFI using host staging. Since running without FFI on Pathways is highly discouraged due to client host OOM and proxy staging timeouts, we should log a warning to alert the user.
| if is_pathways and not use_raiden_ffi: | |
| get_ffi = getattr(raiden_synchronizer, "_get_raiden_ffi", None) | |
| ffi_available = (get_ffi() is not None) if get_ffi else False | |
| if not ffi_available: | |
| raise RuntimeError( | |
| "Under Pathways (JAX_PLATFORMS=proxy), Raiden weight synchronization " | |
| "requires weight_synchronizer_ffi (from tpu_raiden_jax) to avoid client host OOM " | |
| "and proxy staging timeouts. However, _raiden_ffi is not available in " | |
| "tunix.experimental.weight_sync.raiden_synchronizer. Please ensure a " | |
| "compatible tpu_raiden_jax wheel with FFI support is installed." | |
| ) | |
| if is_pathways and not use_raiden_ffi: | |
| get_ffi = getattr(raiden_synchronizer, "_get_raiden_ffi", None) | |
| ffi_available = (get_ffi() is not None) if get_ffi else False | |
| if not ffi_available: | |
| raise RuntimeError( | |
| "Under Pathways (JAX_PLATFORMS=proxy), Raiden weight synchronization " | |
| "requires weight_synchronizer_ffi (from tpu_raiden_jax) to avoid client host OOM " | |
| "and proxy staging timeouts. However, _raiden_ffi is not available in " | |
| "tunix.experimental.weight_sync.raiden_synchronizer. Please ensure a " | |
| "compatible tpu_raiden_jax wheel with FFI support is installed." | |
| ) | |
| else: | |
| logging.warning( | |
| "Under Pathways (JAX_PLATFORMS=proxy), running Raiden weight synchronization " | |
| "without FFI is highly discouraged as it can cause client host OOM and proxy " | |
| "staging timeouts. Consider enabling use_raiden_ffi." | |
| ) |
| self.engine._config = pytypes.SimpleNamespace( | ||
| scan_layers=False, | ||
| num_decoder_layers=2, | ||
| param_scan_axis=1, | ||
| weight_sync_debug=False, | ||
| use_raiden_ffi=None, | ||
| ) |
There was a problem hiding this comment.
The mock config in the unit test is missing inhomogeneous_layer_cycle_interval. If scan_layers is ever set to True in future test modifications, this will cause an AttributeError when accessing self._config.inhomogeneous_layer_cycle_interval in prepare_weight_sync. Adding it makes the test setup more robust.
| self.engine._config = pytypes.SimpleNamespace( | |
| scan_layers=False, | |
| num_decoder_layers=2, | |
| param_scan_axis=1, | |
| weight_sync_debug=False, | |
| use_raiden_ffi=None, | |
| ) | |
| self.engine._config = pytypes.SimpleNamespace( | |
| scan_layers=False, | |
| num_decoder_layers=2, | |
| param_scan_axis=1, | |
| inhomogeneous_layer_cycle_interval=1, | |
| weight_sync_debug=False, | |
| use_raiden_ffi=None, | |
| ) |
9844f2e to
6786aae
Compare
| "rather than data movement. Adds one barrier per sync." | ||
| ), | ||
| ) | ||
| use_raiden_ffi: Optional[bool] = Field( |
There was a problem hiding this comment.
When should we set this flag to False?
| max_logging.log(f"Skipping raiden worker sync patch: {e}") | ||
|
|
||
|
|
||
| patch_raiden_worker_h2d() |
There was a problem hiding this comment.
Is this required to call here?
| return 0 | ||
| try: | ||
| metadata = self._checkpoint_manager.metadata(step) | ||
| except Exception as e: # pylint: disable=broad-except |
There was a problem hiding this comment.
Why this needs to be changed?
| ) | ||
| except Exception as e: # pylint: disable=broad-except | ||
| logging.exception("Failed to restore checkpoint: %s", e) | ||
| return None, None, None |
There was a problem hiding this comment.
Why do we need to change this?
| metadata: Checkpoint metadata payload from Orchestrator. | ||
| **kwargs: Additional checkpoint saving options. | ||
| """ | ||
| if os.environ.get("DISABLE_CHECKPOINTING", "false").lower() in ("true", "1"): |
There was a problem hiding this comment.
This is controlled by orchestrator, I think we should not gate this API behind any flag.
6786aae to
a6ade7c
Compare
890ab06 to
29e3d54
Compare
29e3d54 to
b033d1a
Compare
a6ade7c to
ff6a0eb
Compare
b033d1a to
95adff1
Compare
ff6a0eb to
75ae687
Compare
95adff1 to
20f7c50
Compare
20f7c50 to
212f591
Compare
7b3bf86 to
870c66b
Compare
db7d733 to
b948c90
Compare
e97ce8f to
9e415a2
Compare
…g and assertion guard - Access config fields directly without getattr - Add use_raiden_ffi assertion guard in configs/types.py and prepare_weight_sync - Remove deprecated resolve_use_ffi and normalize_host_stage calls - Simplify RaidenSynchronizer instantiation and update active D2H check - Set default use_weight_converter to true in base.yml - Support single synchronizer lifecycle and rebind - Add comprehensive prepare_weight_sync unit tests
870c66b to
1b747da
Compare
…scan - Support cycle_interval in unscan_layers - Raise descriptive ValueError naming the key and missing cycle-slot prefix when slot is None and cycle_interval > 1 - Add unit tests for unscan_layers and inhomogeneous layer cycles
- Add 128-lane interleaving and padding in convert_utils - Remove dead scan_fused_axis parameter - Add compute_padded_moe_mlp_dim in moe_padding - Add unit tests for convert_utils padding and fusion
…dels - Support target-free weight conversion directly to vLLM format - Enable streaming parameter conversion to minimize host peak RSS - Add comprehensive test suite in weight_converter_test
…g and FFI support - Access config fields directly without getattr - Integrate Tunix FFI resolution and host staging normalization - Add use_raiden_ffi field to config types - Support single synchronizer lifecycle and rebind - Add comprehensive prepare_weight_sync tests
Overview
Part of the stacked Raiden weight-sync enablement PR chain replacing #5089.
Pairs with Tunix [T2a] (
google/tunix).Stack:
Details
use_weight_converter,rollout_backend,weight_sync_debug) directly as typed attributes rather than usinggetattr(addressing @igorts's comment).use_raiden_ffi: Optional[bool] = Field(None, ...)on config types.os.environreads with Tunix's exportedresolve_use_ffiandnormalize_host_stage.tests/unit/prepare_weight_sync_test.py.Verification
pytest tests/unit/prepare_weight_sync_test.py(5/5 passed).pytest tests/post_training/unit/maxtext_engine_test.py(54/54 passed).Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.