Repository navigation
[profiler] Validate chrome trace by event name, not fixed offset - #188264
aostrowski-hbn wants to merge 3 commits into
Conversation
`_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).
🔗 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 FailureAs of commit b000e7e with merge base c70ed7c ( 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:
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. |
|
Warning: Unknown label
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): |
There was a problem hiding this comment.
My personal preference is to match on the XPU strings directly to avoid any accidental matching and make this super easy to understand.
| 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. |
There was a problem hiding this comment.
let's leave these comments out as they reference behavior that isn't present in code
- 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]>
|
|
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]>
|
@ryanzhang22 Failures are unrelated. Please merge. The failed shards are not running the modified test case - it ran on shard 10. |
|
@pytorchbot merge -i |
Merge startedYour 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 |
…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]>
Summary: Test fixed by pytorch/pytorch#188264 Pull Request resolved: #1484 Reviewed By: scotts Differential Revision: D112540385 Pulled By: ryanzhang22 fbshipit-source-id: d65d0846877c1a554fb59806d5e85c379439b0e8
…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]>
…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]>
…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]>
_validate_basic_json(used bytest_basic_chrome_trace) located the"PyTorch Profiler (0)","Iteration Start: PyTorch Profiler"and"Record Window End"markers at fixed negative indices-4/-2/-1of the trace event list.On a device build that emits a second profiler instance this no longer holds. A
USE_XPU=1build appends an__xpu_profiler__ (N)event plus its ownIteration Start: __xpu_profiler__marker to the trace, sotraceEvents[-4]is now the secondary profiler event and the assertiontraceEvents[-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_indexchecks are preserved.Surfaced by the Kineto XPU CI, which runs
test/profiler/from aUSE_XPU=1build (pytorch/kineto#1451 deselects this test until this fix reachesviable/strict).Test plan
Verified on an Intel Data Center GPU Max (PVC)
USE_XPU=1build:test_basic_chrome_trace_cpupasses with this change and fails without it (AssertionError: False is not trueon thetraceEvents[-4]name check).