Skip to content

[profiler] Validate chrome trace by event name, not fixed offset - #188264

Closed
aostrowski-hbn wants to merge 3 commits into
pytorch:mainfrom
aostrowski-hbn:profiler-validate-basic-json-by-name
Closed

aostrowski-hbn wants to merge 3 commits into
pytorch:mainfrom
aostrowski-hbn:profiler-validate-basic-json-by-name

Conversation

@aostrowski-hbn

Copy link
Copy Markdown
Contributor

_validate_basic_json (used by test_basic_chrome_trace) located the "PyTorch Profiler (0)", "Iteration Start: PyTorch Profiler" and "Record Window End" markers at fixed negative indices -4/-2/-1 of the trace event list.

On a device build that emits a second profiler instance this no longer holds. A USE_XPU=1 build appends an __xpu_profiler__ (N) event plus its own Iteration Start: __xpu_profiler__ marker to the trace, so traceEvents[-4] is now the secondary profiler event and the assertion traceEvents[-4]["name"] == "PyTorch Profiler (0)" fails. The secondary instance is emitted regardless of the requested activities, and it is not bounded by the PyTorch profiler window, so it also trips the in-window bounds check ("Trace event ends too late!").

This change locates the three PyTorch profiler markers by name instead of by offset, and skips the secondary device profiler's events when validating the window. CPU and CUDA traces are unaffected (no secondary instance is emitted there), and the GPU-label / sort_index checks are preserved.

Surfaced by the Kineto XPU CI, which runs test/profiler/ from a USE_XPU=1 build (pytorch/kineto#1451 deselects this test until this fix reaches viable/strict).

Test plan

Verified on an Intel Data Center GPU Max (PVC) USE_XPU=1 build: test_basic_chrome_trace_cpu passes with this change and fails without it (AssertionError: False is not true on the traceEvents[-4] name check).

`_validate_basic_json` (used by `test_basic_chrome_trace`) assumed the
"PyTorch Profiler (0)", "Iteration Start: PyTorch Profiler" and
"Record Window End" markers sat at fixed negative indices -4/-2/-1 of the
trace event list.

On a device build that emits a second profiler instance, this no longer
holds. For example an XPU build (`USE_XPU=1`) appends an
`__xpu_profiler__ (N)` event plus its own `Iteration Start: __xpu_profiler__`
marker to the trace, so `traceEvents[-4]` is the secondary profiler event and
the assertion `traceEvents[-4]["name"] == "PyTorch Profiler (0)"` fails. The
secondary instance is emitted regardless of the requested activities, and it
is not bounded by the PyTorch profiler window, so it also trips the
in-window bounds checks ("Trace event ends too late!").

Locate the three PyTorch profiler markers by name instead of by offset, and
skip the secondary device profiler's events when validating the window. CPU
and CUDA traces are unaffected (no secondary instance), and the GPU-label /
sort_index checks are preserved.

Verified on an Intel PVC XPU build: `test_basic_chrome_trace_cpu` passes with
this change (it fails without it).
@pytorch-bot

pytorch-bot Bot commented Jun 26, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/188264

Note: Links to docs will display an error until the docs builds have been completed.

❌ You can merge normally! (2 Unrelated Failures), 1 Unclassified Failure

As of commit b000e7e with merge base c70ed7c (image):

UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:

  • xpu / linux-noble-xpu-n-py3.10 / test (default, 1, 12, linux.idc.xpu) (gh) (this job did not run on the merge base, so DrCI cannot tell whether the failure is pre-existing)
    User: arn:aws:sts::308535385114:assumed-role/gha_workflow_s3_and_ecr_read_only/gha-ecr-login is not authorized to perform: s3:PutObject on resource: "arn:aws:s3:::gha-artifacts/pytorch/pytorch/28524057129/1/artifact/logs-test-default-1-12-linux.idc.xpu_84562470218.zip" because no identity-based policy allows the s3:PutObject action

    AI verdict: AI verdict: not related

    The failure is an AWS IAM permissions error (s3:PutObject denied) in the artifact upload step, completely unrelated to any code change. The same error occurs on multiple prior trunk commits on this exact job.

    Full reasoning on HUD →

FLAKY - The following job failed but was likely due to flakiness present on trunk:

BROKEN TRUNK - The following job failed but was present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot

pytorch-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning: Unknown label ciflow/rocm.
Currently recognized labels are

  • ciflow/b200
  • ciflow/b200-distributed
  • ciflow/b200-symm-mem
  • ciflow/binaries
  • ciflow/binaries_libtorch
  • ciflow/binaries_wheel
  • ciflow/docker
  • ciflow/dtensor
  • ciflow/dynamo
  • ciflow/h100
  • ciflow/h100-cutlass-backend
  • ciflow/h100-distributed
  • ciflow/h100-symm-mem
  • ciflow/inductor
  • ciflow/inductor-cu126
  • ciflow/inductor-micro-benchmark
  • ciflow/inductor-micro-benchmark-cpu-x86
  • ciflow/inductor-pallas
  • ciflow/inductor-perf-compare
  • ciflow/inductor-perf-test-nightly-rocm-mi300
  • ciflow/inductor-perf-test-nightly-rocm-mi350
  • ciflow/inductor-perf-test-nightly-x86-zen
  • ciflow/inductor-perf-test-nightly-xpu
  • ciflow/inductor-periodic
  • ciflow/inductor-rocm-mi200
  • ciflow/inductor-rocm-mi300
  • ciflow/mps
  • ciflow/nightly
  • ciflow/op-benchmark
  • ciflow/periodic
  • ciflow/periodic-rocm-mi200
  • ciflow/periodic-rocm-mi300
  • ciflow/pull
  • ciflow/riscv64
  • ciflow/rocm-mi200
  • ciflow/rocm-mi300
  • ciflow/rocm-navi31
  • ciflow/rocm-nightly
  • ciflow/s390
  • ciflow/slow
  • ciflow/slow-rocm-mi200
  • ciflow/torchtitan
  • ciflow/triton_binaries
  • ciflow/trunk
  • ciflow/tsan
  • ciflow/unstable
  • ciflow/vllm
  • ciflow/win-arm64
  • ciflow/xpu

Please add the new label to .github/pytorch-probot.yml

for i in range(max_gpu_count):
self.assertEqual(gpu_dict["GPU " + str(i)], 1)

def _is_secondary_profiler_event(self, traceEvent):

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.

My personal preference is to match on the XPU strings directly to avoid any accidental matching and make this super easy to understand.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment thread test/profiler/test_profiler.py Outdated
traceEvents[RECORD_START]["name"] == "Iteration Start: PyTorch Profiler"
# Locate the PyTorch profiler markers by name rather than by fixed
# negative offsets: a device build appends a secondary profiler instance
# to the trace, which shifts the previously assumed -4/-2/-1 positions.

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.

let's leave these comments out as they reference behavior that isn't present in code

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

@jbschlosser jbschlosser added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Jun 26, 2026
- Match the secondary profiler markers on the exact XPU strings
  ("__xpu_profiler__" / "Iteration Start: __xpu_profiler__") instead of a
  broad "__...profiler__" pattern, to avoid accidental matches (review
  feedback). CUDA/CUPTI is unaffected: the standard trace has no secondary
  profiler span (__cupti_profiler__ only appears under CUDA_PROFILER_RANGE),
  and this test is skipped on XPU anyway.
- Drop the stale comment referencing the old fixed -4/-2/-1 offsets and the
  now-obvious _find_event comment.
- Re-wrap _is_secondary_profiler_event's return to satisfy ruff-format
  (PYFMT lint failure).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@pytorch-bot

pytorch-bot Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@ryanzhang22 ryanzhang22 added the ciflow/xpu Run XPU CI tasks label Jul 1, 2026
The previous review fix chained two startswith() calls with `or`, which
trips ruff PIE810 ("Call startswith once with a tuple"). Collapse into one
startswith() over a tuple of the XPU marker prefixes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@aostrowski-hbn

Copy link
Copy Markdown
Contributor Author

@ryanzhang22 Failures are unrelated. Please merge. The failed shards are not running the modified test case - it ran on shard 10.

@ryanzhang22

Copy link
Copy Markdown
Contributor

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 7, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 3 checks: pull / linux-jammy-aarch64-py3.10 / build-osdc, xpu / linux-noble-xpu-n-py3.10 / test (default, 1, 12, linux.idc.xpu), xpu / linux-noble-xpu-n-py3.10 / test (default, 6, 12, linux.idc.xpu)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

vishalgoyal316 pushed a commit to vishalgoyal316/pytorch that referenced this pull request Jul 16, 2026
…orch#188264)

`_validate_basic_json` (used by `test_basic_chrome_trace`) located the `"PyTorch Profiler (0)"`, `"Iteration Start: PyTorch Profiler"` and `"Record Window End"` markers at fixed negative indices `-4`/`-2`/`-1` of the trace event list.

On a device build that emits a **second** profiler instance this no longer holds. A `USE_XPU=1` build appends an `__xpu_profiler__ (N)` event plus its own `Iteration Start: __xpu_profiler__` marker to the trace, so `traceEvents[-4]` is now the secondary profiler event and the assertion `traceEvents[-4]["name"] == "PyTorch Profiler (0)"` fails. The secondary instance is emitted regardless of the requested activities, and it is not bounded by the PyTorch profiler window, so it also trips the in-window bounds check (`"Trace event ends too late!"`).

This change locates the three PyTorch profiler markers by name instead of by offset, and skips the secondary device profiler's events when validating the window. CPU and CUDA traces are unaffected (no secondary instance is emitted there), and the GPU-label / `sort_index` checks are preserved.

Surfaced by the Kineto XPU CI, which runs `test/profiler/` from a `USE_XPU=1` build (pytorch/kineto#1451 deselects this test until this fix reaches `viable/strict`).

## Test plan

Verified on an Intel Data Center GPU Max (PVC) `USE_XPU=1` build: `test_basic_chrome_trace_cpu` passes with this change and fails without it (`AssertionError: False is not true` on the `traceEvents[-4]` name check).

Pull Request resolved: pytorch#188264
Approved by: https://github.com/ryanzhang22

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
aostrowski-hbn added a commit to aostrowski-hbn/kineto_intel that referenced this pull request Jul 17, 2026
meta-codesync Bot pushed a commit to pytorch/kineto that referenced this pull request Jul 21, 2026
Summary:
Test fixed by pytorch/pytorch#188264

Pull Request resolved: #1484

Reviewed By: scotts

Differential Revision: D112540385

Pulled By: ryanzhang22

fbshipit-source-id: d65d0846877c1a554fb59806d5e85c379439b0e8
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…orch#188264)

`_validate_basic_json` (used by `test_basic_chrome_trace`) located the `"PyTorch Profiler (0)"`, `"Iteration Start: PyTorch Profiler"` and `"Record Window End"` markers at fixed negative indices `-4`/`-2`/`-1` of the trace event list.

On a device build that emits a **second** profiler instance this no longer holds. A `USE_XPU=1` build appends an `__xpu_profiler__ (N)` event plus its own `Iteration Start: __xpu_profiler__` marker to the trace, so `traceEvents[-4]` is now the secondary profiler event and the assertion `traceEvents[-4]["name"] == "PyTorch Profiler (0)"` fails. The secondary instance is emitted regardless of the requested activities, and it is not bounded by the PyTorch profiler window, so it also trips the in-window bounds check (`"Trace event ends too late!"`).

This change locates the three PyTorch profiler markers by name instead of by offset, and skips the secondary device profiler's events when validating the window. CPU and CUDA traces are unaffected (no secondary instance is emitted there), and the GPU-label / `sort_index` checks are preserved.

Surfaced by the Kineto XPU CI, which runs `test/profiler/` from a `USE_XPU=1` build (pytorch/kineto#1451 deselects this test until this fix reaches `viable/strict`).

## Test plan

Verified on an Intel Data Center GPU Max (PVC) `USE_XPU=1` build: `test_basic_chrome_trace_cpu` passes with this change and fails without it (`AssertionError: False is not true` on the `traceEvents[-4]` name check).

Pull Request resolved: pytorch#188264
Approved by: https://github.com/ryanzhang22

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…orch#188264)

`_validate_basic_json` (used by `test_basic_chrome_trace`) located the `"PyTorch Profiler (0)"`, `"Iteration Start: PyTorch Profiler"` and `"Record Window End"` markers at fixed negative indices `-4`/`-2`/`-1` of the trace event list.

On a device build that emits a **second** profiler instance this no longer holds. A `USE_XPU=1` build appends an `__xpu_profiler__ (N)` event plus its own `Iteration Start: __xpu_profiler__` marker to the trace, so `traceEvents[-4]` is now the secondary profiler event and the assertion `traceEvents[-4]["name"] == "PyTorch Profiler (0)"` fails. The secondary instance is emitted regardless of the requested activities, and it is not bounded by the PyTorch profiler window, so it also trips the in-window bounds check (`"Trace event ends too late!"`).

This change locates the three PyTorch profiler markers by name instead of by offset, and skips the secondary device profiler's events when validating the window. CPU and CUDA traces are unaffected (no secondary instance is emitted there), and the GPU-label / `sort_index` checks are preserved.

Surfaced by the Kineto XPU CI, which runs `test/profiler/` from a `USE_XPU=1` build (pytorch/kineto#1451 deselects this test until this fix reaches `viable/strict`).

## Test plan

Verified on an Intel Data Center GPU Max (PVC) `USE_XPU=1` build: `test_basic_chrome_trace_cpu` passes with this change and fails without it (`AssertionError: False is not true` on the `traceEvents[-4]` name check).

Pull Request resolved: pytorch#188264
Approved by: https://github.com/ryanzhang22

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…orch#188264)

`_validate_basic_json` (used by `test_basic_chrome_trace`) located the `"PyTorch Profiler (0)"`, `"Iteration Start: PyTorch Profiler"` and `"Record Window End"` markers at fixed negative indices `-4`/`-2`/`-1` of the trace event list.

On a device build that emits a **second** profiler instance this no longer holds. A `USE_XPU=1` build appends an `__xpu_profiler__ (N)` event plus its own `Iteration Start: __xpu_profiler__` marker to the trace, so `traceEvents[-4]` is now the secondary profiler event and the assertion `traceEvents[-4]["name"] == "PyTorch Profiler (0)"` fails. The secondary instance is emitted regardless of the requested activities, and it is not bounded by the PyTorch profiler window, so it also trips the in-window bounds check (`"Trace event ends too late!"`).

This change locates the three PyTorch profiler markers by name instead of by offset, and skips the secondary device profiler's events when validating the window. CPU and CUDA traces are unaffected (no secondary instance is emitted there), and the GPU-label / `sort_index` checks are preserved.

Surfaced by the Kineto XPU CI, which runs `test/profiler/` from a `USE_XPU=1` build (pytorch/kineto#1451 deselects this test until this fix reaches `viable/strict`).

## Test plan

Verified on an Intel Data Center GPU Max (PVC) `USE_XPU=1` build: `test_basic_chrome_trace_cpu` passes with this change and fails without it (`AssertionError: False is not true` on the `traceEvents[-4]` name check).

Pull Request resolved: pytorch#188264
Approved by: https://github.com/ryanzhang22

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rocm ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged open source topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants