[PR #5427] [Other] Drafting: a GPU lookup that found no card is made again, so a service started at boot gets DFlash2 #5419

Open
opened 2026-11-07 16:35:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5427
Author: @ezoushen
Created: 11/6/2026
Status: 🔄 Open

Base: main ← Head: drafting-boot-lookup


📝 Commits (1)

  • 8773d77 drafting: a GPU lookup that found no card is made again at the next call, so a service started at boot before the NVIDIA driver answers gets DFlash2 (it kept the MTP, "DFlash2 isn't available on this graphics card"); a card that was found is still looked up once; tests

📊 Changes

2 files changed (+41 additions, -14 deletions)

View changed files

📝 strata_control/drafting.py (+17 -14)
📝 tests/terminal/test_drafting_hardware.py (+24 -0)

📄 Description

Problem and result

strata serve runs as a systemd unit, with "drafting": "dflash2" named in its config. Started at boot, it chose the MTP every time with [strata] Drafting: MTP (DFlash2 isn't available on this graphics card). A systemctl restart of the same unit later in the same boot chose drafting: DFlash2 alone, and the engine then ran it: strata serve: DFlash2 drafter on (…q4_0-selq4.pack, graphs captured in 5 ms). /metrics showed "drafting": "dflash2".

Cause, from the code and the logs below:

  • The lookup. About 0.4 s after systemd started the unit, the process asked nvidia-smi for the card. The NVIDIA driver did not answer yet: exit code 9, "couldn't communicate with the NVIDIA driver". /sys/class/drm listed only card0; the NVIDIA card appears as card1 once nvidia-drm initializes, about half a second later. rocminfo and sycl-ls are not installed on this box.
    • In the code, that lookup is strata_cli/cli.py _serve -> _launch_plan -> serve/server.py engine_args -> drafting.detect_hardware(). I traced this call stack in the 0.1.57 build. Which function made the call at boot was not logged.
  • What it kept (inferred). detect_backend() returned None, and detect_hardware() kept (None, []) in _HARDWARE for the life of the process. This is inferred from the code and the change in outcome; the return value was not logged.
  • What the start did with it. The engine start 12 s later used (None, []): hardware_support(None) gives can_run=False. With DFlash2 named in the config, decide() then picks the MTP with NOT_THIS_CARD.

After this change, a lookup that found no card is not kept, and the next call probes again. A card that was found is still looked up once. On the same box with the same unit, the start chooses DFlash2 at boot.

Code nvidia-smi wrapper (below) Drafter at boot (first Drafting line of the boot)
0.1.57 as released no MTP "isn't available on this graphics card", 6 of 6 boots
0.1.57 as released yes MTP "isn't available on this graphics card", 1 of 1 boot
0.1.57 with this detect_hardware() yes DFlash2 alone, 2 of 2 boots

One of these boots used a version of this patch that differed only in the docstring.

Logs

nvidia-smi calls made by the Strata process at boot. A wrapper script placed first on the unit's PATH logged each call with the uptime, the exit code, the arguments and the /sys/class/drm entries, then ran /usr/bin/nvidia-smi. The kernel and service lines come from journalctl -o short-monotonic.

I trimmed the lines: the pid and ppid, and repeated drm and out fields, are removed. The released-0.1.57 block was copied from my terminal output, because the log file was cleared before the next boot.

The --query-gpu=index,compute_cap call at about 16.3-16.5 s is a different query. It does not go through engine_component._smi_query; in the code it is the BUILD.json architecture check in serve/server.py.

Released 0.1.57:

uptime 4.25-4.29 rc 9 args [--query-gpu=name --format=csv,noheader] drm [card0 card0-Unknown-1 version] out [NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.]
uptime 4.29-4.31 rc 9 args [--query-gpu=compute_cap --format=csv,noheader] drm [card0 card0-Unknown-1 version]
uptime 4.91-4.94 rc 0 args [--query-gpu=name --format=csv,noheader] drm [card1 card1-DP-1 card1-DP-2 card1-HDMI-A-1 card1-HDMI-A-2 renderD128 version] out [NVIDIA GeForce RTX 4080 SUPER]
uptime 4.94-4.97 rc 0 args [--query-gpu=driver_version --format=csv,noheader] out [595.91.07]
uptime 16.30-16.33 rc 0 args [--query-gpu=index,compute_cap --format=csv,noheader] out [0, 8.9]

[    3.866521] systemd[1]: Started ai-strata-qwen.service
[    4.714706] kernel: [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:03:00.0 on minor 1
[   16.401158] strata[1140]: [strata] Drafting: MTP (DFlash2 isn't available on this graphics card)

With this change:

uptime 4.31-4.34 rc 9 args [--query-gpu=name --format=csv,noheader] drm [card0 card0-Unknown-1 version]
uptime 4.34-4.36 rc 9 args [--query-gpu=compute_cap --format=csv,noheader] drm [card0 card0-Unknown-1 version]
uptime 4.98-5.01 rc 0 args [--query-gpu=name --format=csv,noheader]
uptime 5.01-5.04 rc 0 args [--query-gpu=driver_version --format=csv,noheader]
uptime 16.39-16.42 rc 0 args [--query-gpu=name --format=csv,noheader]
uptime 16.54-16.57 rc 0 args [--query-gpu=index,compute_cap --format=csv,noheader]

[    3.902642] systemd[1]: Started ai-strata-qwen.service
[    4.776521] kernel: [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:03:00.0 on minor 1
[   16.654759] strata[1126]: [strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.7)

none. I searched the open and closed issues and pull requests for DFlash2, MTP and boot or start-up detection.

  • #5155 also ends on the MTP, but because the drafter was not downloaded yet.
  • #5388 also ends on the MTP. It states no reason, and its setup (2 cards, PARALLEL=8) differs from this one.

This is a focused fix, with no default and no feature change.

Approach

Only drafting.detect_hardware() changes: it keeps its answer only when a backend was found.

I did not change the unit's ordering instead (for example After=nvidia-persistenced.service). Strata's start should not depend on how a user or an app wrote the autostart, and the ordering does not promise that the driver answers. strata serve already calls detect_hardware() again at the real start, so not keeping the failed answer is enough.

Compatibility:

  • A computer where a card is found: unchanged. One lookup per process, the same result.

  • A computer where no card is found: each call to detect_hardware() probes again, in engine_component.detect_backend(). What a probe costs depends on the system (read in the code, not measured):

    • Linux with no GPU tool installed: shutil.which and sysfs reads.
    • Windows: first the display adapter list, which is cached for 120 s.
    • A GPU tool that is installed but does not answer: the nvidia-smi --query-gpu=name, rocminfo (hipInfo on Windows) and sycl-ls probes are not cached and have an 8 s timeout each. A hung tool can therefore cost its timeout on each call instead of once.

    I did not measure how often detect_hardware() is called on such a computer.

Validation

Revisions:

  • main at 9f7d977d2 with this patch, for the tests.
  • The 0.2.11 release (strata --version: 0.2.11, build 0.1.57) for the hardware runs, with detect_hardware() in the installed strata_control/drafting.py replaced by the patched function (the same text). The function in 0.1.57 is identical to the one on main before this patch.

Passed:

  • python -m pytest tests/terminal/test_drafting_hardware.py, on macOS 27.0.1 with Python 3.14.8 (pytest 9.2.0, requirements.txt and textual 8.2.8): 30 passed.
    • test_a_lookup_that_found_no_card_is_made_again fails on 9f7d977d2 without the code change: Tuples differ: (None, []) != ('cuda', ['sm_89']). It passes with the change.
    • Keeping the failed answer on purpose (if True: in place of if backend is not None:) makes that test fail again.
    • test_a_card_that_was_found_is_looked_up_once passes before and after. It fails when nothing is kept (if False: in place of if _HARDWARE:): 2 != 1 calls of detect_backend.
  • python -m pytest tests/terminal, on the same macOS environment, run on 9f7d977d2 and again with the patch.
    • Without the patch: 265 failed, 2424 passed, 64 skipped, 8 errors.
    • With the patch: 265 failed, 2426 passed, 64 skipped, 8 errors.
    • The two extra passes are the new tests. No test fails only with the patch.
  • Hardware:
    • Ubuntu 24.04.5 LTS, kernel 6.8.0-147-generic, RTX 4080 SUPER 16 GB, driver 595.91.07 (NVIDIA open kernel module).
    • The unit: User= a normal user, After=network-online.target, WantedBy=multi-user.target, ExecStart=… strata serve --config <file> --host 0.0.0.0 --port 8080 --parallel 1.
    • Model: Qwen3.8-Flash-Next UD-IQ3_XXS (Unsloth v3.1), with "drafting": "dflash2".
    • Result: DFlash2 at boot with the patched function (2 of 2 boots), MTP without it (7 of 7 boots). The table and logs are above.

Failed:

none caused by this change. The tests in tests/terminal that fail in my environment fail the same way with and without the patch (the list is identical). They come from a sparse checkout without docs/ and most of apps/, and from Python 3.14 on macOS.

Not run:

  • Windows, the macOS app, AMD (HIP) and Intel (SYCL) hardware.
  • The desktop app's autostart path.
  • The test suite on Python 3.12 or on Linux.
  • A computer with no GPU, or with a GPU tool that hangs: the cost of probing again is not measured.
  • No backend build: the change is Python only.

Limits

  • The card's architecture list can still be empty after a boot like this one.
    • engine_component._smi_query keeps a failed compute_cap answer for 30 s by design (round 0213: a stuck driver should cost its timeout once). The first look, at about 0.4 s, asks for compute_cap while the driver does not answer yet. The logs show a failed --query-gpu=compute_cap at 4.34 s and no --query-gpu=compute_cap call after it.
    • So the start 12 s later most likely gets ("cuda", []). This is inferred from the code and that log; the value itself was not logged.
    • Skipping the architecture probe in detect_hardware() when no backend was found is not enough. I tried that variant on the same box, and a failed --query-gpu=compute_cap call still came at 4.28 s from another caller. By the order in engine_args, that caller is drafting_card_class() (inferred, not traced). From reading the code, updater.detect_hardware() also asks for compute_cap.
    • For CUDA this does not change whether DFlash2 runs, because hardware_support("cuda", []) gives can_run=True.
    • From reading the code only (unconfirmed static analysis), it would change the tested or slower line for sm_120 and sm_86, and the sm_121 branch in drafting_vram_mib. On this card (sm_89, in neither table) I could not observe a difference.
    • I left this alone because it touches the deliberate 30 s caching of failed answers.
  • drafting_card_class() also keeps its first answer for the life of the process (_CARD_CLASS). decide() says klass is not used any more, so I left it as it is.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5427 **Author:** [@ezoushen](https://github.com/ezoushen) **Created:** 11/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `drafting-boot-lookup` --- ### 📝 Commits (1) - [`8773d77`](https://github.com/Niko1221/Strata/commit/8773d77999cf76efdfe2996c8d74acd72ae816ec) drafting: a GPU lookup that found no card is made again at the next call, so a service started at boot before the NVIDIA driver answers gets DFlash2 (it kept the MTP, "DFlash2 isn't available on this graphics card"); a card that was found is still looked up once; tests ### 📊 Changes **2 files changed** (+41 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `strata_control/drafting.py` (+17 -14) 📝 `tests/terminal/test_drafting_hardware.py` (+24 -0) </details> ### 📄 Description ## Problem and result `strata serve` runs as a systemd unit, with `"drafting": "dflash2"` named in its config. Started at boot, it chose the MTP every time with `[strata] Drafting: MTP (DFlash2 isn't available on this graphics card)`. A `systemctl restart` of the same unit later in the same boot chose `drafting: DFlash2 alone`, and the engine then ran it: `strata serve: DFlash2 drafter on (…q4_0-selq4.pack, graphs captured in 5 ms)`. `/metrics` showed `"drafting": "dflash2"`. Cause, from the code and the logs below: - **The lookup.** About 0.4 s after systemd started the unit, the process asked `nvidia-smi` for the card. The NVIDIA driver did not answer yet: exit code 9, "couldn't communicate with the NVIDIA driver". `/sys/class/drm` listed only `card0`; the NVIDIA card appears as `card1` once `nvidia-drm` initializes, about half a second later. `rocminfo` and `sycl-ls` are not installed on this box. - In the code, that lookup is `strata_cli/cli.py` `_serve` -> `_launch_plan` -> `serve/server.py` `engine_args` -> `drafting.detect_hardware()`. I traced this call stack in the 0.1.57 build. Which function made the call at boot was not logged. - **What it kept (inferred).** `detect_backend()` returned `None`, and `detect_hardware()` kept `(None, [])` in `_HARDWARE` for the life of the process. This is inferred from the code and the change in outcome; the return value was not logged. - **What the start did with it.** The engine start 12 s later used `(None, [])`: `hardware_support(None)` gives `can_run=False`. With DFlash2 named in the config, `decide()` then picks the MTP with `NOT_THIS_CARD`. After this change, a lookup that found no card is not kept, and the next call probes again. A card that was found is still looked up once. On the same box with the same unit, the start chooses DFlash2 at boot. | Code | `nvidia-smi` wrapper (below) | Drafter at boot (first `Drafting` line of the boot) | |---|---|---| | 0.1.57 as released | no | MTP "isn't available on this graphics card", 6 of 6 boots | | 0.1.57 as released | yes | MTP "isn't available on this graphics card", 1 of 1 boot | | 0.1.57 with this `detect_hardware()` | yes | DFlash2 alone, 2 of 2 boots | One of these boots used a version of this patch that differed only in the docstring. ### Logs `nvidia-smi` calls made by the Strata process at boot. A wrapper script placed first on the unit's `PATH` logged each call with the uptime, the exit code, the arguments and the `/sys/class/drm` entries, then ran `/usr/bin/nvidia-smi`. The kernel and service lines come from `journalctl -o short-monotonic`. I trimmed the lines: the pid and ppid, and repeated `drm` and `out` fields, are removed. The released-0.1.57 block was copied from my terminal output, because the log file was cleared before the next boot. The `--query-gpu=index,compute_cap` call at about 16.3-16.5 s is a different query. It does not go through `engine_component._smi_query`; in the code it is the BUILD.json architecture check in `serve/server.py`. Released 0.1.57: ```text uptime 4.25-4.29 rc 9 args [--query-gpu=name --format=csv,noheader] drm [card0 card0-Unknown-1 version] out [NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.] uptime 4.29-4.31 rc 9 args [--query-gpu=compute_cap --format=csv,noheader] drm [card0 card0-Unknown-1 version] uptime 4.91-4.94 rc 0 args [--query-gpu=name --format=csv,noheader] drm [card1 card1-DP-1 card1-DP-2 card1-HDMI-A-1 card1-HDMI-A-2 renderD128 version] out [NVIDIA GeForce RTX 4080 SUPER] uptime 4.94-4.97 rc 0 args [--query-gpu=driver_version --format=csv,noheader] out [595.91.07] uptime 16.30-16.33 rc 0 args [--query-gpu=index,compute_cap --format=csv,noheader] out [0, 8.9] [ 3.866521] systemd[1]: Started ai-strata-qwen.service [ 4.714706] kernel: [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:03:00.0 on minor 1 [ 16.401158] strata[1140]: [strata] Drafting: MTP (DFlash2 isn't available on this graphics card) ``` With this change: ```text uptime 4.31-4.34 rc 9 args [--query-gpu=name --format=csv,noheader] drm [card0 card0-Unknown-1 version] uptime 4.34-4.36 rc 9 args [--query-gpu=compute_cap --format=csv,noheader] drm [card0 card0-Unknown-1 version] uptime 4.98-5.01 rc 0 args [--query-gpu=name --format=csv,noheader] uptime 5.01-5.04 rc 0 args [--query-gpu=driver_version --format=csv,noheader] uptime 16.39-16.42 rc 0 args [--query-gpu=name --format=csv,noheader] uptime 16.54-16.57 rc 0 args [--query-gpu=index,compute_cap --format=csv,noheader] [ 3.902642] systemd[1]: Started ai-strata-qwen.service [ 4.776521] kernel: [drm] Initialized nvidia-drm 0.0.0 20160202 for 0000:03:00.0 on minor 1 [ 16.654759] strata[1126]: [strata] drafting: DFlash2 alone (--draft dflash2, --draft-conf 0.7) ``` ## Related discussion none. I searched the open and closed issues and pull requests for DFlash2, MTP and boot or start-up detection. - #5155 also ends on the MTP, but because the drafter was not downloaded yet. - #5388 also ends on the MTP. It states no reason, and its setup (2 cards, `PARALLEL=8`) differs from this one. This is a focused fix, with no default and no feature change. ## Approach Only `drafting.detect_hardware()` changes: it keeps its answer only when a backend was found. I did not change the unit's ordering instead (for example `After=nvidia-persistenced.service`). Strata's start should not depend on how a user or an app wrote the autostart, and the ordering does not promise that the driver answers. `strata serve` already calls `detect_hardware()` again at the real start, so not keeping the failed answer is enough. Compatibility: - **A computer where a card is found:** unchanged. One lookup per process, the same result. - **A computer where no card is found:** each call to `detect_hardware()` probes again, in `engine_component.detect_backend()`. What a probe costs depends on the system (read in the code, not measured): - **Linux with no GPU tool installed:** `shutil.which` and sysfs reads. - **Windows:** first the display adapter list, which is cached for 120 s. - **A GPU tool that is installed but does not answer:** the `nvidia-smi --query-gpu=name`, `rocminfo` (`hipInfo` on Windows) and `sycl-ls` probes are not cached and have an 8 s timeout each. A hung tool can therefore cost its timeout on each call instead of once. I did not measure how often `detect_hardware()` is called on such a computer. ## Validation Revisions: - `main` at 9f7d977d2 with this patch, for the tests. - The 0.2.11 release (`strata --version`: 0.2.11, build 0.1.57) for the hardware runs, with `detect_hardware()` in the installed `strata_control/drafting.py` replaced by the patched function (the same text). The function in 0.1.57 is identical to the one on `main` before this patch. **Passed:** - `python -m pytest tests/terminal/test_drafting_hardware.py`, on macOS 27.0.1 with Python 3.14.8 (pytest 9.2.0, requirements.txt and textual 8.2.8): 30 passed. - `test_a_lookup_that_found_no_card_is_made_again` fails on 9f7d977d2 without the code change: `Tuples differ: (None, []) != ('cuda', ['sm_89'])`. It passes with the change. - Keeping the failed answer on purpose (`if True:` in place of `if backend is not None:`) makes that test fail again. - `test_a_card_that_was_found_is_looked_up_once` passes before and after. It fails when nothing is kept (`if False:` in place of `if _HARDWARE:`): `2 != 1` calls of `detect_backend`. - `python -m pytest tests/terminal`, on the same macOS environment, run on 9f7d977d2 and again with the patch. - Without the patch: 265 failed, 2424 passed, 64 skipped, 8 errors. - With the patch: 265 failed, 2426 passed, 64 skipped, 8 errors. - The two extra passes are the new tests. No test fails only with the patch. - Hardware: - Ubuntu 24.04.5 LTS, kernel 6.8.0-147-generic, RTX 4080 SUPER 16 GB, driver 595.91.07 (NVIDIA open kernel module). - The unit: `User=` a normal user, `After=network-online.target`, `WantedBy=multi-user.target`, `ExecStart=… strata serve --config <file> --host 0.0.0.0 --port 8080 --parallel 1`. - Model: Qwen3.8-Flash-Next UD-IQ3_XXS (Unsloth v3.1), with `"drafting": "dflash2"`. - Result: DFlash2 at boot with the patched function (2 of 2 boots), MTP without it (7 of 7 boots). The table and logs are above. **Failed:** none caused by this change. The tests in `tests/terminal` that fail in my environment fail the same way with and without the patch (the list is identical). They come from a sparse checkout without `docs/` and most of `apps/`, and from Python 3.14 on macOS. **Not run:** - Windows, the macOS app, AMD (HIP) and Intel (SYCL) hardware. - The desktop app's autostart path. - The test suite on Python 3.12 or on Linux. - A computer with no GPU, or with a GPU tool that hangs: the cost of probing again is not measured. - No backend build: the change is Python only. ## Limits - **The card's architecture list can still be empty after a boot like this one.** - `engine_component._smi_query` keeps a failed `compute_cap` answer for 30 s by design (round 0213: a stuck driver should cost its timeout once). The first look, at about 0.4 s, asks for `compute_cap` while the driver does not answer yet. The logs show a failed `--query-gpu=compute_cap` at 4.34 s and no `--query-gpu=compute_cap` call after it. - So the start 12 s later most likely gets `("cuda", [])`. This is inferred from the code and that log; the value itself was not logged. - Skipping the architecture probe in `detect_hardware()` when no backend was found is not enough. I tried that variant on the same box, and a failed `--query-gpu=compute_cap` call still came at 4.28 s from another caller. By the order in `engine_args`, that caller is `drafting_card_class()` (inferred, not traced). From reading the code, `updater.detect_hardware()` also asks for `compute_cap`. - For CUDA this does not change whether DFlash2 runs, because `hardware_support("cuda", [])` gives `can_run=True`. - From reading the code only (unconfirmed static analysis), it would change the tested or slower line for `sm_120` and `sm_86`, and the `sm_121` branch in `drafting_vram_mib`. On this card (`sm_89`, in neither table) I could not observe a difference. - I left this alone because it touches the deliberate 30 s caching of failed answers. - `drafting_card_class()` also keeps its first answer for the life of the process (`_CARD_CLASS`). `decide()` says `klass` is not used any more, so I left it as it is. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5419
No description provided.