[single_controller] feat: discover TPU resource in Ray #7849
 <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.<br/><sub>You have signed the CLA already but the status is still pending? Let us recheck it.</sub>
I'm not sure what Copyright (c) 2026 BAAI. All rights reserved. here means, previous new files were attributed to ByDance.
Should all new added files be attributed to Google?
should it be if not hasattr ... return false?
should this be torch.tpu.is_available() instead or you want to import torch_tpu explicitly to trigger distributed init?
can we read it from TORCH_TPU_TOPOLOGY (it will be different from TPU_TOPOLOGY, but I think it is guaranteed to be set for distributed runs, and should be the right one for environment to use
Ah, it should be Google. This slipped the check. Thanks for pointing out
@askhat-g We prefer to support verl TPU integration as out-of-tree in verl-project/verl-hardware-plugin, once it matures we can move it as in-tree.
@askhat-g We prefer to support verl TPU integration as out-of-tree in verl-project/verl-hardware-plugin, once it matures we can move it as in-tree.
Thank you @wuxibin89 , started a new PR here https://github.com/verl-project/verl-hardware-plugin/pull/18
> @askhat-g We prefer to support verl TPU integration as out-of-tree in verl-project/verl-hardware-plugin, once it matures we can move it as in-tree.
> Thank you @wuxibin89 , started a new PR here verl-project/verl-hardware-plugin#18
@askhat-g https://github.com/verl-project/verl-hardware-plugin/pull/18 merged, please strip platform_tpu.py and keep single-controller changes in this PR.
should we keep this method only for tpu platform? It is actually a bit confusing for platforms other than TPU
just be clear: we have only tested v6e right? maybe have a comment mentioning that.
+1
please check https://github.com/google-pytorch/torchtitan/blob/main/torchtitan/experiments/tpu/cloud_distributed_utils.py for env var setup
This is actually i a bit confusing to read. Can we add a condition of get_platform().device_name == "TPU" and also add a TODO on have ray fix it? cc: @andrewsykim
be explicit that this is the case for TPU in the comment?
Yes, this happens because ranks seem to be treated different in the case of TPU. I wanted to avoid single out the tpu case(if platform == 'TPU') and tried generalize it by overriding the local rank for the tpu case. Let me take it offline with Andrew and discuss if there are better solutions to this
Yeah but we will support this eventually. I will add the comment
The latter is true, it is not about chip availability
Hm, if it is not imported then we try to import it below, that would be a return prematurely
Good to know, let me follow up on this, thank you for pointing that out
@ryanaoleary do you know if https://github.com/ray-project/ray/pull/65723 fixes this or is this a separate issue?
@askhat-g did you run this with RAY_EXPERIMENTAL_NOSET_TPU_VISIBLE_CHIPS=1?
I don't think you need to do this, I suspect it's because we were previously testing with RAY_EXPERIMENTAL_NOSET_TPU_VISIBLE_CHIPS on TPU v6e. Can you try running without RAY_EXPERIMENTAL_NOSET_TPU_VISIBLE_CHIPS?
It still didn't work but I have removed it from this PR. We can align internally if it is needed
Approved these changes.
Approved these changes.
talked offline with @andrewsykim and believe it's a separate issue. The linked Ray PR fixes an issue with dual-device TPUs (tpu7x) by changing get_current_process_visible_accelerator_ids() to expand physical chip indices (0..3 from GKE's injected TPU_VISIBLE_CHIPS) into logical device IDs (0..7). Previously it would cap the TPU Ray resource on the node with the length of the accelerator Ids, which returned the chip IDs. To handle dual-device TPUs you now set RAY_TPU_RESOURCE_PER_CHIP=2 to ensure the translation occurs correctly without breaking default behavior.
I think running without RAY_EXPERIMENTAL_NOSET_TPU_VISIBLE_CHIPS=1 fails here because when it's not set Ray rewrites TPU_HOST_BOUNDS based on the logical resources it sees. The verl actors each request resources={"TPU": 1}, so it overwrites TPU_HOST_BOUNDS to 1,1,1 (https://github.com/ray-project/ray/blob/8e779d8152f15ec7d91a1a8fc8b6f10a3d3d839d/python/ray/_private/accelerators/tpu.py#L847), overwriting the host bounds set by PlatformTPU.
Approved these changes.
jialei777
askhat-g
What does this PR do?
Makes Ray resource discovery and worker placement ask the active platform instead of
assuming NVIDIA, and fixes two places that assume a shape Ray does not guarantee.
This is the in-tree half of out-of-tree platform support.
PlatformTPUitself lives inverl-hardware-plugin#18
(merged); until the call sites here land, that plugin is inert because verl never consults it.
Checklist Before Starting
[{modules}] {type}: {description}Test
tests/single_controller/test_device_agnostic_resources_on_cpu.py(new, 14 cases) covers bothbug fixes and the colocation cap with a stub platform. Runs on CPU, no accelerator and no Ray
cluster required. Eight of the fourteen fail against current
main; the other six areregression guards for existing GPU/NPU behaviour and pass either way.
Broader
tests/single_controller/+tests/plugin/failure set is byte-identical before andafter this change. Cross-checked against the merged plugin with
VERL_PLATFORM=tpu: thecolocation cap applies and the TPU branch resolves.
API and Usage Example
No user-facing API change. Two new
PlatformBasehooks, both defaulting to current behaviour:Design & Code Changes
New hooks
supports_colocated_worker_groups()— applied in bothRayResourcePoolandResourcePoolManagerso the bundle CPU count matches the pool actually created. Left at 3for an exclusive device, the placement group requests 3 CPUs per chip and never schedules.
ray_local_rank_override()— for platforms whose devices Ray does not enumerate viaget_accelerator_ids().get_worker_env_varswas previously a third hook. Per review it is no longer onPlatformBase:RayWorkerGroupcalls it behind an explicitdevice_name == "tpu"branch, sothe only platform needing placement-group-derived mesh environment is the only one carrying it.
Deferred, not silently dropped
is_tpu_availableinverl/utils/device.py— unshippable out-of-tree.verl/__init__.pyimports
verl.utils.deviceat line 33, freezing the module-level flag; entry-point pluginsload at line 74, so
torch_tpuis imported strictly after the flag is evaluated and the flagis always
False, including on a real TPU host.set_numa_affinity— belongs behind a vendor-neutralsupports_numa_affinity()hook paired with a plugin change. The NVML failure it avoided isalready caught and non-fatal.
Docs:
docs/hardware/multi_chip_support.rstmoves TPU from the built-in list to theverl-hardware-plugin list.
Checklist Before Submitting
pre-commitnot available in this environment;ruff checkand
ruff format --checkrun directly and clean, plus thetests/special_sanity/hooks.tests/single_controller/test_device_agnostic_resources_on_cpu.py,CPU-only so it runs in existing CI.
ci-requestchannel.recipesubmodule.