Skip to content

[Core][TPU] Verify VFIO groups are backed by Google TPU PCI devices - #65105

Merged
ryanaoleary merged 7 commits into
ray-project:masterfrom
iaalm:fix/tpu-vfio-vendor-check
Aug 1, 2026
Merged

ryanaoleary merged 7 commits into
ray-project:masterfrom
iaalm:fix/tpu-vfio-vendor-check

Conversation

@iaalm

@iaalm iaalm commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

Counting every numeric /dev/vfio/ entry as a TPU produced a false positive with BlueField-3. Confirm vendor ID with /sys/kernel/iommu_groups//devices/*/vendor.

Related issues

Close #65034

@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 improves TPU detection by verifying that VFIO groups are backed by actual Google TPU PCI devices (vendor ID 0x1ae0), preventing non-TPU devices like NVIDIA BlueField-3 from being misidentified. The feedback suggests catching a broader OSError instead of only FileNotFoundError when listing /dev/vfio to avoid potential startup crashes in environments with restricted permissions.

Comment thread python/ray/_private/accelerators/tpu.py Resolved
@iaalm
iaalm force-pushed the fix/tpu-vfio-vendor-check branch from 7a128f4 to 26f0a62 Compare July 29, 2026 14:05
iaalm added 2 commits July 29, 2026 22:12
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

Signed-off-by: iaalm <[email protected]>
@iaalm
iaalm force-pushed the fix/tpu-vfio-vendor-check branch from 26f0a62 to d608390 Compare July 29, 2026 14:12
@andrewsykim

Copy link
Copy Markdown
Member

@ryanaoleary can you take a look please?

@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jul 29, 2026
Comment thread python/ray/_private/accelerators/tpu.py Resolved
Comment thread python/ray/_private/accelerators/tpu.py Resolved
Comment thread python/ray/_private/accelerators/tpu.py Resolved
Comment thread python/ray/_private/accelerators/tpu.py Resolved
@ryanaoleary

Copy link
Copy Markdown
Contributor

Tested this PR to ensure it does not break TPU resource accounting and legacy behavior. I ran some tests on v6e and tpu7x TPUs, the latter of which exposes two vfio devices per chip.

on v6e:

$ kubectl exec -it tpu-single-host-tpu-singlehost-group-worker-wdzmf -- bash -c '
echo "--- /dev/vfio ---"
ls -l /dev/vfio
echo "--- sysfs devices ---"
for g in /sys/kernel/iommu_groups/*/devices/*; do
    echo -n "$g -> vendor: "
    cat "$g/vendor"
    echo -n "  device: "
    cat "$g/device"
done'

--- /dev/vfio ---
total 0
crw-rw-rw- 1 root root 245,   2 Jul 29 18:29 0
crw-rw-rw- 1 root root 245,   1 Jul 29 18:29 1
crw-rw-rw- 1 root root 245,   3 Jul 29 18:29 2
crw-rw-rw- 1 root root 245,   0 Jul 29 18:29 3
crw-rw-rw- 1 root root  10, 196 Jul 29 18:29 vfio
--- sysfs devices ---
/sys/kernel/iommu_groups/0/devices/0000:00:04.0 -> vendor: 0x1ae0
  device: 0x006f
/sys/kernel/iommu_groups/1/devices/0000:00:05.0 -> vendor: 0x1ae0
  device: 0x006f
/sys/kernel/iommu_groups/2/devices/0000:00:06.0 -> vendor: 0x1ae0
  device: 0x006f
/sys/kernel/iommu_groups/3/devices/0000:00:07.0 -> vendor: 0x1ae0
  device: 0x006f

on tpu7x (Ironwood)::

$ kubectl describe pod vllm-tpu-multihost-x82qf-tpu-group-worker-bhm98 | grep -A 4 "Requests:"
    Requests:
      cpu:             20
      [google.com/tpu](https://google.com/tpu):  4
      memory:          200Gi

$ kubectl exec -it vllm-tpu-multihost-x82qf-tpu-group-worker-bhm98 -- bash -c '
echo "--- /dev/vfio ---"
ls -l /dev/vfio
echo "--- sysfs devices ---"
for g in /sys/kernel/iommu_groups/*/devices/*; do
    echo -n "$g -> vendor: "
    cat "$g/vendor"
    echo -n "  device: "
    cat "$g/device"
done'

--- /dev/vfio ---
total 0
crw-rw-rw- 1 root root 245,   7 Jul 29 23:33 0
crw-rw-rw- 1 root root 245,   5 Jul 29 23:33 1
crw-rw-rw- 1 root root 245,   3 Jul 29 23:33 2
crw-rw-rw- 1 root root 245,   1 Jul 29 23:33 3
crw-rw-rw- 1 root root 245,   2 Jul 29 23:33 4
crw-rw-rw- 1 root root 245,   6 Jul 29 23:33 5
crw-rw-rw- 1 root root 245,   0 Jul 29 23:33 6
crw-rw-rw- 1 root root 245,   4 Jul 29 23:33 7
crw-rw-rw- 1 root root  10, 196 Jul 29 23:33 vfio
--- sysfs devices ---
/sys/kernel/iommu_groups/0/devices/0000:00:04.1 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/1/devices/0000:c0:02.0 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/2/devices/0000:c0:00.0 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/3/devices/0000:00:04.0 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/4/devices/0000:00:03.0 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/5/devices/0000:00:03.1 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/6/devices/0000:c0:00.1 -> vendor: 0x1ae0
  device: 0x0076
/sys/kernel/iommu_groups/7/devices/0000:c0:02.1 -> vendor: 0x1ae0
  device: 0x0076

$ kubectl exec -it vllm-tpu-multihost-x82qf-tpu-group-worker-bhm98 -- python3 -c '
from ray._private.accelerators import TPUAcceleratorManager
print("Detected TPUs:", TPUAcceleratorManager.get_current_node_num_accelerators())'

Detected TPUs: 8

in Ray, since KubeRay automatically passes the value of google.com/tpu as the value for TPU to the rayStartParams in addWellKnownAcceleratorResources, the value for TPU is automatically always set to the number of chips. get_current_node_num_accelerators is only called when the TPU resource value is not passed expliclty or set by KubeRay.

Comment thread python/ray/_private/accelerators/tpu.py Resolved
@ryanaoleary

Copy link
Copy Markdown
Contributor

Some comments, mostly nits, but overall the change LGTM and I will approve after the remaining comments are resolved

@iaalm
iaalm force-pushed the fix/tpu-vfio-vendor-check branch from f772735 to 889dc62 Compare July 30, 2026 13:26

@ryanaoleary ryanaoleary 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.

LGTM

@ryanaoleary

Copy link
Copy Markdown
Contributor

This change maintains the existing user-facing behavior of TPU resource accounting, which is:

  1. Calling TPUAcceleratorManager.get_current_node_num_accelerators will return the count of unique devices (not chips) on the TPU node. This is equivalent to the number of Tensornodes (for tpu7x "chiplets") on the TPU. This is the existing behavior by just counting the /dev/vfio files - but now miscounting is handled.
  2. KubeRay contains to explicitly set the TPU count to the value of google.com/tpu, which is always the # of chips on the TPU VM.

@ryanaoleary
ryanaoleary enabled auto-merge (squash) July 31, 2026 00:21
@github-actions github-actions Bot added the go add ONLY when ready to merge, run all tests label Jul 31, 2026
@github-actions
github-actions Bot disabled auto-merge July 31, 2026 09:21
@ryanaoleary
ryanaoleary enabled auto-merge (squash) August 1, 2026 03:54
@ryanaoleary
ryanaoleary merged commit bc4dcc4 into ray-project:master Aug 1, 2026
7 checks passed
goutamvenkat-anyscale pushed a commit to goutamvenkat-anyscale/ray that referenced this pull request Aug 3, 2026
…ay-project#65105)

## Description
Counting every numeric /dev/vfio/<group> entry as a TPU produced a false
positive with BlueField-3. Confirm vendor ID with
/sys/kernel/iommu_groups/<group>/devices/*/vendor.

## Related issues
Close ray-project#65034

---------

Signed-off-by: iaalm <[email protected]>
Co-authored-by: Ryan O'Leary <[email protected]>
Artimislyy pushed a commit to Artimislyy/ray that referenced this pull request Aug 11, 2026
…ay-project#65105)

## Description
Counting every numeric /dev/vfio/<group> entry as a TPU produced a false
positive with BlueField-3. Confirm vendor ID with
/sys/kernel/iommu_groups/<group>/devices/*/vendor.

## Related issues
Close ray-project#65034

---------

Signed-off-by: iaalm <[email protected]>
Co-authored-by: Ryan O'Leary <[email protected]>
400Ping pushed a commit to 400Ping/ray that referenced this pull request Aug 18, 2026
…ay-project#65105)

## Description
Counting every numeric /dev/vfio/<group> entry as a TPU produced a false
positive with BlueField-3. Confirm vendor ID with
/sys/kernel/iommu_groups/<group>/devices/*/vendor.

## Related issues
Close ray-project#65034

---------

Signed-off-by: iaalm <[email protected]>
Co-authored-by: Ryan O'Leary <[email protected]>
Signed-off-by: 400Ping <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ay-project#65105)

## Description
Counting every numeric /dev/vfio/<group> entry as a TPU produced a false
positive with BlueField-3. Confirm vendor ID with
/sys/kernel/iommu_groups/<group>/devices/*/vendor.

## Related issues
Close ray-project#65034

---------

Signed-off-by: iaalm <[email protected]>
Co-authored-by: Ryan O'Leary <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core][TPU] Numeric /dev/vfio groups are incorrectly detected as TPUs

3 participants