Repository navigation
[cpu-offload] Enable NUMA by default - #3489
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
tianyu-l
left a comment
There was a problem hiding this comment.
Apologize for blocking, as
- I couldn't tell what this code does
- it touches core
Maybe you meant a draft?
Added PR desc, sorry about that. |
Pin each worker to the NUMA node of its GPU at Trainer init via torch.numa.binding. On multi-NUMA machines (e.g. GB200 NVLink-C2C) this ensures pinned-memory allocations land locally, yielding ~330 GB/s D2H bandwidth vs ~115 GB/s cross-NUMA (~3x improvement). Falls back gracefully on non-CUDA hardware or when numactl is unavailable. ghstack-source-id: 37af6c7 Pull-Request: #3489
|
how's this different to the other PR which I left comment #3519 (comment) |
Pin each worker to the NUMA node of its GPU at Trainer init via torch.numa.binding. On multi-NUMA machines (e.g. GB200 NVLink-C2C) this ensures pinned-memory allocations land locally, yielding ~330 GB/s D2H bandwidth vs ~115 GB/s cross-NUMA (~3x improvement). Falls back gracefully on non-CUDA hardware or when numactl is unavailable. ghstack-source-id: 37af6c7 Pull-Request: #3489
Sorry, closed the other one, claude messed up some ghstack metadata. This is the actual PR. Well there isn't downside to enabling this in the eager trainer as well, but I can do that. Wdyt? |
Pin each worker to the NUMA node of its GPU at Trainer init via torch.numa.binding. On multi-NUMA machines (e.g. GB200 NVLink-C2C) this ensures pinned-memory allocations land locally, yielding ~330 GB/s D2H bandwidth vs ~115 GB/s cross-NUMA (~3x improvement). Falls back gracefully on non-CUDA hardware or when numactl is unavailable. ghstack-source-id: 37af6c7 Pull-Request: #3489
[ghstack-poisoned]
Pin each worker to the NUMA node of its GPU at Trainer init via torch.numa.binding. On multi-NUMA machines (e.g. GB200 NVLink-C2C) this ensures pinned-memory allocations land locally, yielding ~330 GB/s D2H bandwidth vs ~115 GB/s cross-NUMA (~3x improvement). Falls back gracefully on non-CUDA hardware or when numactl is unavailable. ghstack-source-id: c89e05f Pull-Request: #3489
Yeah I would wait for the upside for core trainer to put it there. |
Updated, I put it in graph trainer. |
…tions Bind each training process to the NUMA node of its GPU right after set_device in TrainingEngine, before anything allocates pinned host memory, so first touch places that memory on the GPU-local node. Why core: core now has pinned-memory users whose bandwidth depends on NUMA placement -- FSDP2 CPU offload shards (CPUOffloadPolicy pins by default), EMA host copies, pinned batches, and the upcoming eager activation offloading. On GB300 (2 Grace CPUs, 2 GPUs each), a 1 GiB pinned copy from GPU0 measures: pinned memory on D2H H2D local node 193 GB/s 211 GB/s remote node 97 GB/s 100 GB/s Without binding, which node a rank's pinned memory lands on depends on where the scheduler ran the allocating thread, so a rank can silently get half the bandwidth. This also moves the existing calls into the engine. GraphTrainingEngine and the RL Trainer bound only after the model was built and sharded, i.e. after FSDP CPU offload had already pinned its shards. The vLLM generator keeps its own call (separate process, no TrainingEngine). This revives #3519, which was redirected to graph_trainer (#3489) until core had a use for it.
…tions Bind each training process to the NUMA node of its GPU right after set_device in TrainingEngine, before anything allocates pinned host memory, so first touch places that memory on the GPU-local node. Why core: core now has pinned-memory users whose bandwidth depends on NUMA placement -- FSDP2 CPU offload shards (CPUOffloadPolicy pins by default), EMA host copies, pinned batches, and the upcoming eager activation offloading. On GB300 (2 Grace CPUs, 2 GPUs each), a 1 GiB pinned copy from GPU0 measures: pinned memory on D2H H2D local node 193 GB/s 211 GB/s remote node 97 GB/s 100 GB/s Without binding, which node a rank's pinned memory lands on depends on where the scheduler ran the allocating thread, so a rank can silently get half the bandwidth. This also moves the existing calls into the engine. GraphTrainingEngine and the RL Trainer bound only after the model was built and sharded, i.e. after FSDP CPU offload had already pinned its shards. The vLLM generator keeps its own call (separate process, no TrainingEngine). The helper now logs the resulting affinity instead of claiming success unconditionally, and has a TODO for its private torch.numa dependency. AffinityMode.NODE intersects the node's CPUs with the current affinity, so it never widens a narrower launcher binding (torchrun --numa-binding=core-complex, SLURM --cpu-bind=cores); if the launcher bound to another node, torch.numa warns and leaves the affinity alone. Test plan: llama3 8B, FSDP over 4 GB300 GPUs, seq 8192, 2 x 8192 tokens per rank, 30 steps, runs interleaved on a shared host; tps over steps 6-30 (main = 98a8ce0): run mean tps median tps stdev median MFU main #1 22,022 22,055 721 51.09% this PR #1 22,182 22,146 745 51.30% this PR #2 22,179 22,167 750 51.35% main #2 22,024 21,949 735 50.85% Throughput is unchanged (+0.7%, within noise); the Grain loader's prefetch threads run in-process and are rebound with it. This revives #3519, which was redirected to graph_trainer (#3489) until core had a use for it.
<!--
Reviewers need to be convinced, not just informed. Delete sections you
don't need.
Agents: follow .claude/skills/pr-description/SKILL.md. Never fill in the
Summary.
-->
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
this approach, and what you checked yourself. -->
This revives #3519, which was redirected to graph_trainer (#3489) until
core had a use for it.
Bind each training process to the NUMA node of its GPU right after
set_device in TrainingEngine, before anything allocates pinned host
memory, so first touch places that memory on the GPU-local node.
Why core: On GB300 (2 Grace CPUs, 2 GPUs each), a 1 GiB pinned copy from
GPU0 measures:
pinned memory on D2H H2D
local node 193 GB/s 211 GB/s
remote node 97 GB/s 100 GB/s
Without binding, which node a rank's pinned memory lands on depends on
where the scheduler ran the allocating thread, so a rank can silently
get half the bandwidth.
We are working on activation offloading, and this will ensure that there
is appropriate core affinity.
This also moves the existing calls into the engine. GraphTrainingEngine
and the RL Trainer bound only after the model was built and sharded,
i.e. after FSDP CPU offload had already pinned its shards. The vLLM
generator keeps its own call (separate process, no TrainingEngine).
## Testing
<!-- What you ran, and the regression each new test catches. -->
CI
<!--
Reviewers need to be convinced, not just informed. Delete sections you
don't need.
Agents: follow .claude/skills/pr-description/SKILL.md. Never fill in the
Summary.
-->
## Summary (human-written)
<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
this approach, and what you checked yourself. -->
This revives pytorch#3519, which was redirected to graph_trainer (pytorch#3489) until
core had a use for it.
Bind each training process to the NUMA node of its GPU right after
set_device in TrainingEngine, before anything allocates pinned host
memory, so first touch places that memory on the GPU-local node.
Why core: On GB300 (2 Grace CPUs, 2 GPUs each), a 1 GiB pinned copy from
GPU0 measures:
pinned memory on D2H H2D
local node 193 GB/s 211 GB/s
remote node 97 GB/s 100 GB/s
Without binding, which node a rank's pinned memory lands on depends on
where the scheduler ran the allocating thread, so a rank can silently
get half the bandwidth.
We are working on activation offloading, and this will ensure that there
is appropriate core affinity.
This also moves the existing calls into the engine. GraphTrainingEngine
and the RL Trainer bound only after the model was built and sharded,
i.e. after FSDP CPU offload had already pinned its shards. The vLLM
generator keeps its own call (separate process, no TrainingEngine).
## Testing
<!-- What you ran, and the regression each new test catches. -->
CI
(cherry picked from commit dae9de6)
Two fixes for CPU activation offloading on GB200 (Blackwell)
hardware:
run_train.sh: Add --numa-binding node to torchrun — Pins each
worker process to the NUMA node containing its assigned GPU. On
GB200 NVLink-C2C, this guarantees ~350 GB/s D2H/H2D bandwidth for
CPU offload. Without it, the OS scheduler can migrate threads
cross-NUMA, degrading bandwidth to ~120 GB/s.
Stack from ghstack (oldest at bottom):