Repository navigation
modeling: an OOM's shortfall is exact and the memory percentage counts reserved bytes - #397
Draft
JadenFiotto-Kaufman wants to merge 2 commits into
Draft
JadenFiotto-Kaufman wants to merge 2 commits into
JadenFiotto-Kaufman wants to merge 2 commits into
Conversation
alloc_shortfall_by_gpu was requested - (budget - max_memory_reserved). The peak reserved includes cache the allocator released before it refused, so over 24 OOMs on gpt2 under a 2 GiB cap it reported a median of 610 MiB against an exact 178 MiB. The requested size and the card came out of the message by regex, and a sandbox runner's OOM, which arrives as text, was compared against this actor's budget and reserved bytes. torch's out-of-memory observer passes the card, the requested bytes and the allowed bytes, once per OOM it raises, after its cache release and retry; reading memory_reserved in the callback gives the reserved bytes the refusal was measured against. The actor attaches it once after loading, gpu_baselines clears what it recorded, and alloc_shortfall reads it. An OOM raised in another process records nothing here, so it reports None. The regexes go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
max_mem_pct_by_gpu was (peak allocated - baseline) / headroom, but the per-process cap (set_per_process_memory_fraction) is enforced on reserved bytes. On gpt2 under a 2 GiB cap, requests shown at 70% had used 90% of what the cap allowed. The gpu_mem metric had no reserved figure either, so fragmentation could only be read out of OOM text. gpu_peaks now also reads max_memory_reserved, GPUMemMetric writes it as peak_reserved_bytes, and request_meta computes the percentage from it. meta keeps its keys and units: max_mem_by_gpu stays allocated bytes above the weights, and the reserved bytes only feed the percentage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
Two figures in the
metaof a terminal response are wrong.alloc_shortfall_by_gpuisrequested - (budget - torch.cuda.max_memory_reserved(device)). The peak reserved includes cache the allocator released before it refused. gpt2 in bf16 under a 2 GiB cap, running a seeded mix of 240 requests through the actor's request path, raised 24 OOMs: the reported median was 609.6 MiB against an exact 178.0 MiB, and every one was 432 to 581 MiB too high. The requested size and the card are parsed out of the message. A sandbox runner's OOM arrives as text, matchesis_oom, and is compared against this actor's budget and reserved bytes, which describe another process: in the same run it reported{"0": 0}.max_mem_pct_by_gpuis(peak allocated - baseline) / headroom, butset_per_process_memory_fractioncaps reserved bytes. The 19 successful requests above 1.4 GiB showed 69 to 78% while their reserved bytes filled 82 to 95% of the headroom the cap left them. Thegpu_memmetric has no reserved figure, so fragmentation does not show in telemetry.The change
One commit per finding; either can be dropped.
BaseModelDeployment.__init__attaches torch's out-of-memory observer once after loading (watch_refusals). torch calls it once per OOM it raises, after it has released its cache and retried, with the card, the requested bytes and the allowed bytes; the observer readsmemory_reservedthere.gpu_baselinesclears what it recorded, andalloc_shortfallreturnsrequested - (allowed - reserved)from it. An OOM raised in another process (the sandbox runner, a tensor-parallel shard) records nothing in the actor, so it reportsNone. The regexes are deleted.gpu_peaksalso returnsmax_memory_reserved,GPUMemMetricwrites it aspeak_reserved_bytes, andrequest_metacomputesmax_mem_pct_by_gpufrom it.metagets no new key:max_mem_by_gpustays allocated bytes above the weights, and the reserved bytes only feed the percentage, whose meaning (100 means the request filled what was left for it) is now true.docs/reference/schemas.mdanddocs/runbooks/model-oom-on-deploy.md, and the field list indocs/developing/telemetry-internals.md.Why the observer rather than the figures in the message: the message gives the right number too, but only by parsing four figures that torch rounds to two decimals in changing units (and "allowed" appears only when a fraction is set), and a runner's OOM text would still parse. The observer passes exact integers and fires only in this process, so the shortfall is three lines and the runner case needs no code. It is a private call,
torch._C._cuda_attach_out_of_memory_observer: present from torch 2.0 through main, tested by torch itself (test_notifies_oomintest/test_cuda.py), and since 2.1 torch releases the allocator lock before calling observers. If a torch release removes it, the actor fails to start, andtest_reads_torchs_figures_at_the_refusalfails first.Tests
tests/test_utils.py:test_reads_torchs_figures_at_the_refusal(skips without a GPU): attaches the observer, leaves a cached block, asks for 1 TiB, and checks the shortfall against torch's own allowed and reserved bytes.test_forgets_a_refusal_from_before_the_request: fails without the clear ingpu_baselines.test_an_oom_in_another_process_reports_no_shortfall: aRunnerErrorcarrying OOM text reportsNone;devreports a number.test_an_oom_adds_the_shortfallandtest_floors_at_zeronow feed the recorded figures. The tests of the message parsing are deleted.test_percent_is_against_the_headroom_the_request_had: 40% from reserved bytes, where allocated bytes give 20%.Measured with the review's request mix (gpt2 bf16, 2 GiB cap applied by
set_process_limits, 3 seeds of 80 requests) run throughgpu_baselines, the block on a thread of its own,gpu_peaks,request_metaand the actor's cleanup. "Exact" is a second observer in the script; the message's own figures (allocated plus reserved-but-unallocated) agree with it to within -0.4 to +7.6 MiB, the rounding.dev{"0": 0}NonedevpercentageFull suite (
python -m pytest tests): 426 passed, 95 skipped, 2 failed. The two failures aretests/test_sandbox_shared_memory.py::test_a_tensor_made_on_the_cpu_crosses_by_valueand::test_a_runner_killed_mid_request_leaves_the_host_as_it_was, the same two that fail in a full run of unmodifieddev; that file passes 12 of 12 run alone.tests/test_docs.pypasses.Not run against a live stack:
TestRemoteMetaand the OOM tests intests/test_nnsight_remote.pyskip without a server. A comment in that file said the observer fires on OOMs torch recovers from; it does not, and the comment now says why the test is there. nnsight's suite was not run; nnsight is unchanged.Left as it is
nnsight's
docs/remote/ndif-overview.md("What the job cost") has two sentences this makes false: themax_mem_pct_by_gpurow ("max_mem_by_gpuagainst the headroom the job had") and "It is approximate, andNonewhen the server could not tell which card refused."🤖 Generated with Claude Code