Skip to content

[profiler] add a minimal always-on kernel timeline - #5527

Draft
pianpwk wants to merge 6 commits into
gh/pianpwk/117/basefrom
gh/pianpwk/117/head
Draft

pianpwk wants to merge 6 commits into
gh/pianpwk/117/basefrom
gh/pianpwk/117/head

Conversation

@pianpwk

@pianpwk pianpwk commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:

  • Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
    ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
    slow run pulls down). The training-thread cost of each step's drain and
    bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
  • Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
    difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
    thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

[ghstack-poisoned]
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Oct 19, 2026
Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:
- Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
  ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
  slow run pulls down). The training-thread cost of each step's drain and
  bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
- Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
  difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
  thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

ghstack-source-id: ea130ed
Pull Request resolved: #5527
pianpwk added a commit that referenced this pull request Oct 19, 2026
Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:
- Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
  ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
  slow run pulls down). The training-thread cost of each step's drain and
  bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
- Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
  difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
  thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

ghstack-source-id: ea130ed
Pull Request resolved: #5527
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Oct 19, 2026
Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:
- Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
  ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
  slow run pulls down). The training-thread cost of each step's drain and
  bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
- Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
  difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
  thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

ghstack-source-id: 17fa6a0
Pull Request resolved: #5527
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Oct 19, 2026
Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:
- Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
  ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
  slow run pulls down). The training-thread cost of each step's drain and
  bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
- Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
  difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
  thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

ghstack-source-id: 2fa3955
Pull Request resolved: #5527
pianpwk added a commit that referenced this pull request Oct 20, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0)
(oldest at bottom):
* #5527
* #5526
* #5136
* __->__ #5525

Profiler.Config.cuspy switches CUDA activity collection from Kineto to
Cuspy
(PM sampling, environment counters, sync events, graph dependencies,
event-node
ids, and optional Perfetto protobuf output). Profiler startup raises a
ValueError if torch or libcupti lacks Cuspy support.

With CUDA graphs on, kernels replayed from graphs do not carry
annotations in
the Cuspy trace yet; the next PR in the stack captures graphs with a
CUPTI
annotation config to fix that.
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Oct 20, 2026
Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:
- Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
  ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
  slow run pulls down). The training-thread cost of each step's drain and
  bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
- Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
  difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
  thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

ghstack-source-id: 44a0616
Pull Request resolved: #5527
[ghstack-poisoned]
pianpwk added a commit that referenced this pull request Oct 20, 2026
Profiler.Config.always_on records every training step's GPU kernels with
Cuspy for the whole run, keeps the last num_steps steps in host memory, and
writes them as a Chrome trace every dump_freq steps to
profiling/always_on/iteration_N/rank{R}_trace.json.gz, so any recent step can
be looked at, not only a profiling window chosen up front.

torch's NodeTimerObserver records only each kernel's start, end, stream and
CUDA graph node -- no CPU events. At each step end the boundary is stamped in
CUPTI's record clock and the spans delivered so far are drained with a plain
(non-syncing) CUPTI flush and bucketed into their steps. Kernel names come from
each CUDA graph at instantiation, annotations from torch's CUDA graph
annotations, and lanes from torch's graph lane resolver where torch has one;
eager kernels are written unnamed. A dump skips the newest finished step,
whose kernels may still be running.

Kineto cannot initialize CUPTI while Cuspy holds it, so scheduled profiling
must use profiler.cuspy when always_on is set.

Overhead, steady-state steps 11-30, 5 interleaved runs each, no dumps:
- Llama3 8B FSDP2 x TP2 GraphTrainer on 4 GB300s (~3,900 kernels/step,
  ~0.58 s/step): median tps 14,119 -> 14,016 (-0.7%; -1.8% by mean, which one
  slow run pulls down). The training-thread cost of each step's drain and
  bucketing is ~1.5 ms (~0.3% of a step); the rest is CUPTI collection.
- Llama3 debugmodel on 1 GB300 (~600 kernels/step, ~7 ms/step): no
  difference above run-to-run noise (+-10%); ~0.46 ms per step on the training
  thread.

A dump runs on the training thread: writing 19 kept steps of the 8B run
(~74k kernels, 3.2 MB gzipped per rank) took 1.4 s.

Not included yet: dumps on demand or on failure, pftrace output, per-step
summaries, memcpy/memset spans, and names for eager kernels.

ghstack-source-id: 1569cab
Pull Request resolved: #5527
pianpwk added a commit that referenced this pull request Oct 20, 2026
)

Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.15.0)
(oldest at bottom):
* #5527
* #5526
* __->__ #5136

When Cuspy profiling is enabled, capture the forward-backward and
optimizer
CUDA graphs with an annotation config (backend="cupti") so kernels
replayed
from graphs keep their mark_kernels metadata in the Cuspy trace. The
CUDA graph
wrappers take an annotation_config that is passed through to
torch.cuda.graph;
it stays None, preserving current behavior, unless profiler.cuspy is
set.

key_by="auto" keys annotations to the capture graph, which Cuspy
resolves
through CUPTI's sourceGraphNodeId. Cuspy resolves graph event-record
nodes only
by exec-graph id, so enable_event_node_ids keys by the exec graph
instead.

This starts Cuspy's CUPTI subscription at the first capture and holds it
for
the rest of the run, so other CUPTI tools (Nsight Systems, dynolog)
can't
attach to that process.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

1 participant