Skip to content

feat: pass the charged VRAM and card total to the gpu job container (#185) - #191

Merged
ycpss91255 merged 10 commits into
mainfrom
fix/185-vram-env
Nov 29, 2026
Merged

ycpss91255 merged 10 commits into
mainfrom
fix/185-vram-env

Conversation

@ycpss91255

Copy link
Copy Markdown
Member

Summary

Pass the charged VRAM to the gpu job container so a job can self-limit (nothing enforces VRAM on these cards):

  • RUNNER_VRAM_GB=<charged GiB> and RUNNER_VRAM_TOTAL_GB=<card GiB> are put on the engine argv of the job container (not in the env-file).
  • An unpinned fail-safe job gets RUNNER_VRAM_GB=unknown and no card total.
  • With an unset or empty budget no RUNNER_VRAM_ flag is added.
  • The listener fills the card total from the admitted card and exports it through the provisioner.
  • deploy/README.md documents how a workflow reads the values, and that steps run as separate containers through the host Docker socket get them only if the job passes them on.

Closes #185

Behaviour commits

  • b1: b069e88 - runner_container_run passes the charged VRAM (test + fix together, no separate red commit)
  • b2: 63c652b - provisioner exports the pinned card total VRAM to the job
  • b3: 3b7c571 - the listener carries the admitted card total in the provision request
  • No refactor commit.

Red evidence

Behaviour 1 (b069e88): engine env for RUNNER_VRAM_GB and RUNNER_VRAM_TOTAL_GB

Test: runner_container_run passes RUNNER_VRAM_GB and RUNNER_VRAM_TOTAL_GB as engine env (#185) in test/bats/integration/runner_container.bats.

Command: just test-integration (whole integration dir; the justfile has no per-file filter).

Before the fix:

not ok 208 runner_container_run passes RUNNER_VRAM_GB and RUNNER_VRAM_TOTAL_GB as engine env (#185)
(in test file test/bats/integration/runner_container.bats, line 494) `grep -A1 -xF -- '--env' "${CAP}" | grep -qxF -- 'RUNNER_VRAM_GB=8'' failed
error: recipe `test-integration` failed on line 84 with exit code 1

It is the only "not ok" in the run.

After the fix: just check exit 0, 0 "not ok":

ok 208 runner_container_run passes RUNNER_VRAM_GB and RUNNER_VRAM_TOTAL_GB as engine env (#185)
ok 271 update.sh continues past a failing runner and reports a summary (#49)

Behaviour 2 (63c652b): provisioner exports the pinned card total

Test: listener/provisioner_test.go. Design cycles 2 and 3 (unknown with no total; unset or empty gives no flag) were already green at that point, see the TDD trail.

Command: just coverage-go

Before the fix (compile failure):

./provisioner_test.go:361:65: unknown field VRAMTotalMiB in struct literal of type ProvisionRequest
./provisioner_test.go:362:52: unknown field VRAMTotalMiB in struct literal of type ProvisionRequest
FAIL github.com/ycpss91255-lab/github_runner/listener [build failed]

After the fix:

ok  github.com/ycpss91255-lab/github_runner/listener 1.567s coverage: 95.2% of statements
ok: go coverage (listener core) 95.2% (floor 85.0%)

just check exit 0.

Behaviour 3 (3b7c571): the listener fills the request total from the admitted card

Test: TestPinnedJobRequestCarriesAdmittedCardTotal in listener/reactive_test.go (busy 32607 MiB card at GPU 0, idle 16380 MiB card at GPU 1; a vram-gb-4 job lands on GPU 1).

Command: just coverage-go (whole Go suite, no single-test filter). Only this test failed.

Before the fix:

--- FAIL: TestPinnedJobRequestCarriesAdmittedCardTotal (0.00s)
reactive_test.go:436: VRAMTotalMiB = 0, want 16380 (the admitted card, not 32607)
FAIL github.com/ycpss91255-lab/github_runner/listener 1.583s

After the fix:

ok  github.com/ycpss91255-lab/github_runner/listener 1.573s coverage: 94.9% of statements
ok: go coverage (listener core) 94.9% (floor 85.0%)

just check was not run for this commit because only Go files changed. The CHANGELOG already had the #185 entry.

Review-fix commits

  • 9de9750 (round 1, finding 1): the total is delivered only with a known numeric budget. Tests in runner_container.bats: the passes-env test now also asserts both pairs precede the image and the env-file capture is non-empty; new gives an unknown budget and no card total (#185) and adds no RUNNER_VRAM_ flag when the budget is unset or empty (#185). Red (just test-integration): not ok 212 ... gives an unknown budget and no card total (! grep -qxF -- 'RUNNER_VRAM_TOTAL_GB=32' "${CAP}" || return 1 failed) and not ok 213 ... adds no RUNNER_VRAM_ flag when the budget is unset or empty (no_vram_env_on_argv || return 1 failed, a total with no budget was still emitted). Green: the same run passed after the fix, just check exit 0.
  • 32eca91 (round 1, finding 2): take the card total from the admitted GPU instead of a later snapshot lookup. New test TestAdmitGPUReturnsAdmittedCardTotal in listener/reactive_test.go; TestPinnedJobRequestCarriesAdmittedCardTotal still passes.
  • b49392d: final gates on that tree: just check exit 0, just coverage-go exit 0 (95.2%), just coverage-gate exit 0 (bash 88.0%, floor 85%).
  • d03cdf5, 9ab56f9: documentation and test tightening (provision-job.sh docs, engine argv end to end test, argv capture reset before each no-VRAM invocation).
  • b1bccc4 (round 2, finding 2): strengthened runner_container_run adds no RUNNER_VRAM_ flag when the budget is unset or empty (#185). Mutation in lib/runner-container.sh (return 0 before launching the engine when RUNNER_VRAM_GB is empty and RUNNER_VRAM_TOTAL_GB is set), run with just test-integration. Before the fix: not ok 215 runner_container_run adds no RUNNER_VRAM_ flag when the budget is unset or empty (#185) / (in test file test/bats/integration/runner_container.bats, line 547) [ -s "${CAP}" ]' failed. The old test was not run against the mutation; it would have passed it by reasoning only (append-only capture file). The mutation was reverted before committing. After: just checkrc=0, last lineok 278 .... Finding 1 of round 2 was comments only (no test): just check` rc=0.

Review

Review rounds 1 and 2 ran; all findings listed above were addressed in the review-fix commits. No open findings.

TDD trail

  • Design cycles 2 and 3 (unknown with no total; unset or empty gives no flag) were already green when added, because b069e88 gates each --env on non-empty values. They are covered by regression tests in review-fix commits and were never red.
  • Behaviour 2 (63c652b) has a compile-failure red, not an assertion failure. The new test needs the VRAMTotalMiB field, which the same commit adds to ProvisionRequest.
  • Review-fix commits after the behaviour commits (9de9750, 32eca91, d03cdf5, 9ab56f9, b1bccc4) are labelled fix(...) and add or adjust tests together with changes. 9de9750 tightens the behaviour of b069e88 by delivering the total only with a numeric budget.
  • b1bccc4 and the others also touch test docs and tests across several behaviours. 63c652b also edits listener.go, and the CHANGELOG entry is introduced in b069e88 and amended in 63c652b.
  • The history contains a merge commit (1dbb821, Merge origin/main) and cannot be rebased.
  • 3b7c571 does not touch the CHANGELOG, because the existing Pass the charged VRAM to the gpu job container (RUNNER_VRAM_GB) #185 entry already covers it.

Local verification

Run in Docker through the justfile on the final tree (no GPU container):

  • just check: exit 0, 0 "not ok", last line ok 278 update.sh continues past a failing runner and reports a summary (#49).
  • just coverage-go: exit 0, listener core 95.2% (floor 85.0%).
  • just coverage-gate: exit 0, bash line coverage 88.0% (floor 85.0%).
  • The bats specs touched by this diff (runner_container.bats, listener_provision.bats) are inside the just check integration run.

All issue acceptance items (job container env, unknown for an unpinned job, deploy/README.md documentation) are covered by the tests above. Nothing is left for a real-host deploy except rolling out the new listener, which is done separately by the owner.

@ycpss91255
ycpss91255 added this pull request to the merge queue Nov 29, 2026
Merged via the queue into main with commit ff83576 Nov 29, 2026
9 checks passed
@ycpss91255
ycpss91255 deleted the fix/185-vram-env branch November 29, 2026 12:15
@ycpss91255

Copy link
Copy Markdown
Member Author

中文說明

這個 PR 完成 #185:把分到的 VRAM 和整張卡的容量傳進 gpu job 的 container。

job 拿到的環境變數

  • RUNNER_VRAM_GB:這個 job 分到的 VRAM,單位 GiB。
    • 只有在 fail-safe 情況下,job 沒有被固定到某一張卡時,這個值才是 unknown。
  • RUNNER_VRAM_TOTAL_GB:job 被分到的那張卡的總容量,只有固定到某張卡時才會給。
  • 卡的編號照舊用 NVIDIA_VISIBLE_DEVICES 傳。
  • 沒有值的變數不會加進 container,所以 cpu job 完全不受影響。

用途

  • 這兩張卡都沒辦法硬性限制 VRAM,所以讓 job 知道自己分到多少,由 job 自己控制用量。
  • 例如 PyTorch 可以用 torch.cuda.set_per_process_memory_fraction 限制用量,做法比照阿里雲 gpushare。
  • job 透過 host 的 Docker socket 另外開的 container,不會自動拿到這兩個變數,需要 job 自己傳進去。

流程

  • 這是第一個用新版 tdd-fix workflow 做的 issue:
    1. 設計先經過 codex 審查。
    2. 每個行為的測試和修正放在同一個 commit,共 3 個行為。
    3. 接著 review。
    4. 最後獨立驗證,每個行為都重新跑出一次 red。
  • 每個行為的 red 輸出列在上方的 Red evidence。

後續

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pass the charged VRAM to the gpu job container (RUNNER_VRAM_GB)

1 participant