Skip to content

[core] Apply NUMA binding on CUDA hardware for local memory bandwidth - #3519

Closed
mlazos wants to merge 1 commit into
gh/mlazos/7/basefrom
gh/mlazos/7/head
Closed

mlazos wants to merge 1 commit into
gh/mlazos/7/basefrom
gh/mlazos/7/head

Conversation

@mlazos

@mlazos mlazos commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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-poisoned]
Comment thread torchtitan/trainer.py Resolved
@mlazos mlazos closed this Jun 4, 2026
anijain2305 added a commit that referenced this pull request Nov 9, 2026
…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.
anijain2305 added a commit that referenced this pull request Nov 9, 2026
…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.
anijain2305 added a commit that referenced this pull request Nov 10, 2026
<!--
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
rakkit pushed a commit to rakkit/torchtitan that referenced this pull request Nov 25, 2026
<!--
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants