Skip to content

fix(trainer-rank): credit reusable cache when placing gathered outputs - #1100

Draft
bradhilton wants to merge 4 commits into
mainfrom
dalinar/output-placement-cache-credit
Draft

bradhilton wants to merge 4 commits into
mainfrom
dalinar/output-placement-cache-credit

Conversation

@bradhilton

@bradhilton bradhilton commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Agent: Dalinar

Problem

Hayek's 060 run failed its first training call, before any optimizer update, with MemoryError: Gathered model-device outputs require 637760 GPU bytes; only 0 bytes are available. There was no CUDA OOM.

#925's output placement budgets explicit model-device copies (the default output_device="model") as physical free memory, minus the 3% reserve, minus pending backward reserves. On the native allocator, _available_memory_bytes gives no credit for PyTorch's reusable cache. So whenever the allocator holds most of the GPU as cached, freed blocks, which is typical right after a forward, the budget can read zero (the reserve is about 4.2 GiB on an H200) while the copy could be served from cache. A CPU repro on ad170 shows this: 47 GiB of reusable cache and 3 GiB physical free give a budget of 0.

This is a default-mode correctness gap whatever caused 060. 060 retained no allocated/reserved/staging operands at the refusing gate, and the nearest NVML sample (about 39 GiB free) was taken at a different time. So this PR does not claim the cache exclusion caused 060; pending-backward reserves remain a possible contributor.

Behavior

  • Explicit model-device outputs, which were refused outright, are now checked against a budget that also credits reusable cache, reserved - active, through _available_memory_bytes(reusable_cache=True). Frees pending on other streams stay active and are not credited.
  • Optional auto outputs keep the physical-only budget. Inactive cache doesn't guarantee an allocatable block (split large-pool blocks, the small pool, stream-private caches), so crediting it could send an auto output to GPU and OOM where CPU would have worked.
  • The credit applies only when the native allocated, active and reserved counters are all present exact integers and consistent (0 <= allocated <= active <= reserved); otherwise there is none.
  • Planning admission and every other caller keep the physical-only budget.
  • Explicit model placement still raises when the credited budget is short; there is no silent CPU fallback.
  • It composes with fix(trainer-rank): honor oversized model output placement #1099 (now on main), which lets the oversized opt-in skip the required-copy check. Without the opt-in, required copies are checked against the cache-credited budget and auto against the physical one. This fixes default-mode consumers too.

Validation

  • New budget tests: the cache credit, the 060 shape (physical free below the reserve, with cache present), the pending-free exclusion, and missing, non-integer or inconsistent counters granting no credit.
  • A placement test checks that an explicit copy uses the credited budget while auto keeps the physical one; it fails without the credit. Placement-path test budgets accept the new keyword. The 243 related tests pass.
  • Related suites pass. CPU repro of the 060 state on ad170: 47 GiB cache with 3 GiB physical free gave a 0 budget before this change.

Limits

  • 060's refusing gate retained no operands, so this is not a confirmed causal fix for 060. It closes the cache-exclusion path, which the CPU repro demonstrates.
  • For explicit copies the credit is optimistic. Under fragmentation, a copy that was previously refused can now fail as a real CUDA OOM instead; both outcomes failed before. Not exercised on GPU.
  • No GPU run.

🤖 Generated with Claude Code

Gathered-output placement budgeted explicit model-device copies against physical free memory alone. On the native allocator that excludes PyTorch's cache, so right after a forward, with freed activations cached, the budget fell to zero and refused even a 623 KiB logprob copy (Hayek's 060). Output placement now credits reserved minus active bytes when the allocator counters are consistent; frees pending on other streams stay excluded. Planning admission keeps its physical-only budget.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 13:36 — with GitHub Actions Error
…ache credit

Credit reusable cache only when the native allocated, active and reserved counters are all present, exact integers; a missing, boolean or fractional allocated counter no longer grants credit. Placement-path test budgets now accept the keyword (output memory, aggregate outputs, CUDA canary).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 13:48 — with GitHub Actions Error
Inactive cache does not guarantee an allocatable block for a given request (split large-pool blocks, small pool, stream-private caches), so crediting it to optional auto placement could pick GPU and then OOM where the physical budget would have chosen CPU. Only explicit model-device outputs, which would otherwise be refused, are checked against the cache-credited budget; auto placement keeps the physical one.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bradhilton
bradhilton had a problem deploying to trainer-rank-gpu-validation October 3, 2026 14:00 — with GitHub Actions Failure
…ent-cache-credit

# Conflicts:
#	src/art/trainer_rank/_commands.py
#	src/art/trainer_rank/_memory_policy.py
@bradhilton
bradhilton deployed to trainer-rank-gpu-validation October 3, 2026 14:49 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
trainer-rank-gpu-validation — 9c0b77c0 Deployed Oct 3, 2026 by bradhilton via Run on 2x H200 #1194
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.

1 participant