Skip to content

[Test] Add TestProfilerDevice with instantiate_device_type_tests in test_profiler - #182434

Closed
RiyaP2508 wants to merge 8 commits into
gh/RiyaP2508/9/basefrom
gh/RiyaP2508/9/head
Closed

RiyaP2508 wants to merge 8 commits into
gh/RiyaP2508/9/basefrom
gh/RiyaP2508/9/head

Conversation

@RiyaP2508

@RiyaP2508 RiyaP2508 commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Summary
Create TestProfilerDevice class with 20 tests moved from TestProfiler, refactored to be device-agnostic using instantiate_device_type_tests.

Infrastructure added:

  • get_profiler_activities(device_type) helper that dynamically builds the ProfilerActivity list
  • @onlyAccelerator decorator for GPU-required tests
  • @OnlyOn(["cpu", "cuda"]) for tests with CUDA-specific assertions
  • instantiate_device_type_tests(TestProfilerDevice, globals())

Moved and refactored tests:

  • test_kineto — @OnlyOn(["cpu", "cuda"]), device-agnostic profiling with CUDA/ROCm kernel checks guarded
  • test_memory_profiler — conditional device memory checks
  • test_flops — device-agnostic activity list
  • test_kineto_profiler_api — multi-backend profiler API
  • test_kineto_profiler_multiple_steppers — step tracking across backends
  • test_tensorboard_trace_handler — device-agnostic trace export
  • test_kineto_profiler_with_environment_variable — @OnlyOn(["cpu", "cuda"]), subprocess self-detects device
  • test_event_list — @onlyAccelerator
  • test_basic_chrome_trace — device-aware Chrome trace validation
  • test_cpu_annotation_overlap — device-agnostic activity list
  • test_user_annotation — simple device param
  • test_basic_profile — @onlyAccelerator
  • test_dynamic_toggle — @onlyAccelerator
  • test_forked_process — skips on CUDA/XPU due to fork-after-init
  • test_profile_all_threads — @onlyAccelerator
  • test_profiler — device-agnostic with PrivateUse1 fallback
  • test_activity_filter_dict_syntax — @OnlyOn(["cpu", "cuda"]), @onlyAccelerator
  • test_activity_filter_nonmember_type_name — @onlyAccelerator
  • test_activity_filter_empty_list — @onlyAccelerator
  • test_kineto_kernel_metadata_in_trace — @OnlyOn(["cpu", "cuda"]), @onlyAccelerator

Note: test_kineto_profiler_with_environment_variable self-detects the available device in its subprocess script. test_forked_process skips on CUDA/XPU due to fork-after-init restrictions.

Test plan
Verified on CUDA: 111 passed, 11 skipped, 0 failures

cc: @albanD @fffrog @mansiag05

@pytorch-bot

pytorch-bot Bot commented May 5, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 2 New Failures

As of commit df17628 with merge base 019cea9 (image):

NEW FAILURES - The following jobs have failed:

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

…ice-agnostic profiler tests

Add imports for instantiate_device_type_tests and onlyAccelerator from
common_device_type. Add _get_device_target_cats() helper for
device-aware Kineto event category names.

Create TestProfilerDeviceType class with 3 tests moved from TestProfiler
(test_event_list, test_profile_all_threads, test_kineto_kernel_metadata_in_trace)
that are parameterized with @onlyAccelerator and a device argument.
Apply instantiate_device_type_tests for all accelerator devices.

Split TestProfilerEventsParity into CPU-only tests (3 tests stay) and
TestProfilerEventsParityDeviceType (5 tests with @onlyAccelerator):
test_profiler_flow_events_parity, test_profiler_timestamp_consistency,
test_profiler_external_id_parity, test_profiler_activity_type_parity,
test_structured_metadata_matches_chrome_trace.

Replace hardcoded device="cuda", ProfilerActivity.CUDA, and
torch.cuda.synchronize() with device-agnostic equivalents in all
8 parameterized tests.

[ghstack-poisoned]
@RiyaP2508 RiyaP2508 changed the title [test] Add @onlyAccelerator and instantiate_device_type_tests for device-agnostic profiler tests [Test] Add @onlyAccelerator and instantiate_device_type_tests in test_profiler May 5, 2026
@mansiag05 mansiag05 moved this from Backlog to Ready for Review in PyTorch Test Refactoring May 6, 2026
@fffrog fffrog moved this from Ready for Review(Definitive) to Ready for Review(Initial) in PyTorch Test Refactoring May 7, 2026
RiyaP2508 added a commit that referenced this pull request May 11, 2026
…est_profiler

Create TestProfilerDevice class with 20 tests moved from TestProfiler,
refactored to be device-agnostic using instantiate_device_type_tests.

Infrastructure: get_profiler_activities() helper, @onlyAccelerator
decorator for GPU-required tests.

Moved tests: test_kineto, test_memory_profiler, test_flops,
test_kineto_profiler_api, test_kineto_profiler_multiple_steppers,
test_tensorboard_trace_handler, test_kineto_profiler_with_environment_variable,
test_event_list, test_basic_chrome_trace, test_cpu_annotation_overlap,
test_user_annotation, test_basic_profile, test_dynamic_toggle,
test_forked_process, test_profile_all_threads, test_profiler,
test_activity_filter_dict_syntax, test_activity_filter_nonmember_type_name,
test_activity_filter_empty_list, test_kineto_kernel_metadata_in_trace.

Note: test_kineto_profiler_with_environment_variable self-detects the
available device in its subprocess script. test_forked_process skips on
CUDA/XPU due to fork-after-init restrictions.

ghstack-source-id: 6e12888
Pull Request resolved: #182434
…sts in test_profiler"


## Summary
Apply `onlyAccelerator` and `instantiate_device_type_tests` to profiler tests that should run on any accelerator (CUDA, XPU, HPU, etc.), not just CUDA.
**Changes:**
- Add `_get_device_target_cats(device_type)` helper for device-aware Kineto event category names
- Create `TestProfilerDeviceType` class with 3 tests moved from `TestProfiler`:
  - test_event_list
  - test_profile_all_threads
  - test_kineto_kernel_metadata_in_trace
- Split `TestProfilerEventsParity` into:
  - `TestProfilerEventsParity` (3 CPU-only tests stay)
  - `TestProfilerEventsParityDeviceType` (5 device-parameterized tests):
    - test_profiler_flow_events_parity
    - test_profiler_timestamp_consistency
    - test_profiler_external_id_parity
    - test_profiler_activity_type_parity
    - test_structured_metadata_matches_chrome_trace
- Replace hardcoded `device="cuda"`, `ProfilerActivity.CUDA`, `torch.cuda.synchronize()` with device-agnostic equivalents in all 8 parameterized tests
- Apply `instantiate_device_type_tests` to both new DeviceType classes
## Test plan
- [x] Verified on CUDA : 110 passed, 2 skipped, 0 failures

cc: albanD fffrog mansiag05 


[ghstack-poisoned]
@RiyaP2508 RiyaP2508 changed the title [Test] Add @onlyAccelerator and instantiate_device_type_tests in test_profiler [Test] Add TestProfilerDevice with instantiate_device_type_tests in test_profiler May 11, 2026
RiyaP2508 added a commit that referenced this pull request May 11, 2026
…est_profiler

Create TestProfilerDevice class with 20 tests moved from TestProfiler,
refactored to be device-agnostic using instantiate_device_type_tests.

Infrastructure: get_profiler_activities() helper, @onlyAccelerator
decorator for GPU-required tests.

Moved tests: test_kineto, test_memory_profiler, test_flops,
test_kineto_profiler_api, test_kineto_profiler_multiple_steppers,
test_tensorboard_trace_handler, test_kineto_profiler_with_environment_variable,
test_event_list, test_basic_chrome_trace, test_cpu_annotation_overlap,
test_user_annotation, test_basic_profile, test_dynamic_toggle,
test_forked_process, test_profile_all_threads, test_profiler,
test_activity_filter_dict_syntax, test_activity_filter_nonmember_type_name,
test_activity_filter_empty_list, test_kineto_kernel_metadata_in_trace.

Note: test_kineto_profiler_with_environment_variable self-detects the
available device in its subprocess script. test_forked_process skips on
CUDA/XPU due to fork-after-init restrictions.

ghstack-source-id: 6676c91
Pull Request resolved: #182434
…_tests in test_profiler"


## Summary

Create `TestProfilerDevice` class with 20 tests moved from `TestProfiler`, refactored to be device-agnostic using `instantiate_device_type_tests`.

**Infrastructure added:**
- `get_profiler_activities(device_type)` helper that dynamically builds the `ProfilerActivity` list
- `onlyAccelerator` decorator for GPU-required tests
- `instantiate_device_type_tests(TestProfilerDevice, globals())`

**Moved and refactored tests:**
- `test_kineto` — device-agnostic profiling with CUDA/ROCm kernel checks guarded
- `test_memory_profiler` — conditional device memory checks
- `test_flops` — device-agnostic activity list
- `test_kineto_profiler_api` — multi-backend profiler API
- `test_kineto_profiler_multiple_steppers` — step tracking across backends
- `test_tensorboard_trace_handler` — device-agnostic trace export
- `test_kineto_profiler_with_environment_variable` — subprocess self-detects device
- `test_event_list` — `onlyAccelerator`
- `test_basic_chrome_trace` — device-aware Chrome trace validation
- `test_cpu_annotation_overlap` — device-agnostic activity list
- `test_user_annotation` — simple device param
- `test_basic_profile` — `onlyAccelerator`
- `test_dynamic_toggle` — `onlyAccelerator`
- `test_forked_process` — skips on CUDA/XPU due to fork-after-init
- `test_profile_all_threads` — `onlyAccelerator`
- `test_profiler` — device-agnostic with PrivateUse1 fallback
- `test_activity_filter_dict_syntax` — `onlyAccelerator`
- `test_activity_filter_nonmember_type_name` — `onlyAccelerator`
- `test_activity_filter_empty_list` — `onlyAccelerator`
- `test_kineto_kernel_metadata_in_trace` — `onlyAccelerator`

**Note:** `test_kineto_profiler_with_environment_variable` self-detects the available device in its subprocess script. `test_forked_process` skips on CUDA/XPU due to fork-after-init restrictions.

## Test plan
- Verified on CUDA: 111 passed, 11 skipped, 0 failures

cc: albanD fffrog mansiag05 


[ghstack-poisoned]
Comment thread test/profiler/test_profiler.py Resolved
RiyaP2508 added a commit that referenced this pull request May 13, 2026
…est_profiler

Create TestProfilerDevice class with 20 tests moved from TestProfiler,
refactored to be device-agnostic using instantiate_device_type_tests.

Infrastructure added: get_profiler_activities(device_type) helper,
@onlyAccelerator decorator for GPU-required tests, @OnlyOn(["cpu", "cuda"])
for tests with CUDA-specific assertions (test_kineto,
test_kineto_profiler_with_environment_variable,
test_activity_filter_dict_syntax, test_kineto_kernel_metadata_in_trace).

ghstack-source-id: 49d131e
Pull Request resolved: #182434
…_tests in test_profiler"


## Summary

Create `TestProfilerDevice` class with 20 tests moved from `TestProfiler`, refactored to be device-agnostic using `instantiate_device_type_tests`.

**Infrastructure added:**
- `get_profiler_activities(device_type)` helper that dynamically builds the `ProfilerActivity` list
- `onlyAccelerator` decorator for GPU-required tests
- `instantiate_device_type_tests(TestProfilerDevice, globals())`

**Moved and refactored tests:**
- `test_kineto` — device-agnostic profiling with CUDA/ROCm kernel checks guarded
- `test_memory_profiler` — conditional device memory checks
- `test_flops` — device-agnostic activity list
- `test_kineto_profiler_api` — multi-backend profiler API
- `test_kineto_profiler_multiple_steppers` — step tracking across backends
- `test_tensorboard_trace_handler` — device-agnostic trace export
- `test_kineto_profiler_with_environment_variable` — subprocess self-detects device
- `test_event_list` — `onlyAccelerator`
- `test_basic_chrome_trace` — device-aware Chrome trace validation
- `test_cpu_annotation_overlap` — device-agnostic activity list
- `test_user_annotation` — simple device param
- `test_basic_profile` — `onlyAccelerator`
- `test_dynamic_toggle` — `onlyAccelerator`
- `test_forked_process` — skips on CUDA/XPU due to fork-after-init
- `test_profile_all_threads` — `onlyAccelerator`
- `test_profiler` — device-agnostic with PrivateUse1 fallback
- `test_activity_filter_dict_syntax` — `onlyAccelerator`
- `test_activity_filter_nonmember_type_name` — `onlyAccelerator`
- `test_activity_filter_empty_list` — `onlyAccelerator`
- `test_kineto_kernel_metadata_in_trace` — `onlyAccelerator`

**Note:** `test_kineto_profiler_with_environment_variable` self-detects the available device in its subprocess script. `test_forked_process` skips on CUDA/XPU due to fork-after-init restrictions.

## Test plan
- Verified on CUDA: 111 passed, 11 skipped, 0 failures

cc: albanD fffrog mansiag05 


[ghstack-poisoned]
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
Comment thread test/profiler/test_profiler.py Resolved
@claude

claude Bot commented May 31, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 1m 52s —— View job


CI Failure Analysis

  • Analyze the 3 CI failures reported
  • Determine if they are related to this PR's changes
  • Provide explanation

No, the 3 failures are not related to each other. Two share the same root cause (infrastructure), and one is a Windows-specific test issue that is related to this PR.

1. linux-docs / build-docs-cpp-false and linux-docs / build-docs-python-false

Root cause: aws: command not found (exit code 127)

These failed at the S3 upload step after the docs built successfully. The error is:

aws s3 sync cppdocs/ s3://doc-previews/pytorch/pytorch/182434/cppdocs --quiet
line 1: aws: command not found

The docs generation itself completed fine — this is a CI infrastructure issue where the aws CLI was not available in the container. Not related to this PR's changes at all.

2. trunk / win-vs2022-cpu-py3 / test (default, 2, 4)

Root cause: PermissionError on Windows temp files in test_tensorboard_trace_handler_cpu

The test fails at test_profiler.py:2559 with:

PermissionError: [Errno 13] Permission denied: 'C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\tmp0eyjv0qk.json'

This happens when export_chrome_trace tries to re-open a NamedTemporaryFile for reading (open(fp.name, "rb")) on Windows. On Windows, NamedTemporaryFile holds an exclusive lock by default, so a second open() on the same path fails with a PermissionError. This is a known Windows-specific behavior with tempfile.NamedTemporaryFile.

This test was moved into TestProfilerDevice by this PR, which caused it to run on the Windows CPU CI (via instantiate_device_type_tests). The underlying issue is in torch/profiler/profiler.py's export_chrome_trace code (not in the test itself), but the test previously may not have been exercised on Windows in this configuration. This is a pre-existing Windows bug that was surfaced by this PR's test refactoring.

Summary

Failure Related to PR? Action needed?
linux-docs (x2) No — infra issue (aws CLI missing) None
win-vs2022 test Indirectly — PR surfaced a pre-existing Windows PermissionError in export_chrome_trace with gzip mode May need a skipIfWindows or fix the underlying tempfile handling

@jansel jansel 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.

fix test failures

RiyaP2508 added a commit that referenced this pull request May 31, 2026
…est_profiler

Create TestProfilerDevice class with 20 tests moved from TestProfiler,
refactored to be device-agnostic using instantiate_device_type_tests.

Infrastructure added: get_profiler_activities(device_type) helper,
@onlyAccelerator decorator for GPU-required tests, @OnlyOn(["cpu", "cuda"])
for tests with CUDA-specific assertions (test_kineto,
test_kineto_profiler_with_environment_variable,
test_activity_filter_dict_syntax, test_kineto_kernel_metadata_in_trace).

ghstack-source-id: 0b4c13f
Pull Request resolved: #182434
…_tests in test_profiler"


**Summary**
Create TestProfilerDevice class with 20 tests moved from TestProfiler, refactored to be device-agnostic using instantiate_device_type_tests.

**Infrastructure added:**
- get_profiler_activities(device_type) helper that dynamically builds the ProfilerActivity list
- onlyAccelerator decorator for GPU-required tests
- onlyOn(["cpu", "cuda"]) for tests with CUDA-specific assertions
- instantiate_device_type_tests(TestProfilerDevice, globals())

**Moved and refactored tests:**
- test_kineto — onlyOn(["cpu", "cuda"]), device-agnostic profiling with CUDA/ROCm kernel checks guarded
- test_memory_profiler — conditional device memory checks
- test_flops — device-agnostic activity list
- test_kineto_profiler_api — multi-backend profiler API
- test_kineto_profiler_multiple_steppers — step tracking across backends
- test_tensorboard_trace_handler — device-agnostic trace export
- test_kineto_profiler_with_environment_variable — onlyOn(["cpu", "cuda"]), subprocess self-detects device
- test_event_list — onlyAccelerator
- test_basic_chrome_trace — device-aware Chrome trace validation
- test_cpu_annotation_overlap — device-agnostic activity list
- test_user_annotation — simple device param
- test_basic_profile — onlyAccelerator
- test_dynamic_toggle — onlyAccelerator
- test_forked_process — skips on CUDA/XPU due to fork-after-init
- test_profile_all_threads — onlyAccelerator
- test_profiler — device-agnostic with PrivateUse1 fallback
- test_activity_filter_dict_syntax — onlyOn(["cpu", "cuda"]), onlyAccelerator
- test_activity_filter_nonmember_type_name — onlyAccelerator
- test_activity_filter_empty_list — onlyAccelerator
- test_kineto_kernel_metadata_in_trace — onlyOn(["cpu", "cuda"]), onlyAccelerator

**Note:** test_kineto_profiler_with_environment_variable self-detects the available device in its subprocess script. test_forked_process skips on CUDA/XPU due to fork-after-init restrictions.

**Test plan**
Verified on CUDA: 111 passed, 11 skipped, 0 failures

cc: albanD fffrog mansiag05


[ghstack-poisoned]
@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

fix test failures

done, updated in latest commit

@jansel

jansel commented May 31, 2026

Copy link
Copy Markdown
Contributor

@claude explain those CI failures, are they related?

@claude

claude Bot commented May 31, 2026 •

Copy link
Copy Markdown

Claude finished @jansel's task in 1m 27s —— View job


CI Failure Analysis

  • Check current CI status
  • Analyze failures and determine if they're related to this PR

The 2 failures are related to each other but NOT related to this PR's changes. They share the same root cause: a CI infrastructure issue.

linux-docs / build-docs-python-false and linux-docs / build-docs-cpp-false

Root cause: aws: command not found (exit code 127)

Both jobs failed at the S3 upload step ("Upload Python Docs Preview" / "Upload C++ Docs Preview") — the docs themselves built successfully. The error is:

line 1: aws: command not found

The aws CLI is not installed in the container that runs the upload step. This is a CI infrastructure issue — the Docker image or runner environment is missing the AWS CLI. The actual docs generation completed fine in both cases (the Python docs job committed 5412 changed files before failing on upload).

This has nothing to do with the test_profiler.py changes in this PR. These jobs would fail on any PR running on this CI configuration right now.

Previous Windows failure (now resolved)

The earlier win-vs2022-cpu-py3 / test (default, 2, 4) failure (PermissionError on NamedTemporaryFile in test_tensorboard_trace_handler_cpu) appears to have been addressed in the latest commit per RiyaP2508's comment, and no test failures remain in the current run.


@RiyaP2508
RiyaP2508 requested a review from jansel June 1, 2026 06:52

@jbschlosser jbschlosser 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.

looks good if all tests are passing

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i "unrelated failures"

@pytorch-bot

pytorch-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: unrecognized arguments: unrelated failures

usage: @pytorchbot [-h]
                   
                   {merge,revert,rebase,label,drci,lint,fix-lint,apply-lint,cherry-pick}
                   ...

Try @pytorchbot --help for more info.

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@pytorch-bot

pytorch-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

This PR has pending changes requested. Please address the comments and update the PR before merging.

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

fix test failures

Done, addressed them.

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

@jansel The test failures have been fixed. Could you please re-review?
Thank you!

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -f "linux-docs failures are infra issues (aws CLI missing), not related to PR changes"

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use -f as last resort and instead consider -i/--ignore-current to continue the merge ignoring current failures. This will allow currently pending tests to finish and report signal before the merge.

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

@github-project-automation github-project-automation Bot moved this from Ready for Review(Definitive) to Done in PyTorch Test Refactoring Jun 2, 2026
meta-codesync Bot pushed a commit to pytorch/kineto that referenced this pull request Jun 26, 2026
Summary:
## Problem

`linux_xpu_pytorch.yml` has been red on `main`. The job builds PyTorch (`USE_XPU=1`) and runs `test/profiler/`. Two CPU-variant tests from the device-parametrized `TestProfilerDevice` (added in pytorch/pytorch#182434) fail and were never deselected for XPU, unlike CUDA/ROCm (#1429).

## What fails and why (verified on PVC with an XPU device present)

- **`test_forked_process_cpu`** — `RuntimeError: Cannot re-initialize XPU in forked subprocess`. Independent of runtime XPU availability (it also fails with an XPU device present); already deselected on CUDA and ROCm.
- **`test_basic_chrome_trace_cpu`** — `_validate_basic_json` indexes `traceEvents[-4]` expecting the `"PyTorch Profiler (0)"` event, but a `USE_XPU=1` build appends a second `"__xpu_profiler__ (0)"` instance to the trace, shifting that fixed offset. Caused by XPU being *built*, not by runtime availability. An upstream fix to locate the events by name instead of by offset is tracked separately; deselecting until it lands.

## Relationship to #1450

Orthogonal. #1450 fixes runtime XPU visibility (`umf`/`tcm` env sourcing); this PR fixes the two build-dependent test failures. Both are needed for the workflow to go green.

Note: `test_kineto_profiler_with_environment_variable_cpu` is intentionally **not** deselected here — it passes once XPU is available at runtime (covered by #1450).

Pull Request resolved: #1451

Reviewed By: scotts

Differential Revision: D109839396

Pulled By: ryanzhang22

fbshipit-source-id: 7a865d27175a92f8fc0cf42d1e37b10d532a26db
@github-actions
github-actions Bot deleted the gh/RiyaP2508/9/head branch July 3, 2026 03:37
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…est_profiler (pytorch#182434)

**Summary**
Create TestProfilerDevice class with 20 tests moved from TestProfiler, refactored to be device-agnostic using instantiate_device_type_tests.

**Infrastructure added:**
- get_profiler_activities(device_type) helper that dynamically builds the ProfilerActivity list
- @onlyAccelerator decorator for GPU-required tests
- @OnlyOn(["cpu", "cuda"]) for tests with CUDA-specific assertions
- instantiate_device_type_tests(TestProfilerDevice, globals())

**Moved and refactored tests:**
- test_kineto — @OnlyOn(["cpu", "cuda"]), device-agnostic profiling with CUDA/ROCm kernel checks guarded
- test_memory_profiler — conditional device memory checks
- test_flops — device-agnostic activity list
- test_kineto_profiler_api — multi-backend profiler API
- test_kineto_profiler_multiple_steppers — step tracking across backends
- test_tensorboard_trace_handler — device-agnostic trace export
- test_kineto_profiler_with_environment_variable — @OnlyOn(["cpu", "cuda"]), subprocess self-detects device
- test_event_list — @onlyAccelerator
- test_basic_chrome_trace — device-aware Chrome trace validation
- test_cpu_annotation_overlap — device-agnostic activity list
- test_user_annotation — simple device param
- test_basic_profile — @onlyAccelerator
- test_dynamic_toggle — @onlyAccelerator
- test_forked_process — skips on CUDA/XPU due to fork-after-init
- test_profile_all_threads — @onlyAccelerator
- test_profiler — device-agnostic with PrivateUse1 fallback
- test_activity_filter_dict_syntax — @OnlyOn(["cpu", "cuda"]), @onlyAccelerator
- test_activity_filter_nonmember_type_name — @onlyAccelerator
- test_activity_filter_empty_list — @onlyAccelerator
- test_kineto_kernel_metadata_in_trace — @OnlyOn(["cpu", "cuda"]), @onlyAccelerator

**Note:** test_kineto_profiler_with_environment_variable self-detects the available device in its subprocess script. test_forked_process skips on CUDA/XPU due to fork-after-init restrictions.

**Test plan**
Verified on CUDA: 111 passed, 11 skipped, 0 failures

Pull Request resolved: pytorch#182434
Approved by: https://github.com/fffrog, https://github.com/jansel, https://github.com/jbschlosser
ghstack dependencies: pytorch#182432, pytorch#182433
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…est_profiler (pytorch#182434)

**Summary**
Create TestProfilerDevice class with 20 tests moved from TestProfiler, refactored to be device-agnostic using instantiate_device_type_tests.

**Infrastructure added:**
- get_profiler_activities(device_type) helper that dynamically builds the ProfilerActivity list
- @onlyAccelerator decorator for GPU-required tests
- @OnlyOn(["cpu", "cuda"]) for tests with CUDA-specific assertions
- instantiate_device_type_tests(TestProfilerDevice, globals())

**Moved and refactored tests:**
- test_kineto — @OnlyOn(["cpu", "cuda"]), device-agnostic profiling with CUDA/ROCm kernel checks guarded
- test_memory_profiler — conditional device memory checks
- test_flops — device-agnostic activity list
- test_kineto_profiler_api — multi-backend profiler API
- test_kineto_profiler_multiple_steppers — step tracking across backends
- test_tensorboard_trace_handler — device-agnostic trace export
- test_kineto_profiler_with_environment_variable — @OnlyOn(["cpu", "cuda"]), subprocess self-detects device
- test_event_list — @onlyAccelerator
- test_basic_chrome_trace — device-aware Chrome trace validation
- test_cpu_annotation_overlap — device-agnostic activity list
- test_user_annotation — simple device param
- test_basic_profile — @onlyAccelerator
- test_dynamic_toggle — @onlyAccelerator
- test_forked_process — skips on CUDA/XPU due to fork-after-init
- test_profile_all_threads — @onlyAccelerator
- test_profiler — device-agnostic with PrivateUse1 fallback
- test_activity_filter_dict_syntax — @OnlyOn(["cpu", "cuda"]), @onlyAccelerator
- test_activity_filter_nonmember_type_name — @onlyAccelerator
- test_activity_filter_empty_list — @onlyAccelerator
- test_kineto_kernel_metadata_in_trace — @OnlyOn(["cpu", "cuda"]), @onlyAccelerator

**Note:** test_kineto_profiler_with_environment_variable self-detects the available device in its subprocess script. test_forked_process skips on CUDA/XPU due to fork-after-init restrictions.

**Test plan**
Verified on CUDA: 111 passed, 11 skipped, 0 failures

Pull Request resolved: pytorch#182434
Approved by: https://github.com/fffrog, https://github.com/jansel, https://github.com/jbschlosser
ghstack dependencies: pytorch#182432, pytorch#182433
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

6 participants