Page MenuHomePhabricator

MI300 machines need startup tweaks
Closed, ResolvedPublic

Description

At the moment, when we reboot MI300-based machines, specifically the workers 1013 and 1012, we lose the partitioning of the GPUs we may have done. We should create a service or one-off script that (re)sets the partitioning on startup, before the kubelet or device plugin start.

Also, the device plugin and the Kubelet seem to have some race condition between them: sometimes a restart of the plugin is needed after boot, or the Kubelet won't advertise the GPUs correctly.

These issues are also relevant on the Lab and Build hosts, but are less critical there.

Event Timeline

Worth to remember - amd-smi is currently relying on a manual fix in the Python files due to https://github.com/ROCm/amdsmi/pull/136, since we were waiting for the rocm 7.2.0 release (afaics it should contain the fix). Without it any reimage would bring up the wrong version of the libs, and partitioning becomes impossible.

I'l look into this.
In the last technical we decided to have 8 partitions on 3 hosts and 2 partitions on 1 host.

Change #1269344 had a related patch set uploaded (by Dpogorzelski; author: Dpogorzelski):

[operations/puppet@production] amg-gpu: Set up explicit GPU partitioning

https://gerrit.wikimedia.org/r/1269344

Change #1272580 had a related patch set uploaded (by Elukey; author: Elukey):

[operations/debs/amd-k8s-device-plugin@master] debian: add explicit ordering between node labeller and gpu plugin

https://gerrit.wikimedia.org/r/1272580

Change #1272580 merged by Elukey:

[operations/debs/amd-k8s-device-plugin@master] debian: add explicit ordering between node labeller and gpu plugin

https://gerrit.wikimedia.org/r/1272580

So far, teh changes have not had the desired effect. I did some deeper digging and tried gating the start of amd-devplugin unit on the presence of the kfd devices via udev, i.e.

# /etc/udev/rules.d/70-kfd.rules
SUBSYSTEM=="kfd", KERNEL=="kfd", MODE="0666", TAG+="systemd"

This results in a virtual systemd unit that is active as soon as the device drivers load:

# systemctl status sys-devices-virtual-kfd-kfd.device
● sys-devices-virtual-kfd-kfd.device - /sys/devices/virtual/kfd/kfd
     Loaded: loaded
     Active: active (plugged) since Fri 2026-04-24 11:44:26 UTC; 11min ago
 Invocation: 828e9c393e164297a377af0fc4356856
     Device: /sys/devices/virtual/kfd/kfd

We can then tweak /usr/lib/systemd/system/amd-k8s-device-plugin.service to depend on this device:

[Unit]
Description=AMD GPU K8s device plugin
Wants=network-online.target
After=network-online.target systemd-udev-settle.service sys-devices-virtual-kfd-kfd.device
Requires=kubelet.service

[Service]
Restart=on-failure
ExecStart=/usr/bin/amd-k8s-device-plugin -logtostderr=true -stderrthreshold=INFO -v=5

However, this does not work in this case. Looking at the startup timing, we see the driver is loaded at 11:44:27:

[Fri Apr 24 11:44:26 2026] ipmi_ssif: IPMI SSIF Interface driver
[Fri Apr 24 11:44:27 2026] bnxt_en 0000:e6:00.1 ens11f1np1: NIC Link is Up, 10000 Mbps (NRZ) full duplex, Flow control: none
[Fri Apr 24 11:44:27 2026] bnxt_en 0000:e6:00.1 ens11f1np1: FEC autoneg off encoding: None
[Fri Apr 24 11:44:27 2026] bnxt_en 0000:e6:00.1 bnxt_re3: Port: 1 Link ACTIVE
[Fri Apr 24 11:44:27 2026] [drm] amdgpu kernel modesetting enabled.
[Fri Apr 24 11:44:27 2026] amdgpu: Virtual CRAT table created for CPU
[Fri Apr 24 11:44:27 2026] amdgpu: Topology: Add CPU node
[Fri Apr 24 11:44:27 2026] amdgpu 0000:05:00.0: enabling device (0000 -> 0002)
[Fri Apr 24 11:44:27 2026] [drm] initializing kernel modesetting (IP DISCOVERY 0x1002:0x74A1 0x1002:0x74A1 0x00).
[Fri Apr 24 11:44:27 2026] [drm] register mmio base: 0xF6200000
[Fri Apr 24 11:44:27 2026] [drm] register mmio size: 2097152

And accordingly, the systemd unit is started soon after:

```# systemctl status sys-devices-virtual-kfd-kfd.device
● sys-devices-virtual-kfd-kfd.device - /sys/devices/virtual/kfd/kfd
     Loaded: loaded
     Active: active (plugged) since Fri 2026-04-24 11:44:26 UTC; 1min 8s ago
 Invocation: 828e9c393e164297a377af0fc4356856
     Device: /sys/devices/virtual/kfd/kfd

But the driver takes almost 30s to enumerate all the GPUs and subdevices and thus the devplugin does not see the GPUs unit then. I added a wrapper script around the plugin to wait for the relevant device nodes to show up, and it logs:

Apr 24 11:44:28 ml-serve1015 systemd[1]: Started amd-k8s-device-plugin.service - AMD GPU K8s device plugin.
░░ Subject: A start job for unit amd-k8s-device-plugin.service has finished successfully
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ A start job for unit amd-k8s-device-plugin.service has finished successfully.
░░ 
░░ The job identifier is 140.
Apr 24 11:44:28 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:29 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:30 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:31 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:32 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:33 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:34 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:35 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:36 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:37 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:38 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:39 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:40 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:41 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:42 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:43 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:44 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:45 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:46 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:47 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:48 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:49 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:50 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:51 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:52 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:53 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:54 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:55 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: /sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting....
Apr 24 11:44:55 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: I0424 11:44:55.715383    5533 main.go:120] AMD GPU device plugin for Kubernetes
Apr 24 11:44:55 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: I0424 11:44:55.715450    5533 main.go:120] /usr/bin/amd-k8s-device-plugin version
Apr 24 11:44:55 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: I0424 11:44:55.715455    5533 main.go:120] hwloc: _VERSION: 2.12.0, _API_VERSION: 0x00020c00, _COMPONENT_ABI: 7, Runtime: 0x00020c00
Apr 24 11:44:55 ml-serve1015 amd-k8s-device-plugin.wrapper[5533]: I0424 11:44:55.715463    5533 manager.go:42] Starting device plugin manager

The code for the wrapper is pretty simple:

#!/bin/bash

while [ ! -d '/sys/module/amdgpu/drivers/pci:amdgpu' ]; do
        echo "/sys/module/amdgpu/drivers/pci:amdgpu does not exist yet, waiting...." >&2
        sleep 1
done
exec /usr/bin/amd-k8s-device-plugin "$@"

My proposal is to add this wrapper via Puppet and override the Debian-package systemd unit via a file in /etc/systemd/system. In the meantime, we can also file a bug upstream, proposing a change to make the binary wait for the devices (I can create that PR).

Change #1277078 had a related patch set uploaded (by Klausman; author: Klausman):

[operations/puppet@production] modules/amd_rocm: Add wrapper around devplugin binary

https://gerrit.wikimedia.org/r/1277078

Change #1277078 merged by Klausman:

[operations/puppet@production] modules/amd_rocm: Add wrapper around devplugin binary

https://gerrit.wikimedia.org/r/1277078

Change #1277103 had a related patch set uploaded (by Klausman; author: Klausman):

[operations/puppet@production] profile/amd_gpu: Fix wrong unit override

https://gerrit.wikimedia.org/r/1277103

Change #1277103 merged by Klausman:

[operations/puppet@production] profile/amd_gpu: Fix wrong unit override

https://gerrit.wikimedia.org/r/1277103

Change #1269344 merged by Dpogorzelski:

[operations/puppet@production] amg-gpu: Set up explicit GPU partitioning

https://gerrit.wikimedia.org/r/1269344

Thanks both for working on this!
Could you provide a summary of the current status? Any follow up tasks?

All of the needed tweaks have been done. We may need to change things up if-when we decide on a different partitioning scheme or the like, but that should be a new Phab task.

Worth to remember - amd-smi is currently relying on a manual fix in the Python files due to https://github.com/ROCm/amdsmi/pull/136, since we were waiting for the rocm 7.2.0 release (afaics it should contain the fix). Without it any reimage would bring up the wrong version of the libs, and partitioning becomes impossible.

@isarantopoulos this needs some attention:

The https://github.com/ROCm/amdsmi/pull/136/changes fix is already merged by upstream, I think it is just a matter of finding what is the right ROCm distribution and import the amd-smi-lib package on our apt repos (and then deploy it on the MI300X hosts).

Didn't realize this was closed. Reopening it to complete the above :)

Worth to remember - amd-smi is currently relying on a manual fix in the Python files due to https://github.com/ROCm/amdsmi/pull/136, since we were waiting for the rocm 7.2.0 release (afaics it should contain the fix). Without it any reimage would bring up the wrong version of the libs, and partitioning becomes impossible.

@isarantopoulos this needs some attention:

The https://github.com/ROCm/amdsmi/pull/136/changes fix is already merged by upstream, I think it is just a matter of finding what is the right ROCm distribution and import the amd-smi-lib package on our apt repos (and then deploy it on the MI300X hosts).

Following up on this to leave a good trace of the work to be done. https://github.com/ROCm/amdsmi/pull/136/changes allows amd-smi set -C etc.. to work, so "compute-partition", and it currently fails on ROCm < 7.20. We haven't see impact so far on newer nodes since /usr/local/bin/amd-smi-gpu-partition, that applies the partitioning config, uses set --memory-partition that works fine. I would upgrade anyway because this is a very nice trap that we could fall into if we switch to computer partition in the future.

Change #1327563 had a related patch set uploaded (by Elukey; author: Elukey):

[operations/puppet@production] profile::amd_gpu: avoid running amd-smi-gpu-partition every puppet run

https://gerrit.wikimedia.org/r/1327563

Change #1327563 merged by Elukey:

[operations/puppet@production] profile::amd_gpu: avoid running amd-smi-gpu-partition every puppet run

https://gerrit.wikimedia.org/r/1327563