Repository navigation
Stop the remote GGUF guard reserving an output buffer for the first slot - #8635
danielhanchen wants to merge 2 commits into
Conversation
|
Re-verified this independently before recommending it, since it partially reverses a merged PR. The load-bearing claim is that the local branch never charges an output buffer for the first slot. So one slot reserves activation scratch and no output buffer, and that is a fitted measurement rather than a guess. Charging one anyway bills The trade-off is genuine and worth stating in the open rather than burying. The remote branch has no header, so it cannot ask
Assuming chat is the better default: it is the overwhelmingly common case, the error is an order of magnitude smaller, and it removes a divergence where an uncached model cost 0.58 GiB more than the identical model once on disk. Since this guard 409s a load that will not fit beside a running training job, the over-charge was refusing loads for bytes that never become resident. Confirmed locally: This is currently the only thing keeping Backend CI red across the repo, reproduced on a clean |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 23251121c3
ℹ️ 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".
| # embedding GGUF does output its whole first micro-batch, but its real | ||
| # vocab sits far under the 262144 ceiling assumed here, so from two slots | ||
| # on the ceiling already covers the slot this drops. | ||
| _out_slots = n_parallel if tensor_parallel else max(0, n_parallel - 1) |
There was a problem hiding this comment.
Retain the first output buffer for remote embedding GGUFs
For an uncached remote embedding GGUF using non-tensor placement with n_parallel = 1, this sets _out_slots to zero even though the launched embedding server allocates an output buffer for every slot (_estimate_compute_buffer_bytes uses output_slots = par for embedding models). With an explicit large micro-batch such as 32768, even a 32K vocabulary leaves roughly 4.6 GiB unaccounted for, so the training guard can approve a load that exhausts VRAM and terminates the active training run. Preserve the first-slot reserve when the remote model is known or may be an embedding model.
Useful? React with 👍 / 👎.
| # embedding GGUF does output its whole first micro-batch, but its real | ||
| # vocab sits far under the 262144 ceiling assumed here, so from two slots | ||
| # on the ceiling already covers the slot this drops. | ||
| _out_slots = n_parallel if tensor_parallel else max(0, n_parallel - 1) |
There was a problem hiding this comment.
Account for single-slot activation scratch remotely
For a remote chat GGUF using non-tensor placement with n_parallel = 1, this also zeros the only flat-buffer allowance, although the local estimator always charges act_scratch = 4 * n_embd * ubatch * 4 even when chat needs no full output buffer. The remote path consequently retains only the KQ mask: at the default micro-batch it misses the measured single-slot scratch, while an explicit 32768-token micro-batch on an 8192-wide model leaves about 4.6 GiB unaccounted for. The removed ceiling-sized output term previously covered this allocation, so the guard can now admit a load that OOMs the active training run; add a separate conservative activation-scratch reserve before dropping the chat output slot.
Useful? React with 👍 / 👎.
|
CI status, since the red checks here are not this PR's. Measured on main's own Backend CI at This PR clears all 8 GGUF failures. The Backend job reports So the two are complementary and mutually blocking. Merging both should take Backend CI to zero. The |
|
Both items are genuine. The first is fixed in 1b85738.
The fix adds an Named test: The second item I am leaving open, because the remedy as stated cannot be written. There is no remote embedding signal: One correction to this PR's own description while I am here. It says 2+ slots are "covered by the 262144 vocab ceiling". That is false for embedding GGUFs above a 131072 vocab: Qwen3-Embedding-8B at 2 slots reserves 44.88 GiB at launch against 36.80 GiB charged, 8.08 GiB short, where pre-PR it was covered. After the fix, chat is never under-reserved at any slot count or micro-batch; embedding is still under-reserved at 1 and 2 slots. |
…them #8524 changed the remote output-buffer slot count from n_parallel - 1 to max(1, n_parallel), so every single-slot uncached estimate gained about 0.58 GB. #8641 then extracted the reserve and held it at zero in the drafter tests, which turned Backend CI green without settling whether the charge is right. It is not. The local branch, which reads the header and is fitted to measured allocations, charges act_scratch + output_buffer * (slots - 1) for a chat model: {1:36, 2:492, 4:1388, 8:3220} MiB, so one slot reserves the scratch and no output buffer. The remote branch stands in for that same computation on a model whose header is not readable yet, and the two are supposed to agree: an existing comment in the same function calls out the case where "the same model 409s while remote and loads once cached" as the thing to avoid. Charging the first slot made every uncached chat load read 0.58 GB heavier than the identical cached one, on an estimator whose only consumer refuses the load when it does not fit. So the slot count goes back to matching the local branch, and the activation scratch it was standing in for is charged explicitly, at a ceiling the way the vocab already is. Without that a one-slot remote load would carry the KQ mask alone, which is the same divergence pointing the other way. Measured against _estimate_compute_buffer_bytes for a 152k-vocab, 5120-wide chat model at the default micro-batch, remote now sits just above cached rather than half a gigabyte above it: 1 slot cached 0.0449 GiB remote 0.0726 GiB (+0.028) 2 slots cached 0.3782 GiB remote 0.6476 GiB (+0.269) Known residual: a remote EMBEDDING GGUF now reads low, by 0.31 GB at one slot for a 152k vocab, because that branch charges an output buffer at every slot and this one cannot tell an embedding repo from a chat repo before the header is readable. #8524's own comment records that there is no reliable pre-load probe for it. The under-charge is bounded by the model's real vocab and those repos are small, which is the same small-half trade the activation scratch used to be, against half a gigabyte of headroom taken from every chat load.
16a9f50 to
c4ef549
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c4ef549506
ℹ️ 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".
| # motivated charging it, but its real vocab sits far below the 262144 ceiling | ||
| # assumed here, so from two slots on the ceiling already covers the slot this | ||
| # drops. | ||
| _out_slots = n_parallel if tensor_parallel else max(0, n_parallel - 1) |
There was a problem hiding this comment.
Preserve the quantized-cache context scratch
When an uncached non-tensor chat GGUF uses a quantized KV cache, this drops the first-slot ceiling buffer even though the remote branch does not receive cache_type_kv and therefore budgets only the f16 KQ mask. Once cached, _compute_buffer_ctx_bytes additionally charges the context-linear dequantization scratch; for a regular-attention model with n_embd=5120, 32K context, and a 32768-token micro-batch, the new mask-plus-activation reserve is about 7.6 GiB while the cached compute estimate is about 25.4 GiB. The removed output reserve previously covered this case, so this change can let the coexistence guard approve a load that exhausts VRAM; pass the planned cache type into the remote estimator and conservatively reserve its context scratch before zeroing this slot.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed, and this one decides the PR. Measured on this branch for a 5120-wide model at a 32768 context and micro-batch:
cached context buffer f16 3.00 GiB q8_0 22.50 GiB
remote reserve, 1 slot 7.60 GiB
one ceiling output buffer at that ubatch 36.80 GiB
The remote branch never receives cache_type_kv, so it budgets the f16 mask and nothing else, while the cached path charges 22.5 GiB of dequant scratch for the same launch. The first-slot ceiling buffer was covering that, and dropping it takes the estimate far below what the model costs once cached, which is the direction that OOMs the training run rather than the direction that 409s a load.
Same for the other two you raised: _estimate_gguf_kv_gb charges (devices - 1) * _PIPELINE_PER_DEVICE_OVERHEAD_MIB and the architecture-specific context term through _compute_buffer_ctx_bytes, and the remote branch charges neither. All three are terms it cannot compute without the header, so the ceiling output buffer is the only slack standing in for them.
You are also right about the arithmetic in the ceiling comment, and it was wrong in the direction that mattered: out_buffer = vocab * ubatch * 4 against scratch = 16 * n_embd * ubatch puts equality at n_embd = vocab / 4 = 65536, not /16. A 16384-wide ceiling would have been a quarter of one output buffer, so the stated reason for not covering that class does not hold.
So the premise of this PR is wrong. The first-slot charge is not a principled output buffer, but it is load-bearing slack, and removing it is only safe once the terms it stands in for are charged, which the remote path cannot do while the header is unreadable. Closing rather than patching around it; the 0.58 GB over-charge at the default micro-batch is real but small next to a 20 GB shortfall at large ones.
| * (2 * devices if tensor_parallel else 1) | ||
| * LlamaCppBackend._COMPUTE_BUFFER_SAFETY | ||
| ) | ||
| return (mask_bytes + out_buffer_bytes + act_scratch_bytes) / (1024**3) |
There was a problem hiding this comment.
Add the layer-split device overhead explicitly
For an uncached one-slot chat GGUF explicitly split across multiple GPUs, this return omits the fixed per-extra-device allocation that the cached path adds as (devices - 1) * _PIPELINE_PER_DEVICE_OVERHEAD_MIB (currently 1 GiB per device). With two pinned GPUs and a 1024-token micro-batch, the removed first-slot ceiling contributed about 1.15 GiB and covered that allocation, whereas the replacement activation term contributes only the ordinary flat scratch, leaving the remote estimate roughly 1 GiB below the process that launches. Add the same per-extra-device overhead used by _estimate_gguf_kv_gb, or the guard can approve a layer-split load that OOMs beside training.
Useful? React with 👍 / 👎.
|
This is currently the fix for a red
All 8 are Bisected to
The line is in the remote branch of - _out_slots = n_parallel if tensor_parallel else max(0, n_parallel - 1)
+ # The remote header is unknown, so reserve as if it enables embeddings.
+ _out_slots = max(1, n_parallel)The intent is defensible, since a remote GGUF's pooling type is genuinely unknown before download. The cost is that every remote GGUF, chat models included, is now charged one output buffer it will not use, so admission refuses loads that do fit. #8524 updated This branch at Worth noting it fixes the source rather than re-baselining the 8 assertions. That distinction matters: those tests exist to check drafter classification, and the extra buffer was incidental to them, so re-baselining would have quietly locked in the over-reservation instead of removing it. No failing checks here, and the branch is level with |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ca1ab192a3
ℹ️ 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".
| # The 405B class reaches 16384 and is deliberately not covered: 16384 is exactly | ||
| # _ASSUMED_MAX_VOCAB / 16, so a ceiling there would make this term one whole ceiling | ||
| # output buffer and charge the dropped first slot straight back under another name. | ||
| _ASSUMED_MAX_EMBD = 8192 |
There was a problem hiding this comment.
Raise the activation ceiling above 8192
For an uncached one-slot remote GGUF whose n_embd exceeds 8192—the adjacent comment itself identifies the supported 16384-wide class—this new ceiling still underprices the activation scratch. With n_ubatch=32768, a 16384-wide model reserves about 9.2 GiB for this term, while the guard charges only 4.6 GiB; the removed first-slot output reserve previously covered that gap, so the guard can now approve a load that OOMs an active training run. The stated equivalence is also off: because the output formula is 4 * vocab * ubatch and the scratch formula is 16 * n_embd * ubatch, a whole ceiling output buffer corresponds to n_embd = _ASSUMED_MAX_VOCAB / 4, not / 16, so covering 16384-wide models would not undo the intended reduction.
Useful? React with 👍 / 👎.
| * (2 * devices if tensor_parallel else 1) | ||
| * LlamaCppBackend._COMPUTE_BUFFER_SAFETY | ||
| ) | ||
| return (mask_bytes + out_buffer_bytes + act_scratch_bytes) / (1024**3) |
There was a problem hiding this comment.
Preserve Inkling's context-linear reserve
For an uncached one-slot Inkling GGUF using the default f16 cache, this replacement no longer covers the architecture-specific context buffer that the cached path charges in _compute_buffer_ctx_bytes. At a 32768-token context and micro-batch, Inkling's 8192 * n_ctx * (ubatch / 512) term alone is 16 GiB, whereas this remote path now reserves only the 3 GiB mask plus 4.6 GiB activation ceiling; the removed first-slot output term contributed 36.8 GiB and previously covered the allocation. The resulting deficit can let the coexistence guard approve a remote Inkling load that exhausts VRAM, so retain a conservative architecture-specific context allowance while the header is unreadable.
Useful? React with 👍 / 👎.
|
Correction to my comment above: by the time I posted it, What still holds, and why this PR is not redundant: #8641 fixed the 8 failing tests by extracting _out_slots = max(1, n_parallel)at This branch already contains #8641 (and #8608, #8638), keeps the new helper, and changes only the charge: _out_slots = n_parallel if tensor_parallel else max(0, n_parallel - 1)
|
|
Settling the charge with the measured data, since #8524 and this PR assert opposite things about it and #8641 landed on a third position. The three claims:
Model A is this PR's, with So #8524's slot count was wrong and this change is right. The fit also shows the two halves of this PR are inseparable. Without charging activation scratch unconditionally, model A predicts 0 MiB at one slot against a measured 36. Dropping the first output buffer without adding the scratch back is not a smaller version of this fix, it is a different and wrong model. That is what the follow-up commit here corrects. On #8641, to be fair to it: its stated premise does not survive this fit, but its action was the right one and I would not undo it. Rather than baking either value into the assertions it extracted the reserve into One thing this does not settle: embedding GGUFs still charge every slot, and above a 131072 vocab that is under-reserved at 1 and 2 slots, quantified in my earlier comment. It needs a remote pooling-type signal that does not exist yet, so it stays out of this PR. |
|
Closing. The review above overturned the premise, and I checked each point against the code rather than taking it on faith. The argument for this change was that the remote estimate should match the cached one, and that charging an output buffer for the first slot made every uncached chat load read 0.58 GB heavier than the same model once cached. That part is true. What I had not checked is what else the remote branch fails to charge, where the same first-slot buffer was quietly covering the difference in the opposite direction. Measured on this branch, 5120-wide model, 32768 context and micro-batch: The remote branch is never passed That makes the first-slot charge unprincipled as an output buffer but load-bearing as slack, and the asymmetry decides it: over-reserving costs a 409 the user can see and retry, under-reserving costs a training run. The 0.58 GB over-charge at the default micro-batch is real, and small next to a 20 GB shortfall at large ones. The comment justifying the 8192 activation ceiling was also wrong, as the review points out: with What is worth keeping from this, for whoever picks it up: the remote estimator is missing the quantized-cache scratch, the per-device layer-split overhead and the architecture-specific context term, and it compensates with a slot count that does not mean what its name says. Charging those explicitly, from the ceilings the branch already uses, would let the slot count go back to matching the local branch. That is the real fix and it is bigger than this PR. |
Rebased onto current
main, which now carries #8641's extraction of the reserve into_remote_gguf_compute_reserve_gb. This PR keeps that extraction and changes only what it charges.Which PR introduced what
ImportError: cannot import name 'openai_codex_auth_router'main.pywithout the test stubValueError: Responses event type is missing(2 tests)response_event_typeand wired onlyopenai_codex_clientto pass the SSE event nameTestEstimateGgufRequiredGboff by 0.575732421875 GB (8 tests)Why the charge is the part still open
#8524 made two changes to the remote branch. The default micro-batch is right and stays: a request that emits no batch flags still launches at llama.cpp's 512, and the local branch already charges against that default.
The slot count is the other one.
max(1, n_parallel)reserves an output buffer for the first slot, and the local branch, which reads the header and is fitted to measured allocations, does not:One slot reserves the activation scratch and no output buffer. The remote branch stands in for that same computation on a model whose header cannot be read yet, and the two are meant to agree; a comment already in this function names the failure mode, "the same model 409s while remote and loads once cached". Charging the first slot made every uncached chat load read 0.58 GB heavier than the identical cached one, on an estimator whose only consumer answers 409.
So the slot count returns to the local branch's form, and the activation scratch it was standing in for is charged explicitly under a ceiling, the way the vocab already is. Without that a one-slot remote load would carry the KQ mask alone, which is the same remote-vs-cached divergence pointing the other way.
Measured
Against
_estimate_compute_buffer_bytesfor a 152k-vocab, 5120-wide chat model at the default micro-batch:Remote now sits just above cached instead of half a gigabyte above it.
test_the_remote_reserve_tracks_what_the_cached_path_chargespins both directions: never under the cached figure, and at one slot not a whole ceiling output buffer over it.Suites that touch the estimator or the buffers it models: 818 passed (
test_batch_sizes_per_load,test_chat_load_during_training,test_mtp_drafter_companion,test_compute_buffer,test_embedding_gguf_launch,test_kv_cache_estimation,test_diffusion_memory).The residual, stated plainly
A remote embedding GGUF now reads low, by 0.31 GB at one slot for a 152k vocab, because the cached branch charges an output buffer at every slot and this one cannot tell an embedding repo from a chat repo before the header is readable. #8524's own comment records that there is no reliable pre-load probe for it. The under-charge is bounded by the model's real vocab and those repos are small; the alternative is half a gigabyte of headroom taken from every uncached chat load. That trade is the reviewable decision here, and it reverses part of a merged PR, so it deserves a second opinion rather than my word for it.
Not measured
No llama-server was launched. The single-slot 36 MiB figure is the one already recorded in the estimator, not a fresh reading, and the embedding residual is derived from the vocab ceiling rather than observed.