Skip to content

[cpu-offload] Enable NUMA by default - #3489

Merged
mlazos merged 11 commits into
mainfrom
gh/mlazos/5/head
Jun 5, 2026
Merged

mlazos merged 11 commits into
mainfrom
gh/mlazos/5/head

Conversation

@mlazos

@mlazos mlazos commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

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):

mlazos added 2 commits June 2, 2026 14:30
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jun 2, 2026
mlazos added a commit that referenced this pull request Jun 2, 2026
ghstack-source-id: d446da1
Pull-Request: #3489
mlazos added 2 commits June 2, 2026 14:52
[ghstack-poisoned]
[ghstack-poisoned]
@mlazos
mlazos requested a review from IvanKobzarev as a code owner June 2, 2026 21:52
mlazos added a commit that referenced this pull request Jun 2, 2026
ghstack-source-id: f4057ec
Pull-Request: #3489

@tianyu-l tianyu-l left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologize for blocking, as

  • I couldn't tell what this code does
  • it touches core

Maybe you meant a draft?

Comment thread run_train.sh Resolved
@mlazos

mlazos commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

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.

[ghstack-poisoned]
mlazos added a commit that referenced this pull request Jun 2, 2026
ghstack-source-id: 37af6c7
Pull-Request: #3489
@mlazos
mlazos requested a review from SherlockNoMad June 2, 2026 22:33
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Jun 4, 2026
ghstack-source-id: 1418a58
Pull-Request: #3489
mlazos added a commit that referenced this pull request Jun 4, 2026
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]
[ghstack-poisoned]
@mlazos
mlazos requested a review from tianyu-l June 4, 2026 04:28

@SherlockNoMad SherlockNoMad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@tianyu-l

tianyu-l commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

how's this different to the other PR which I left comment #3519 (comment)

mlazos added a commit that referenced this pull request Jun 4, 2026
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
@mlazos

mlazos commented Jun 4, 2026 •

Copy link
Copy Markdown
Contributor Author

how's this different to the other PR which I left comment #3519 (comment)

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?

mlazos added a commit that referenced this pull request Jun 4, 2026
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
mlazos added 2 commits June 4, 2026 10:55
[ghstack-poisoned]
[ghstack-poisoned]
mlazos added a commit that referenced this pull request Jun 4, 2026
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
@tianyu-l

tianyu-l commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Well there isn't downside to enabling this in the eager trainer as well, but I can do that. Wdyt?

Yeah I would wait for the upside for core trainer to put it there.

[ghstack-poisoned]
@mlazos

mlazos commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Well there isn't downside to enabling this in the eager trainer as well, but I can do that. Wdyt?

Yeah I would wait for the upside for core trainer to put it there.

Updated, I put it in graph trainer.

@mlazos
mlazos changed the base branch from gh/mlazos/5/base to main June 5, 2026 06:58
@mlazos
mlazos merged commit d3d123b into main Jun 5, 2026
10 of 11 checks passed
@mlazos
mlazos deleted the gh/mlazos/5/head branch June 5, 2026 07:01
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.

3 participants