Skip to content

Fix OOM in to_huggingface conversion and stabilize post-training E2E TPU pipelines - #4937

Draft
SurbhiJainUSC wants to merge 1 commit into
mainfrom
post_train_dag
Draft

Fix OOM in to_huggingface conversion and stabilize post-training E2E TPU pipelines#4937
SurbhiJainUSC wants to merge 1 commit into
mainfrom
post_train_dag

Conversation

@SurbhiJainUSC

Copy link
Copy Markdown
Collaborator

Description

This PR fixes the following issues caught by TPU post-training E2E pipeline:

  1. Checkpoint Conversion:

    • Pop transformed parameters from state_dict and trigger gc.collect() per iteration in _transform_weights_to_full_model to prevent host RAM accumulation and OOM-kill on large models (e.g., Llama 3.1 70B).
    • Pop LoRA weights when calculating deltas and delete checkpoint_dict after state dict extraction.
    • Pass target dtype to ocp.ArrayRestoreArgs in load_orbax_checkpoint when weight_dtype is specified, reducing initial checkpoint memory footprint.
  2. LLaMA 3.1 70B RL failure:

    • Export required vLLM multiprocessing and IPC flags (VLLM_WORKER_MULTIPROC_METHOD=spawn, VLLM_ENABLE_V1_MULTIPROCESSING=0, GRPC_ENABLE_FORK_SUPPORT=0, PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=upb).
    • Explicitly forward use_pathways=${use_pathways} to train_rl and vllm_decode to prevent falling back to Pathways execution on standard distributed JAX/XPK clusters.
    • Configure chips_per_vm=4 and max_target_length=512 for stable GRPO training on TPU v5p slices.
  3. Gemma 3 / Gemma 4 Post-Training E2E Tests:

    • Add export DATASET_PATH=gs://maxtext-dataset to test_gemma3_multimodal_sft.sh.
    • Add missing vLLM runtime flags and use_pathways forwarding to test_gemma3_rl.sh.
    • Update test_gemma4_rl.sh with batch_size=1, chips_per_vm=4, and max_target_length=512.

Tests

E2E tests

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

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

Copy link
Copy Markdown

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 introduces memory optimizations in the Hugging Face checkpoint conversion process by popping state dictionary keys and invoking garbage collection. It also adds support for specifying a target weight data type when restoring Orbax checkpoints, and updates various TPU end-to-end RL test scripts with new environment variables and execution parameters. Feedback is provided regarding the handling of tuple keys during state dictionary popping to prevent potential downstream crashes if subkeys are missing.

Comment thread src/maxtext/checkpoint_conversion/to_huggingface.py Outdated
@SurbhiJainUSC
SurbhiJainUSC force-pushed the post_train_dag branch 3 times, most recently from f223d8f to b8ef6b3 Compare August 18, 2026 20:49
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

@SurbhiJainUSC
SurbhiJainUSC force-pushed the post_train_dag branch 7 times, most recently from 00cc87a to e54ca71 Compare August 18, 2026 22:48
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.

1 participant