Skip caching_allocator_warmup on Neuron (no reuse pool to warm; currently OOMs)#47029
Draft
dacorvo wants to merge 1 commit into
Draft
Skip caching_allocator_warmup on Neuron (no reuse pool to warm; currently OOMs)#47029dacorvo wants to merge 1 commit into
dacorvo wants to merge 1 commit into
Conversation
caching_allocator_warmup pre-allocates get_total_byte_count bytes per device in a single torch.empty(). The cuda/xpu branch clamps that with mem_get_info and mps is skipped (#46239); every other accelerator, including neuron (a PrivateUse1 backend), falls through to the unclamped allocation. On Neuron this OOMs the NeuronCore during from_pretrained, before any weight is placed, and provides no benefit: Neuron keeps no CUDA-style reuse pool for the warmup to fill (torch_neuronx.memory_stats() reports reserved_bytes == 0 even while memory is allocated, and pre-warming shows no measured speedup), and torch.neuron exposes no mem_get_info so the allocation cannot be bounded. Skip warmup on neuron, mirroring the mps skip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
CI recapDashboard: View test results in Grafana |
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Contributor
Author
|
Pushed without my consent by an overzealous agent, sorry about that. |
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.
What does this PR do?
caching_allocator_warmuppre-allocatesget_total_byte_countbytes per device in a singletorch.empty(...). Thecuda/xpubranch bounds that allocation against device capacity viamem_get_info;mpsis skipped (#46239). Every other accelerator device — includingneuron(AWS Trainium/Inferentia, a PrivateUse1 backend) — falls through to the unclamped allocation, which
OOMs the NeuronCore during
from_pretrained, before any weight is loaded:Concrete failures (TP load, bf16, Trainium2
trn2.48xlarge, ~24 GB per NeuronCore):openai/gpt-oss-120bQwen/Qwen3-VL-32B-InstructCohereLabs/North-Mini-Code-1.0openai/gpt-oss-20bHBM is ~0 GB at the point of failure — this is the warmup pre-allocation, before any weight is placed.
With the skip, loading proceeds normally: the spurious warmup allocation is gone and the model loads up to
its real per-device footprint. In a full support sweep, models that previously failed here in warmup now
proceed to actual load/compile — several pass (e.g.
Qwen/Qwen2.5-32B-Instructtp8), and any that stillrun out of memory do so on their genuine footprint, not on a bogus full-model pre-allocation.
Why skip on Neuron? (measured on Trainium2, Neuron SDK)
Two independent reasons, both verified empirically:
The warmup provides no benefit. Neuron keeps no CUDA-style reuse pool for a warm-up to fill:
torch_neuronx.memory_stats()reportsreserved_bytes = 0even while 2 GB is allocated; alloc/free are1:1 with the NRT runtime; and pre-warming a 4 GB pool then allocating 256×16 MB is the same speed as cold
(2.9 ms vs 3.0 ms, ~1.0×). The warmup's premise — amortize many slow device mallocs into one — does not
hold; Neuron allocation is a cheap direct runtime call.
The allocation can't be bounded, so it OOMs.
torch.neuronexposes nomem_get_info, so the cuda/xpuclamp (
min(byte_count, total_device_memory - 1.2 GiB)) can't run. Combined withget_total_byte_countover-estimating under
tp_plan="auto"(params the auto plan doesn't cover — MoE experts, vision towers —stay at full unsharded size), the unclamped
torch.emptyrequests ~the whole model on one core.Skipping therefore costs nothing and fixes the OOM — the same trade-off as the MPS skip (#46239).
Notes / alternatives
elif, mirroring MPS).mem_get_info(coversNeuron and future backends). Happy to take that shape if preferred.
get_total_byte_countover-estimating undertp_plan="auto"is a latent over-reservation on cuda/xpu too(masked there by the clamp); out of scope here.
Before submitting
sweep with the skip applied — the warmup allocations are gone, models load up to their real footprint,
and TP>1 models that previously passed still pass (no regression). transformers CI has no Neuron runner,
as with the MPS skip.
Who can review?
@Cyrilvallez @SunMarc (reviewed the related warmup PRs #36380 / #46145; cf. the MPS skip #46239)