Skip to content

[TPU] feat: add TPU distributed/runtime patches and torchrun PJRT env setup - #11

Merged
askhat-g merged 1 commit into
mainfrom
feat/tpu-sft-and-runtime-patches
Oct 9, 2026
Merged

askhat-g merged 1 commit into
mainfrom
feat/tpu-sft-and-runtime-patches

Conversation

@askhat-g

@askhat-g askhat-g commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Part 1 of 2 (Platform & Runtime Patches):

  1. TPU Distributed & Runtime Patches (verl_hardware_plugin/accelerators/tpu/patches/reduce_avg_allreduce_patch.py):
    • Rewrites torch.distributed.all_reduce(op=ReduceOp.AVG) into ReduceOp.SUM + tensor.div_(world_size) on tpu_dist process groups (matching the XPU reduce_avg_allreduce_patch pattern).
    • Routes torch.distributed.all_gather_object(..., group=dp_group) on tpu_dist device-mesh subgroups through either the default Gloo group (when group_size == world_size) or fixed-shape int32 byte tensors via dist.all_gather (avoiding tensor.resize_() crashes on PJRT/XLA), and detaches any TPU metric tensors to CPU.
    • Replaces verl.utils.distributed.set_numa_affinity with a no-op on TPU and routes verl.utils.torch_functional.logprobs_from_logits to vectorized logprobs_from_logits_naive for TPU tensors.
  2. torchrun Multi-Controller PJRT Environment Setup (PlatformTPU):
    • Adds configure_torchrun_tpu_env() in platform_tpu.py (invoked from PlatformTPU.__init__) so standalone torchrun -m verl.trainer.sft_trainer automatically populates PJRT_DEVICE, TORCH_TPU_SLICEBUILDER_ADDRESSES, TPU_PROCESS_PORT, TPU_VISIBLE_CHIPS, and topology bounds from LOCAL_RANK / RANK / WORLD_SIZE.

Test Plan

  • pytest tests/test_plugin_registration.py -v

@askhat-g
askhat-g force-pushed the feat/tpu-sft-and-runtime-patches branch from 50d94d7 to a63484a Compare October 8, 2026 20:11
@askhat-g
askhat-g force-pushed the feat/tpu-sft-and-runtime-patches branch from a63484a to 16dbdcb Compare October 8, 2026 20:43
@askhat-g askhat-g changed the title [TPU] feat: add TPU distributed/runtime patches, SFT bucketed loss adapter, and torchrun env setup [TPU] feat: add TPU distributed/runtime patches and torchrun PJRT env setup Oct 8, 2026
@askhat-g
askhat-g merged commit df1ed53 into main Oct 9, 2026
2 checks passed
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