Skip to content

gate-batch: a local batch runs one lane and packs against the machine's own memory - #1125

Merged
juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-device-runner-resources
Nov 2, 2026
Merged

juliankang4 merged 3 commits into
midagedev:mainfrom
juliankang4:dgx-spark-q38-device-runner-resources

Conversation

@juliankang4

Copy link
Copy Markdown
Collaborator

로컬 모드의 GPU 선택을 박스의 카드 이름 대신 실제로 보이는 카드에서 읽고, 로컬 gate-batch가 레인 1개와 그 머신의 메모리로 묶도록 바꾸는 도구 PR입니다.

What and why

Local mode (BLOOMERY_BOX_LOCAL=1) still chose cards by the two names of the maintainer workstation, so BLOOMERY_CARD=both was refused on every machine, including one with two cards, and a machine with several cards could not time on the card it had in view. A local batch also ran two lanes, although every local gate takes the one local gate lock, and packed its loads against the workstation's memory figure instead of the machine's own.

cards_view in tools/ref/cards.sh now says which cards a local run uses. It reads the listed cards from nvidia-smi and takes the caller's CUDA_VISIBLE_DEVICES (UUIDs, unique UUID prefixes, or indices) as the view. A failing nvidia-smi, an empty view, an entry that names no listed card, a repeated card, and an index that CUDA's default device order could read as another card are each refused with the reason. tools/box.sh, tools/gpu-gate.sh and tools/ref/timing-card.sh take their local cards from it, so BLOOMERY_CARD=both and BLOOMERY_GATE_CARD=both run when two or more cards are in view and are refused, naming the cards, when fewer are. tools/ref/tier-cost.sh drops its own physical-card count, and the stub runners embed the real cards_view. In local mode tools/gate-batch.sh defaults to --lanes 1; --lanes 2 still runs two lanes and packs against the machine's MemAvailable less the same 1 GiB margin, read once at start. BLOOMERY_PACK_BUDGET still overrides, and the box's defaults are unchanged. tools/gate-batch-resources.tsv's header, docs/contrib/local-check.md, docs/contrib/dgx-spark.md, docs/BUILD.md and the justfile comments now describe this.

Release notes: Changed: local gate runs read their cards from the cards in view, so the two-card recipes run on a machine with two or more cards, and a local gate-batch runs one lane by default.

Code shape

  • No second copy. One selector, cards_view, replaces the name checks in tools/box.sh, tools/gpu-gate.sh and tools/ref/timing-card.sh, and the separate card count in tools/ref/tier-cost.sh is removed. The stub tree embeds the real function instead of a copy.
  • Model code holds only architecture facts. No model code changes.
  • Dead code is gone.
  • No silent failure. cards_view returns a named reason for every refusal and each caller turns it into a named refusal (exit 64); tools/gate-batch.sh stops by name when /proc/meminfo gives nothing.
  • Comments state what is true now.
  • No relaxed gate. No band, tolerance or lint moved.
  • cargo fmt and cargo clippy are clean on what I touched; the lint count did not go up.

Duplication found or removed (path:line): none.

What I ran

Base e635e3fb7b82a656f5b7b9849fb5da79bdf0a980, PR head 0319b30125c9ceb4b518d5b03e740937bdc824a1.

The selector and the two-card refusals on the card, through box.sh's local mode (BLOOMERY_BOX_LOCAL=1). The probe reads the view through cards_view with the caller's CUDA_VISIBLE_DEVICES unset, as an index, as a UUID prefix, as an index past the list, as an unlisted UUID and as a card named twice, then runs timing-card.sh through tools/box.sh and asks for both:

$ nvidia-smi
Mon Nov  2 01:31:43 2026       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 595.84                 Driver Version: 595.84         CUDA Version: 13.3     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GB10                    On  |   0000000F:01:00.0 Off |                  N/A |
| N/A   51C    P8              4W /  N/A  | Not Supported          |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+

$ nvidia-smi --query-gpu=name,driver_version --format=csv,noheader
NVIDIA GB10, 595.84

$ BLOOMERY_CARD=both tools/box.sh 'echo BOTH-RAN'
box.sh: BLOOMERY_CARD=both runs on two or more cards in view, and this machine has 1 in view: GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb
BOTH-BOX rc=64
VIEW[unset] rc=0 n=1 view=GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb why=
VIEW[0] rc=0 n=1 view=GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb why=
VIEW[GPU-7d7913f3] rc=0 n=1 view=GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb why=
VIEW[1] rc=1 n=0 view= why=CUDA_VISIBLE_DEVICES=1: '1' names none of the cards nvidia-smi lists (GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb)
VIEW[GPU-00000000] rc=1 n=0 view= why=CUDA_VISIBLE_DEVICES=GPU-00000000: 'GPU-00000000' names none of the cards nvidia-smi lists (GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb)
VIEW[0,GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb] rc=1 n=0 view= why=CUDA_VISIBLE_DEVICES=0,GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb: 'GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb' names GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb, already in view
TIMING gpu=GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb why=none cvd=GPU-7d7913f3-b87d-8be6-42b5-d88981ead1eb
TIMING-BOX rc=0

The model-free one-card gate end to end through box.sh's local mode, the build and gpu-gate.sh's local lock:

$ BLOOMERY_BOX_LOCAL=1 just gate-gpu-kquant
gpu-gate.sh: gate_kquant on this machine's card(s), the local gate lock (asked any)
gpu-gate.sh: gate_kquant ran 2 s (exit 0)
GATE-KQUANT rc=0

The gate printed 164 PASS lines and no FAIL, ending in PASSED: gate_kquant q5k_gemv_sel within 1e-5 of the f64 dequant_row reference at 8 shapes.

The tool tests, on a Linux host without a card:

$ bash tools/ref/card-tests/run.sh
card-tests: 1009 tests, 0 failed
$ bash tools/gate-batch.sh --self-test
gate-batch self-test: 793 of 793 ok
$ bash tools/gpu-gate.sh --self-test --part 3
gpu-gate self-test: 47 of 47 ok
$ bash tools/ref/depth-qwen3moe-stub.sh
depth-qwen3moe-stub: 95 checks, 0 failed

The new cases include the local both runs on two cards in view, the env-file narrowing, an index under CUDA_DEVICE_ORDER=PCI_BUS_ID, an index that leaves a card out, an index beside a UUID, a card named twice, a newline in the value, --lanes 1 as the local default and --lanes 2 packing against MemAvailable less 1 GiB. With the production files at the base and the tests at this change, the same two commands fail:

$ bash tools/ref/card-tests/run.sh
FAIL box.sh: local mode runs BLOOMERY_CARD=both on two cards in view: rc 64, want 0
FAIL gpu-gate.sh: box.sh's local mode takes both on two cards in view to its one lock: rc 64, want 69
FAIL timing-card.sh local: the caller's CUDA_VISIBLE_DEVICES puts one card in view: no line matches ...
card-tests: 1002 tests, 11 failed
$ bash tools/gate-batch.sh --self-test --part 10
FAIL local mode: one lane by default (the one local gate lock): no line matches /dry run .*, lanes 1, /
gate-batch self-test: 33 of 35 ok

Hardware (if the change is for a machine)

Machine Card Driver CUDA
DGX Spark NVIDIA GB10 595.84 13.3

AI help

AI 코딩 에이전트가 코드를 작성한 후 설명을 썼고, 테스트를 마쳤습니다. diff 리뷰와 PR 초안 리뷰는 제가 직접 했습니다.

…e box's card names

Outside the box the card a command runs on was told three ways: tools/box.sh refused
BLOOMERY_CARD=both by name on every machine, tools/gpu-gate.sh refused BLOOMERY_GATE_CARD=both
the same way, and tools/ref/timing-card.sh listed every card nvidia-smi shows, ignoring the
CUDA_VISIBLE_DEVICES the command was given, so a machine with two cards and one in view was
refused as two. tools/ref/tier-cost.sh counted the physical cards on its own.

- tools/ref/cards.sh gains cards_view: the cards in view by UUID, from CUDA_VISIBLE_DEVICES
  (UUIDs, unique UUID prefixes or nvidia-smi indices) or every listed card when it is unset,
  with a named reason when they cannot be told: an entry naming no card, several or one
  already in view, and, without CUDA_DEVICE_ORDER=PCI_BUS_ID, an index unless the indices
  alone name every card, since CUDA counts fastest first by default and nvidia-smi lists by
  PCI bus. The box's two names stay in the file as the box's own.
- tools/box.sh's local mode runs BLOOMERY_CARD=both when two or more cards are in view, read
  after the environment file, and otherwise refuses with the cards in view (64). The one local
  gate lock holds every card of the machine, so it holds whatever is in view.
- tools/gpu-gate.sh's local mode takes BLOOMERY_GATE_CARD=both by the same rule.
- timing-card.sh's local mode times the one card in view, or the BLOOMERY_TIMING_GPU among
  them. tier-cost.sh's own count of physical cards goes: timing-card.sh leaves it one card in
  view or refuses with the reason.
- The stub trees' cards.sh carries the real cards_view, and the depth-serve local case starts
  from the caller's view.
- local-check.md, dgx-spark.md, BUILD.md and the serve-qwen38 comments describe the cards in
  view instead of the card names.
…'s own memory

The batch's two lanes are the box's two cards, each behind a gate lock of its own, and the
pack's budget is the box's lowest MemAvailable. Under BLOOMERY_BOX_LOCAL=1 every gate takes the
one local gate lock that holds the machine's cards, so a second lane's gates only queued on it,
and a two-lane pack summed its items against the box's 262 GB whatever the machine had.

- Local mode defaults to --lanes 1; --lanes 2 still runs two lanes.
- A two-lane local batch packs against this machine's MemAvailable less the same 1 GiB margin,
  read once as it starts; BLOOMERY_PACK_BUDGET still overrides it.
- tools/gate-batch-resources.tsv says what a row is: the plan's host bytes, the same on every card
  with the room for the gate plan, summed against the machine's budget.
- The self-test clears BLOOMERY_BOX_LOCAL for its cases and checks both local defaults.
@github-actions github-actions Bot added dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Nov 2, 2026

@github-actions github-actions 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.

Verdict: CLEAN: Local card selection and batching preserve named refusals and the local lock contract.

Checked

Duplicates: 1 new production function checked by Grep; no duplicate owner. Stub runners embed the production selector.
Complexity: no Rust function changed; no crapper targets.
Silent failure: 4 caller paths followed through box, gate, timing, and batch setup. Invalid views and unreadable memory produce named refusals.
Tests: all 9 changed shell scripts pass bash -n. The selector and batch assertions cover invalid views, environment overrides, two-card refusals, lane defaults, and the local memory budget.
Mutation review: ignoring the view, accepting duplicates, dropping trailing-empty or device-order checks, and shifting index lookup make the selector assertions red (tools/ref/cards.sh:52). Moving selection before environment overrides breaks the box assertions (tools/box.sh:1411). Dropping the two-card guard breaks the gate refusal assertion (tools/gpu-gate.sh:2247). Keeping two default lanes or the workstation budget breaks the batch assertions (tools/gate-batch.sh:4406, tools/gate-batch.sh:4418).
Gates: no numeric gate or lint moved. The PR supplies FAIL-first output for the replaced local-mode behavior.
Escape catalog: no C1–C4 pattern matched. New status captures preserve errors; heredoc substitutions are intentional.
Performance: tool and documentation changes only; no inference hot path changed.

Notes

Dryer and crapper did not run because no Rust file changed. Runtime cases, full tool suites, and hardware gates were not rerun during validation.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@juliankang4

Copy link
Copy Markdown
Collaborator Author

The review is done and the contribution check passed, so I'm merging this.

@juliankang4
juliankang4 merged commit 1990e73 into midagedev:main Nov 2, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgx-spark The DGX Spark (aarch64, GB10) port documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant