Skip to content

Name an AMD device node this account cannot open, instead of reading it as no GPU - #10473

Merged
danielhanchen merged 89 commits into
mainfrom
studio/amd-device-permissions
Sep 19, 2026
Merged

danielhanchen merged 89 commits into
mainfrom
studio/amd-device-permissions

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Closes #10466.

The gap

Every AMD probe in this tree tests that /dev/kfd and /dev/dri/renderD* exist. On a stock Linux distribution they are root:render mode 0660, so an account outside that group passes all of them and then cannot open the device. HIP counts zero devices, the Vulkan loader enumerates none, and /sys/class/kfd/kfd/topology/nodes/*/properties is world readable so detection still reports an AMD GPU. The result is byte for byte what owning no GPU looks like: Studio runs on CPU and tells the user to install a driver stack that is already loaded.

That is what #10466 was, on a fresh Strix Halo install, and adding the account to the render and video groups fixed it. Nothing in the product pointed there:

where what it said before why it could not help
_gpu_present_but_unusable_message a PyTorch build mismatch, offering Repair installation the wheel is correct, and no reinstall changes group membership
_explain_empty_gpu_probe "the Vulkan probe reported no device" sends the user after a driver that is already working
install.sh "install the ROCm kernel stack so /dev/kfd exists" /dev/kfd does exist

Note this is not fixed by routing the host to Vulkan: the ICD probe reads world readable manifests, so a gfx1151 box with no render group membership is routed to Vulkan and still falls to CPU. Both backends open the render node.

The change

amd_nodes_closed_to_this_user() in studio/backend/utils/hardware/amd.py lists the AMD nodes that exist and this account cannot open read write, and amd_node_permission_hint() turns that into one line naming the nodes, the groups and the account. The two runtime messages consult it before their existing branches, and install.sh gets the shell equivalent, printed instead of the kernel stack hint rather than after it.

This account cannot open /dev/kfd, /dev/dri/renderD128, so no GPU backend can use
the AMD card even though the driver is loaded. Add the account to the render and
video groups and then log out and back in: sudo usermod -a -G render,video ada

Vendor gating, which is the part that needed care

Render nodes are root:render for every vendor. The first version of this probe, run on the 8xNVIDIA box it was written on, listed all eight renderD* nodes and would have told every CUDA user with a failed probe to join the AMD groups. /sys/class/drm/renderD128/device/vendor reads 0x10de there.

So ownership is confirmed before a node is reported: sysfs vendor 0x1002 for render nodes, and KFD vendor_id 4098 for /dev/kfd, since NVIDIA's open kernel module registers KFD nodes of its own. sysfs is world readable, so ownership is answerable without the access being tested for. After the gate the shell helper reports nothing on that NVIDIA box, and the false positive is a test.

Verification

studio/backend/tests/test_amd_device_node_permissions.py, 14 cases, all passing. Node paths are patched rather than created: a test that had to mknod would need root, which is the one account this bug cannot reach.

Both message tests come with the control that makes them mean something:

  • test_the_capability_message_names_the_permission_not_a_torch_mismatch fails on the pre-change code with the old PyTorch wording, and test_the_capability_message_is_unchanged_when_the_nodes_open asserts every other unusable GPU host keeps it.
  • the same pair for the empty probe explanation, so a Vulkan host with openable nodes keeps its own reason.
  • test_an_nvidia_hosts_closed_render_nodes_are_not_reported is the false positive above.
  • test_read_only_access_is_not_enough, since HIP and the Vulkan loader both open the node read write.
  • test_a_host_whose_nodes_open_reports_nothing, without which every assertion here also passes on a host with no AMD hardware at all.

Six suites together (this one plus test_rocm_hip_unreachable_defers_to_torch, test_amd_smi_inventory_matches_hip, test_torch_cpu_build_on_nvidia_host, test_install_resolve_prebuilt and the mixed host suite) report 470 passed, 1 skipped. bash -n install.sh clean, and the shell helper was run live on this host to confirm it reports nothing after the vendor gate.

Not covered

No AMD hardware here, so this is verified by construction and by unit test rather than on a Strix Halo box. The probe is Linux only: macOS and Windows have no render nodes, and os.access on Windows answers for a permission model this message does not describe.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T22:07:38.852432Z 7cb45fe Manual request
🔒 Security Review ✅ Completed 2026-09-17T18:26:12.985285Z 6c81719 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…it as no GPU

Every AMD probe in the tree tests that /dev/kfd and /dev/dri/renderD* EXIST. On a
stock Linux distribution they are root:render mode 0660, so an account outside that
group passes all of them and then cannot open the device. HIP counts zero devices
and the Vulkan loader enumerates none, which is byte for byte what owning no GPU
looks like, so Studio ran on CPU and told the user to install a driver stack that
was already loaded.

The reports were fresh Strix Halo installs fixed by adding the account to the render
and video groups. Nothing pointed there: the capability message blamed a PyTorch
mismatch and offered Repair installation, the empty probe explanation blamed the
Vulkan probe, and the installer suggested installing the ROCm kernel stack. None of
those repairs can change group membership.

amd_nodes_closed_to_this_user() lists the nodes that exist and this account cannot
open read write, and the two runtime messages plus the installer hint now name them
and the usermod line. Vendor gated in both Python and shell: render nodes are
root:render for every vendor, so an NVIDIA only host has exactly the same closed
nodes and none of the problem, and the ownership check is what keeps a CUDA user
with a failed probe from being told to join the AMD groups.
@danielhanchen
danielhanchen force-pushed the studio/amd-device-permissions branch from dba02d1 to 723ff9e Compare September 8, 2026 05:02
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 8, 2026 06:04
…is about

Three narrowings, from review of the first version.

The installer check ran inside the */cpu arm of the wheel-index case. A host whose
nodes are closed is exactly a host whose runtime probes read nothing, and the reroute
above that case then rewrites a */cpu index to a per-arch */gfx* one, so the arm never
ran for the host the hint was written for. Read once before the case and reported
after it, whichever arm took the index.

/dev/kfd and the render node do not block the same backends. HIP and the Vulkan
loader both open the render node; only HIP opens /dev/kfd. Claiming that a closed
KFD node stopped every backend told a Vulkan user with an unrelated failure to join
the ROCm groups, so the wording now follows the closed set and a Vulkan binary is
asked only about the render node.

The capability message replaced the PyTorch diagnosis unconditionally. On a hybrid
host an NVIDIA card can raise the same verdict while an AMD node happens to be
closed, and there reinstalling the GPU build is the repair and group membership is
not. Gated on the vendors already recorded for the mismatch being reported.

Eight tests, five of which fail on the previous version.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Three places where the permission hint was answering for more than it knows.

The capability message replaced the reinstall advice for both verdicts. That is
right for a GPU wheel that cannot initialise the device, which the closed node
fully explains, and wrong for a CPU-only wheel: opening the node leaves a build
with no GPU path at all. That host needs both repairs and is now given both.

The empty-probe explanation asked about /dev/kfd for anything that was not a
Vulkan build, which is CUDA as well as HIP. On a hybrid host a CUDA build finds
AMD nodes present and closed while its own probe came back empty for an
unrelated reason, and joining the render group repairs none of it. Only a
positively CUDA-only install is skipped, so a build this probe cannot read keeps
the hint rather than losing it to a detection miss.

install.sh suppressed the missing-kernel-stack diagnosis for any closed node.
That node existing is the evidence the stack is loaded and is what makes the
hint wrong, so only a closed /dev/kfd suppresses it now. A host whose /dev/kfd
is absent while a render node is closed needs both, since no amount of group
membership creates /dev/kfd, and gets both.

Six tests, each with the control that gives it meaning. The shell one lifts the
guard out of install.sh by text and anchors on the part of the condition this
change does not touch, so reverting the guard fails it rather than making the
extraction find nothing.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 8, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 8, 2026 08:58
Five places where the hint reached a host it cannot help, all found by the same
question: does joining the render group change anything here.

The capability override gated on AMD appearing in CHAT_ONLY_MISMATCH_VENDORS.
That set is qualifying physical inventory, and a supported AMD card qualifies
whatever wheel is installed, so a hybrid host running CUDA torch records both
vendors and took the override for a verdict about its NVIDIA card. AMD now also
has to be what this install targets: the only qualifying vendor, or a venv that
asked for ROCm, or a torch carrying a HIP runtime. Those are the two helpers
_devices_that_can_establish_a_mismatch already reads.

The empty-probe explanation classified the build by counting libraries, so a
CUDA-plus-Vulkan build was not CUDA-only and a CPU-only build was not either,
and both were sent after a repair that cannot change what they enumerate. It now
asks which backend the install defers to, which is the question _is_vulkan_backend
already answers, and _backend_lacks_gpu_lib for the CPU case. An install this
probe cannot read stays eligible, so a detection miss does not lose the #10466
host.

That explanation also returned before the visibility masks were inspected. A mask
and a closed node are independent and the groups clear neither, so a host with
both now gets one message naming both.

And the runtime hint claimed the driver is loaded while prescribing only group
membership, even where /dev/kfd does not exist at all. install.sh already keeps
the missing-kernel-stack diagnosis for that host; this is the runtime half.

Nine tests. Five fail on the previous code, four are the controls that bound
them. The existing hybrid-host test was passing for the host's reason rather
than its own, since this venv carries a ROCm torch, and now stubs both helpers.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…lind the build

Two fixes, both narrowing a claim that was made more broadly than the evidence
supported.

The permission hint hard-coded "render,video". That pair is not universal, and
docker/run.sh in this repo already says why: --group-add takes numeric gids
because a name is resolved inside the container, where the host's video and
render groups do not exist, and minimal hosts really do ship without a render
group. A node left root:root by a udev rule is not fixed by joining either one.
The groups are now read from the nodes that were refused -- os.stat().st_gid,
grp.getgrgid() for the name, the GID itself when no group entry matches, since
usermod -a -G takes a number as happily as a name -- with the same derivation in
install.sh through stat -c %G, falling back to %g when stat prints UNKNOWN. The
documented pair remains only as the fallback for a host where nothing could be
read.

The empty-probe explanation named every visibility variable that was merely SET
as a second blocker beside the closed node. HIP_VISIBLE_DEVICES=0 exposes GPU 0
and is not why the probe came back empty, and a Vulkan build reads none of the
four at any value; both were being sent after a change that fixes nothing. Only
a value that can hide every device counts now, and only on a build that reads
it. CUDA and HIP stop at the first entry naming no device, so an empty value or
a leading -1 blinds them while 0,-1 does not. mask_note is unchanged: it
annotates the torch arms, which describe what torch was looking at rather than
claiming a repair.

Fourteen tests. Six fail on the pre-fix code; the rest are the controls that
would fail on the over-broad version of each fix -- a mask that really does hide
everything must still be reported, 0,-1 must not, and both group fallbacks must
still produce advice rather than an empty -G argument. The installer test reads
a real file and asserts the message names that file's actual group.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1dabcd7434

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +2111 to +2112
if node_hint and reason == "torch_cuda_unavailable":
return f"This host has a GPU, but {feature} cannot use it. {node_hint}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve independent ROCm initialization repairs

When a ROCm-targeted host has both closed device nodes and another initialization failure, such as a wheel/runtime incompatibility or an unsupported driver, classify_torch_build() still produces torch_cuda_unavailable and node_hint is nonempty. This unconditional return then removes the existing driver/runtime diagnosis even though joining the groups fixes only one of the two blockers, leaving export and video unavailable after the advertised repair. Retain both pieces of guidance unless the code can positively establish that node permissions are the sole initialization failure.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declining this one, and the bar you set is the reason: the code cannot positively establish that node permissions are the sole failure, and neither can anything else, because a closed node makes every other cause unobservable. torch answers is_available() == False and nothing more, so while the node is shut there is no evidence a second blocker exists.

What it can establish is when the wheel is provably wrong from its own label, and both such cases are already carved out and tested: a CPU-only build keeps the reinstall advice (it has no GPU path either way), and as of this round so does a wheel tagged for another vendor. What is left is a ROCm wheel on an AMD host with a closed node, where "reinstall PyTorch" is exactly the wrong advice that #10466 was filed about.

The diagnosis is also sequential rather than lost: once the groups are joined the hint is None, this message is recomputed, and it then names whatever remains.

Five items, one idea: every sentence this hint prints has to be a change that
would actually open the node.

Groups. _groups_that_own now returns (joinable, unnamed_gids, no_group), read
from the node's mode as well as its gid. A GID with no group entry is reported
rather than handed to usermod -- shadow 4.13 answers "group '993' does not
exist" and exits 6, checked live rather than read out of the man page -- and a
node whose own group has no read and write (a udev rule leaving one 0600) gets
the udev sentence instead of a command that runs and changes nothing. Nodes that
could not be stat'd at all still get the documented pair, since that is a
detection miss rather than evidence.

Missing render node. /dev/kfd mapped without /dev/dri passes every probe here
and still cannot initialise ROCm, because ROCr opens a render node to reach
amdgpu; docker/run.sh passes both devices for that reason. Said alongside the
permission repair, symmetric with the missing-KFD sentence, in both halves.

Visibility masks. The flat first-token rule is replaced by the per-variable
semantics: GPU_DEVICE_ORDINAL through _gpu_device_ordinal_active, which reads
whitespace as no filter; the HIP layer through clr's own precedence, so an empty
CUDA mask behind a valid HIP one is never consulted; and ROCr separately,
because it composes with that layer rather than deferring to it, so an empty
ROCr mask blinds the runtime while HIP wins above it.

Wheel vendor. wheel_targets_amd is now separate from amd_is_the_target: whether
the closed node is worth mentioning is about the hardware, whether it REPLACES
the reinstall advice is about the wheel. A CUDA-tagged build on an AMD-only host
gets both, like the CPU-wheel arm.

Installer. The missing-KFD diagnosis is hoisted out of the */cpu arm to after
the case: it is a property of the host, and the arm the index lands in is not --
the per-arch reroute rewrites exactly that host's cpu index to a gfx one, so it
was missing the case it was written for.

71 tests. Each new one was checked against a reverted fix and fails only on its
own; the installer one distinguishes placement from existence, since the cpu arm
keeps passing under the revert.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…nce cannot support

Five fixes from review of the device-node work.

Moving the two node diagnoses out of the */cpu arm let them reach an index the
reporting case has no arm for at all. _has_amd_rocm_gpu returns false on any host
with a usable NVIDIA GPU, so on a CUDA route its condition held for every hybrid
box with an AMD card on the bus, and someone correctly installing CUDA wheels was
told to install the ROCm kernel stack. Both diagnoses are now gated on the route
being one the case reports a wheel line for.

_gpu_present_but_unusable_message read recorded ROCm intent as evidence that the
installed wheel targets AMD, so a venv that recorded ROCm and then had a CUDA build
installed over it was answered with group membership instead of the reinstall it
needs. The label and the live runtime describe what is installed now, so a label
naming another vendor's accelerator settles it; a bare +cpu names none, so it
settles nothing and the intent still speaks.

A missing render node is not a permission problem and was reported only alongside a
closed one. A container given --device /dev/kfd and not --device /dev/dri opens the
one node it has, so the closed set was empty and nothing was said while ROCr had no
render node to open. Reported independently now, gated on the KFD topology naming
AMD, which is the presence signal that survives having no render node at all.

_hides_every_device judged only the shape of the first entry, but the list stops at
the first index no device answers to, so HIP_VISIBLE_DEVICES=3 on a one-GPU host
exposes nothing. Ordinals are now checked against the KFD GPU-node count, and only
when it can be read.

acl(5): with an access ACL present the group-class bits in st_mode are the ACL mask
rather than the owning group's grant, so prescribing usermod from a stat is a
promise it cannot support. Such a node is reported instead, in both the Python hint
and the installer.

Twenty tests, each fix paired with a control that fails when the fix is written too
broadly: the cpu and rocm routes must still print, a label naming no vendor must
still let the intent speak, a host with no AMD card must not be told to map a render
node, a valid ordinal and an unreadable device count must both leave the selector
alone, and an ordinary node must still be prescribed for.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits September 17, 2026 22:11
Both halves filed every node this account owns as an owner-mode problem and prescribed
a mode change or a udev rule. os.access had already said the node is shut, so where the
OWNER bits already grant read and write the mode is not what denies it: an LSM or a
container device policy is, and neither repair touches that. It is the same external
denial the already-a-member branch reports, reached by owner class instead.

_groups_that_own grows an eighth bucket, external, with its own sentence, and
install.sh's _amd_node_repairs prints external: for the same shape.

Writing the shell half turned up a second one. stat %a drops leading zeros, so mode 060
prints "60" and the owner digit sits at index 0 -- which is not an error in awk: gawk
and mawk return the GROUP digit there and busybox returns "", so the same node would
have been classified differently depending on which awk the host ships. The mode is
padded to three digits before indexing. The group read counts from the right, where the
digit is always second-from-last, so it was already safe and is left alone.

Controls in both directions and in both languages: owner bits that do not grant rw are
still the mode, in Python and read off install.sh, and reverting either branch or the
padding fails exactly its own test.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 57f5f963b2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

danielhanchen added 2 commits September 17, 2026 22:46
Comment-only. The AST gate reports amd.py and llama_cpp.py as code-unchanged; install.sh
is flagged only because the lines live inside a single-quoted awk program, where the
shell parser cannot tell an awk comment from code, and the diff there is those comment
lines alone. Behaviour confirmed unchanged: bash -n, 42 passed in
test_rocminfo_gpu_name_7307.sh, and 367 passed in the AMD suite.
@danielhanchen

Copy link
Copy Markdown
Member Author

Final state on this branch.

Codex is at no open items. The last three rounds fixed, each with a negative control that fails exactly its own test:

  1. The loader-override attribution named a variable by a fixed SELECT-then-DISABLE order, then by a filename-allowance counterfactual. Both could name something that was holding nothing back. The per-variable rules are gone: there is one counterfactual, _the_loader_would_have_a_driver_without, and the answer is the smallest set whose removal leaves a manifest the loader can LOAD. One variable, all of them together, or None and the reinstall sentence.
  2. The no-driver diagnosis was appended into node_hint, which is demoted to "not why the probe is empty" when a sibling render node is open. It empties the probe however the node is owned, so it now rides on the primary reason.
  3. An owned node whose OWNER bits already grant rw was filed as a mode problem in both halves. It is an external denial, and it now says so in amd.py and in install.sh. Writing the shell half turned up that stat %a drops leading zeros, so the owner index was 0 for mode 060 and substr(s, 0, 1) returns the GROUP digit in gawk and mawk and "" in busybox: the same node would have been classified by which awk the host ships. Padded before indexing.

One item was checked and declined: shlex.quote(None) does not raise, it returns '' on 3.9 through 3.13, so there was no TypeError swallowing the repair. I reverted the change and the test I had written for it, since the test passed with and without it.

CI: the red legs are Core, GGUF inference smoke, Repo tests (CPU, python/rest/studio), workflow-trigger lint and connection (codex, stable). All of them fail on a clean origin/main worktree here. Repo tests (CPU, studio) is new on this branch only because merging main brought main's install.ps1 with it: the branch had a stale copy that happened to pass the two test_installer_av_shapes.py bitdefender cases.

Local on this head: 72 shell test files with no failures, and 7384 passed with 36 skipped across the AMD, resolve-prebuilt and install suites.

… a diagnostic from aborting the install

Two defects in the node-permission advice, found by auditing the printed repair rather
than the code that builds it.

The group name is not a token. usermod's -G takes a comma-separated list, so a node whose
owning group is genuinely named "render,sudo" produced a repair command that adds the
account to the second group as well. _PRIVILEGED_GROUPS never matched, because it compares
whole names. Shell quoting is the wrong layer for this and is why it was not caught by it:
_shell_word hands the shell one correctly quoted argument, and the split that grants the
extra membership happens inside usermod afterwards. install.sh had the same hole plus one
of its own, since it parses `stat -c` output with awk -F'|' and a name carrying a pipe
shifted every field after it, including the GID and uid the classifier branches on.

Both halves now treat a name outside the portable groupadd(8) charset as no name at all
and report the node by its GID, which is what --group-add takes anyway, so nothing is
lost. The installer's stat format puts the group name LAST, because it is the one field
NSS controls: winbind hands back DOMAIN\group and a directory can return anything, while
everything before it comes from the kernel or from the node list we passed in.

The second is that a diagnostic could take the install down with it. install.sh runs under
set -e, and three command substitutions in this block were unguarded while shelling out to
stat, awk and tr. Two of them run on every Linux install whether or not anything is
closed. With tr absent the installer exited 127 at the index-leaf read before installing
anything. On such a host the answer has to be "no advice", never "no install", and every
consumer already reads empty as nothing to report.

Verified by reverting each of the six hunks in turn: each fails exactly its own tests and
no others. The controls hold, so this did not collapse into never naming a group -- an
ordinary render, a Samba host$ and a dotted gpu.users-1 are all still prescribed.
…bove

6146 lines to 4873, and 358 test functions to 131, with no case lost: the file now
collects 411 cases against 369 before. Nothing was deleted to get there. The increase is
tests that had been looping over their inputs inside one body, or carrying two independent
arms in one function, becoming real cases that fail one at a time and name themselves.

Three changes, in order of what they were worth.

Shared setup. Every case stubbed the same four things by hand: the shipped ggml libraries,
the capability verdict, the vendors that qualified for the mismatch, and the eight-bucket
group derivation. Those are now _ggml, _empty_probe, _capability_message,
_mismatch_vendors, _owning and _buckets, so a case names only the bucket it populates
instead of counting commas in an eight-element tuple. The two deferred imports are at
module scope, the pair of device nodes a ROCm host has is named once, and the account the
repair commands quote moved into the autouse fixture that already stubs its passwd entry,
since the two cases that are ABOUT which account is named set their own.

Parametrization. Families that differed on one axis -- which node is closed, which backend
is installed, which vendor qualified, which mask is set, which wheel tag, which loader
filter -- are one table each, with an id per row carrying the old test name so a failure
still says which case it was.

Docstrings, compressed rather than cut. They are the reason each control exists and
several record the bug the control found, so the restatement went and the facts stayed:
the shadow 4.13 exit 6 finding, acl(5) mask semantics, the ROCr and clr layering, the
Vulkan loader's documented ordering, the coreutils id.c behaviour, the eight-NVIDIA-card
false positive, and every "fails before the fix" note are all still here.

The tables are hand-wrapped one case to a row and fenced with fmt: off. The repo formatter
explodes any call it cannot fit on one line into one argument per line, which makes a table
LONGER than the tests it replaced -- unfenced, this file formats to 5944 lines and the
exercise is pointless. The file is a fixed point of scripts/run_ruff_format.py as it
stands; everything that is not a table is left formatter-covered.

Also here, because they belong with the file they test: the cases for the two fixes in the
commit before this one. A group name carrying the usermod separator, the awk field
separator, a shell metacharacter or nothing but whitespace is reported by GID rather than
prescribed, with an ordinary name, a Samba machine account and a dotted group as the
controls; and the three install.sh diagnostics are asserted both to carry their guard and
to really survive stat, awk and tr all exiting 127.
… the runner

Real gfx1151 CI on Linux and Windows ran this suite and eight tests failed on
both, identically, while every one of them passes on a box with no AMD GPU. The
tests were reading the runner where they meant to describe a machine.

Three lifted install.sh spans and one Python harness consulted live host state:

  - the `-e /dev/kfd` test in the three-armed kernel-stack case, which decides
    which arm runs, so on a host that has the node the case took a different arm
    than the one under test
  - the KFD sysfs topology, via a `_kfd_topology_has_an_amd_gpu` that was left
    live in two harnesses and stubbed in the others
  - `amd_kfd_gpu_node_count`, unstubbed, so a selector was judged against
    whatever the machine enumerated
  - `substep` and `C_WARN`, undefined in one lifted span

A test operator cannot be stubbed, so `-e` is kept and the PATH it is given now
belongs to the case: `_kfd_node_the_case_owns` rewrites the node in the lifted
script to one the test creates or withholds under tmp_path, and asserts the
installer still tests where the harness expects, so a rewrite of that line fails
loudly rather than silently reading the host again.

That also retires two skips that were each other's complement -- one arm needed
a host with /dev/kfd, its mirror needed a host without -- so the pair could
never both run anywhere. Both now run on every host.

The suite is now identical on three synthesised hosts: no AMD GPU, AMD with the
nodes open, and NVIDIA-only with AMD nodes shut. 410 passed, 1 skipped on each,
where the last of those previously failed six.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: 7976026c93

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ed mask

GGML_VK_VISIBLE_DEVICES=-1 on a Vulkan build with a closed AMD node was reported
as a mask merely worth checking, behind the group repair as the primary advice.
No group membership repairs it.

ggml reads the variable with `size_t tmp; while (ss >> tmp)` in
ggml_vk_instance_init (ggml/src/ggml-vulkan/ggml-vulkan.cpp). Unsigned extraction
applies strtoull, which accepts a sign and wraps, so "-1" arrives as 2**64-1,
trips `tmp >= num_available_devices` and throws "Invalid Vulkan device index".
_run_vulkan_probe turns that nonzero exit into the empty result being diagnosed.
Confirmed against the upstream source and by compiling the same extraction
locally: "-1" yields 18446744073709551615, "abc" fails extraction, "-0" yields 0.

That makes a negative ordinal the one out-of-range value decidable WITHOUT the
raw device count, which is why it is judged here while a merely large positive
one stays unresolved: it wraps past every possible bound. Same treatment an
Illegal ROCr token already gets, and for the same stated reason.

Extraction walks the list, so the scan does too: a negative ordinal throws
wherever it sits, but only if every token ahead of it still extracts, since ggml
stops reading at the first that does not. "-0" wraps to 0 and is in range, so it
is not promoted.

Four cases cover it, two of which fail without the change.
The slimming pass left two module-level constants sharing one name: a dict of
node -> (gid, mode) used by the repair-command cases, and a plain list of the
same three paths used by the open-sibling and shut-node cases below it.

Nothing misbehaves today only because the dict's single use sits inside a
pytest.param evaluated at import, before the rebinding runs. That is precisely
the trap Lint CI names: the later binding wins silently, so the first looks dead
and the next edit to either one reaches the wrong object.

The list is renamed to _THREE_NODE_PATHS, which is also what it is.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ly denied

A node this account neither owns nor shares a group with puts it in the OTHER
permission class. POSIX resolves that one exclusively, exactly as it resolves the
owner class, so when its bits already grant read and write the mode is not what
denies a node os.access() has just called shut. Something outside the mode is: a
container device cgroup, or an LSM. Neither chmod nor usermod moves it.

Both halves classified such a node from the GROUP bits instead and answered with
a group to join, or with a mode repair, neither of which can work. A render node
left 0666 by a udev rule, on a host with an LSM policy over it, is the shape.

The rule was already written twice in this file for the other two classes: the
owner branch files an owned node whose owner bits grant rw under external, and
the already-a-member branch says a group this account holds is not what denies
it. This is the same rule for the one class that was left reading its
neighbour's bits.

Verified rather than assumed, since it turns on permission-class precedence: a
file owned by this account at mode 0006, where only the other bits grant rw, is
refused by both os.access and open(). The first matching class decides alone.

Placed above the group-bits test, which would otherwise prescribe a chmod, and
guarded on membership, since a member is in the group class and `already` names
the group more precisely. The awk mirror in install.sh takes the same branch and
needs no padding for it: the other digit is the last one.

Three cases plus the installer twin; the two asserting the new behaviour fail
without the change, and the two controls hold.
… runs on

Staging CI on macos-15 failed nine of these, and both causes were in the harness.

os.listxattr does not exist on macOS or Windows, so monkeypatching it raised
AttributeError on the PATCH and the ACL cases never reached the probe they are
about. raising=False fixes it; the probe already answers False through the same
AttributeError there, which is what those cases assert about a host that cannot
report an ACL. All five now run on a Mac instead of erroring.

The rest lift install.sh's real stat|awk classifier onto the running host. It
reads each node with GNU `stat -c '%a|%g|%u|%n|%G'`, and BSD stat rejects -c
outright, so the record arrived empty, the owner branch could not match a uid it
never parsed, and every node fell through to "join a group". That is the harness
speaking, not the installer, which gates every diagnosis reaching that classifier
on `[ "$OS" != "macos" ]` and so never runs it on a Mac at all.

Six of those cases failed. The other nineteen PASSED, on the fallback sentence
rather than the branch they name, which is the worse half of the same problem:
they were green for a reason unrelated to their subject. All twenty-five now skip
together with one stated reason.

Keyed on the OS, never on hardware. Every Linux host still runs all of them
whatever GPU it has, which is the property the rest of this file was fixed to
keep, and the synthetic-record harness beside this one stubs stat and so still
runs everywhere.

Verified by standing in for a Mac at exactly the two points that broke there,
platform.system() and the missing os.listxattr: 393 passed, 26 skipped, none
failed, with the ACL cases among the passes. Linux is unchanged at 418 passed
and 1 skipped, identical across all three synthesised hosts.
… import

Staging CI on windows-latest did not fail a test, it failed to reach one:

    studio\backend\tests\test_amd_device_node_permissions.py:26: in <module>
        import grp
    E   ModuleNotFoundError: No module named 'grp'
    ERROR studio/backend/tests/test_amd_device_node_permissions.py
    1 error in 3.75s

grp and pwd are POSIX-only. Imported at module level they took the ENTIRE file
down at collection, so it reported one error rather than its own verdict, and no
Windows job could ever have told us anything about this change. The production
module imports both inside the functions that need them, for this exact reason.

Two skipif DECORATORS called os.geteuid(), which does not exist there either.
Decorators are evaluated at import, so each was a second whole-file collection
error waiting behind the first; they now go through a helper that answers "not
root" on a platform with no such idea.

With collection fixed, the file skips as a unit on Windows, which is the honest
answer rather than a workaround: there is no /dev, no POSIX group, and no device
node mode, and amd_nodes_closed_to_this_user returns [] with
amd_node_permission_hint returning None on any non-Linux host. The AMD CI run on
a real Windows box asserted exactly that about this change.

macOS is deliberately NOT skipped. It has both modules, and the cases that fake a
Linux host exercise the real logic there.

Windows, stood in for at the four points that actually broke (platform.system,
grp, pwd, os.geteuid): 419 skipped, no collection error, where it was 1 error and
0 tests. Restoring the module-level import reproduces the original error exactly.
macOS is unchanged at 393 passed and 26 skipped, Linux at 418 and 1 across all
three synthesised hosts.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…e left

The mapping branch was gated on the KFD topology alone, so the container the
whole diagnosis was written for got no diagnosis at all: --device /dev/dri with
no --device /dev/kfd, and /sys/class/kfd masked along with it.

Nothing else covers that host. The two PCI branches below need
`! _has_amd_rocm_gpu`, and amd-smi answers through sysfs and libdrm there, so it
reports the card and silences both. The closed-node list cannot speak for it
either: /dev/kfd does not EXIST, and a node that is absent is never a node that
is shut. The run finished silently while HIP had nothing to open.

The Python half already reads it the other way. _amd_nodes_the_runtime_lacks
takes the topology first and falls back to a CONFIRMED AMD render node when the
topology cannot be read at all, which is exactly state 2 of the shell tri-state.
The two halves are meant to agree; this one did not.

_amd_silicon_behind_a_missing_kfd mirrors it question for question. Confirmed
rather than merely present, so an NVIDIA-only host whose sysfs is masked the same
way cannot claim an AMD card, and the state is captured rather than tested inline
because this runs under set -e, where a bare non-zero command ends the installer
instead of answering.

The harness lifts the new predicate and stubs only its three inputs, so the arms
measure the rule rather than a copy of it. Three cases: the container, a masked
sysfs with no confirmed node (stays silent, or the branch becomes "always
advise"), and a readable topology naming no AMD that DRM must not rescue.
Reverting the fallback fails the first and leaves both controls green.
…nuation lines

The installer prints that repair across a line continuation: a groupadd, then a
trailing backslash, then an indented usermod on the next line.

The test collected the two lines separately and ran `bash -n` on each, so the
first half it checked was not a command at all: it ends in a dangling backslash.
GNU bash accepts one at end of input and exits 0, which is why this passed on
every Linux runner. bash 3.2, the one macOS ships, calls it "syntax error:
unexpected end of file", and staging CI on macos-15 failed exactly there.

So the test was green on Linux for a reason unrelated to its subject, and the
thing it claims to check, that the emitted repair is runnable, was never checked
on either platform.

The lines are now reassembled across the continuation before parsing, and a
repair that ends mid-continuation is its own assertion rather than a fragment
quietly dropped. The parse is then of the whole command, which is what the
docstring always said it was, and no longer depends on which bash the host ships.

I could not reproduce the strict rejection locally: dash accepts the dangling
backslash as well, so it is not a stand-in for bash 3.2. The evidence is the
macOS CI log, and the fix stands on not handing a fragment to any parser.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…not the owner

A defect of the other-class fix two commits back rather than of the code it
changed. That fix routed a node this account neither owns nor shares a group with
into the `external` bucket, which was correct, but the sentence that bucket
prints was written when it held only one shape and opens "is owned by this
account and its owner bits already grant read and write".

So the reader of a mode-0666 node denied by an LSM was told it owns a node it
does not, in the one sentence whose job is to establish that the mode is not the
problem. That claim is checkable in a second with ls -l, and finding it false is
a good reason to disbelieve the rest of the diagnosis.

One bucket now holding two shapes needs wording true of both, so it names the
permission bits that apply to this account rather than the owner's. Both halves
say it the same way, since the installer emitted the identical claim.

The case that pinned the old phrasing now also asserts the ownership claim is
absent, so restoring it fails rather than passing quietly; reverting the sentence
does fail that case. The two existing tests already compose to the whole claim,
one showing an other-class node lands in `external` and this one showing
`external` never claims ownership, so no third test was added for it.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…loaded

The userspace-only branch claimed the AMD kernel stack was already loaded on the
strength of /dev/kfd existing. Existence proves a node is there, not that the AMD
driver created it, and that branch then tells the user to install rocminfo when
the real repair is the kernel stack.

_kfd_node_is_amds reads the KFD topology as a TRI-STATE rather than requiring
vendor 4098 outright, and the distinction is the whole fix:

  state 1, read and holding no AMD agent, is the only reading that CONTRADICTS
    the claim, so the userspace advice is withheld and the kernel-stack branch
    takes the host instead;
  state 2, a topology that cannot be read at all, leaves the claim unproven
    rather than false. That is the container mapping /dev/kfd while masking
    /sys/class/kfd, and a strict "require 4098" gate would silently drop the
    diagnosis it gets today.

The second arm is widened to match, so a /dev/kfd carrying no AMD agent reaches
"install the ROCm kernel stack", which is what that host actually needs.

Three arms cover it: a topology naming AMD still gets the userspace advice, a
readable one naming none gets the kernel-stack advice, and an unreadable one
keeps today's behaviour. Reverting either gate fails this pair.

On the premise: the reviewer's reasoning rested on NVIDIA's open kernel module
registering KFD nodes, which this repository asserts in five places. I could not
corroborate it from NVIDIA's documentation or the open-gpu-kernel-modules source,
and the only source I found asserting it is this PR, so I have not relied on it.
The fix stands on the weaker and solid ground that an existing node does not
establish an AMD agent, whatever else may create one.
…ns about

install.sh is #!/bin/sh and CI runs shellcheck over it. This change was the only
new finding the PR added: 52 on the merge base, 53 at head.

SC2012 is about globbing ls output for FILENAMES, which breaks on whitespace and
newlines. This reads column 11 of the mode string for one explicitly named node,
and the trailing "+" it looks for is the access-ACL marker, which is exactly what
find -printf cannot report and why getfacl, absent on many hosts here, is not
used instead. So the rule does not apply, and the disable carries that reason
rather than silencing it bare.

Back to 52, so the PR adds no shellcheck finding. The job is informational and
does not gate; this is about not leaving an unexplained one behind.

Also checked the file with the right parser while here. I had been validating
these edits with `bash -n`, which is the wrong one for a #!/bin/sh script; dash
accepts the file, so the two functions added earlier are POSIX after all.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 7cb45fef72

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Post-convergence comment pass, comments only and AST-verified.

Scope is what this PR ADDS, not the whole of every file it touches: llama_cpp.py
carries 12k comment lines and this change accounts for a hundred of them, so a
whole-file target would mean rewriting other people's work under cover of this
branch. The pre-existing Windows shortcut block and the HSA_OVERRIDE paragraph
are left alone for the same reason.

Seventeen multi-line paragraphs collapsed, each to the facts a reader cannot
recover from the code: the two layers that read a group name as structure, the
strtoull wrap that makes a negative Vulkan ordinal always throw, why intent is
the last resort and not the first, the tri-state readings that separate
"contradicted" from "unproven". What went is narration around them -- restating
the branch below, re-explaining a rule already stated two lines up, and recording
which earlier version got it wrong where the test already pins the behaviour.

Added comment lines per file: install.sh 314 -> 293, llama_cpp.py 140 -> 128,
amd.py 200 -> 186, hardware.py 44 -> 20.

comment_tools check passes on all four, shellcheck holds at 52 findings (the
merge-base count), dash -n is clean and the suite is 421 passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Inference does not use AMD iGPU on Strix Halo without appropriate permissions

3 participants