Skip to content

[Test] Refactor payload()'s use_cuda to device param in test_profiler - #182432

Closed
RiyaP2508 wants to merge 6 commits into
gh/RiyaP2508/7/basefrom
gh/RiyaP2508/7/head
Closed

RiyaP2508 wants to merge 6 commits into
gh/RiyaP2508/7/basefrom
gh/RiyaP2508/7/head

Conversation

@RiyaP2508

@RiyaP2508 RiyaP2508 commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Summary

Replace the use_cuda boolean pattern in TestProfiler.payload() with a device parameter using .to(device) pattern. Update all callers including test_disable_external_correlation and test_kineto_kernel_metadata_in_trace.

Also update sort_by to use self_device_time_total (the non-deprecated replacement for self_cuda_time_total) and simplify use_device variable.

Test plan

  • Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: @albanD @fffrog @mansiag05

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label May 5, 2026
@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/182432

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

❌ 2 New Failures

As of commit bcc400d 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.

…ities() helper

Replace the use_cuda boolean pattern in TestProfiler.payload() with a
device parameter, and add a get_profiler_activities() helper that
dynamically builds the activity list for any device type.

Update 8 tests that used the old use_cuda pattern: test_kineto,
test_kineto_profiler_api, test_kineto_profiler_multiple_steppers,
test_tensorboard_trace_handler, test_user_annotation,
test_kineto_profiler_with_environment_variable,
test_disable_external_correlation, and test_profiler. Also update
sort_by to use "self_device_time_total" and replace hardcoded
DeviceType.CUDA with device-agnostic getattr(DeviceType, device.upper()).

[ghstack-poisoned]
@RiyaP2508 RiyaP2508 changed the title [test] Refactor payload() to device-agnostic + add get_profiler_activities() helper [Test] Refactor use_cuda to device param and add get_profiler_activities helper in test_profiler May 5, 2026
@mansiag05 mansiag05 moved this from Backlog to Ready for Review in PyTorch Test Refactoring May 6, 2026
Comment thread test/profiler/test_profiler.py Outdated
from torch.autograd.profiler_util import FunctionEvent


def get_profiler_activities(device_type):

@fffrog fffrog May 7, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @RiyaP2508, thank you for abstracting this helper function!

But I perfer you to move this function definitin to #182434, because the function don`t be invoked in current PR

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, thanks! You're right - this helper isn't invoked in this PR. I'll move the get_profiler_activities() definition to #182434 where it's first used. Will update.

Comment thread test/profiler/test_profiler.py Outdated
def test_kineto(self):
use_cuda = torch.profiler.ProfilerActivity.CUDA in supported_activities()
device = "cuda" if use_cuda else "cpu"
use_device = "cuda" if use_cuda else None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can safely remove use_device, and using device instead

with _profile(use_device=device, use_kineto=True):
            self.payload(device=device)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I agree we should remove the redundant use_device variable. However, _profile(use_device="cpu") isn't valid - the profiler only accepts "cuda", "xpu", "mtia", "hpu" for use_device (see torch/autograd/profiler.py lines 276-284), and passing "cpu" triggers a warning before falling back to None.

I'll simplify it by removing use_device and inlining the logic:

with _profile(use_device=device if use_cuda else None, use_kineto=True):
    self.payload(device=device)

This removes the extra variable as you suggested while correctly passing None for CPU. Hope this works!


output = p.key_averages().table(
sort_by="self_cuda_time_total" if use_cuda else "self_cpu_time_total",
sort_by="self_device_time_total" if use_cuda else "self_cpu_time_total",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

self_cuda_time_total is a built-in term, so we can not change it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for flagging! Actually self_cuda_time_total is deprecated in favor of self_device_time_total - see torch/autograd/profiler_util.py lines 968-973:

@deprecated(
    "`self_cuda_time_total` is deprecated. Use `self_device_time_total` instead.",
    category=FutureWarning,
)
def self_cuda_time_total(self):
    return self.self_device_time_total

The table() sort logic (line 1241) also normalizes "cuda" → "device" internally, so both keys resolve to the same attribute. Using self_device_time_total aligns with the device-agnostic direction, let me know thoughts!

def trace_handler(p):
output = p.key_averages().table(
sort_by="self_cuda_time_total" if use_cuda else "self_cpu_time_total",
sort_by="self_device_time_total" if use_cuda else "self_cpu_time_total",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

self.payload(device=device)
output = p.key_averages().table(
sort_by="self_cuda_time_total" if use_cuda else "self_cpu_time_total",
sort_by="self_device_time_total" if use_cuda else "self_cpu_time_total",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

@fffrog fffrog moved this from Ready for Review(Definitive) to Ready for Review(Initial) in PyTorch Test Refactoring May 7, 2026
@@ -513,18 +516,19 @@ def _check_stats(self, profiler_stats):
@unittest.skipIf(not kineto_available(), "Kineto is required")
def test_kineto(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

test_kineto is intended to be accelerator-agnostic, but it currently contains logic that specifically depends on CUDA and ROCm:

found_gemm = False
        found_memcpy = False
        found_mm = False
        for e in p.function_events:
            if "aten::mm" in e.name:
                found_mm = True
            if "gemm" in e.name.lower() or "Cijk" in e.name:
                found_gemm = True
            if "memcpy" in e.name.lower() or "__amd_rocclr_copyBuffer" in e.name:
                found_memcpy = True
        if use_cuda:
            self.assertTrue(found_gemm)
            self.assertTrue(found_memcpy)
        else:
            self.assertTrue(found_mm)

Therefore, I suggest moving these test cases into a separate class and using a decorator to restrict their execution to CPU and CUDA only in next PR and leave the deeper refactor for future update.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good observation! The gemm, Cijk, memcpy, and __amd_rocclr_copyBuffer checks are indeed CUDA/ROCm-specific. They're guarded by if use_cuda: (line 541), so on non-CUDA backends the test falls back to just checking aten::mm.

This means the test won't break on XPU or other accelerators, but also won't validate their device-specific kernel events - it effectively runs the CPU assertion path. Making the kernel-name checks truly device-agnostic would require knowing each backend's kernel naming conventions.

Happy to note this as a follow-up for deeper refactoring, or move test_kineto to TestProfilerCUDA if you prefer keeping it CUDA/ROCm-only for now. Let me know your preference!

Comment thread test/profiler/test_profiler.py Resolved
@fffrog

fffrog commented May 7, 2026

Copy link
Copy Markdown
Collaborator

Hey @RiyaP2508, the Profiler module is quite complex and contains a lot of hardcoded and special logic. I'm going to dig deeper into this test file tomorrow to provide you with comprehensive feedback. In the meantime, feel free to switch context and work on other tasks until I leave my comments. Sorry for the delay!

@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

Hey @RiyaP2508, the Profiler module is quite complex and contains a lot of hardcoded and special logic. I'm going to dig deeper into this test file tomorrow to provide you with comprehensive feedback. In the meantime, feel free to switch context and work on other tasks until I leave my comments. Sorry for the delay!

Thanks @fffrog! No worries at all - I really appreciate you taking the time to dig deeper into the profiler module. Looking forward to your comprehensive feedback tomorrow. I'll hold off on making changes to this PR stack until then so we're aligned on the approach.

@fffrog

fffrog commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Hey @RiyaP2508

  • TestProfilerCUDA and TestProfilerITT are backend-specific and do not require any changes.
  • TestProfiler, by definition, should focus on testing the general mechanisms of the Profiler, independent of any specific accelerator implementation.
    • Move CUDA-specific test cases to TestProfilerCUDA. This includes the following cases (these can be moved here temporarily and may be relocated to TestProfilerDevice later as the architecture evolves):
      • test_kineto_multigpu
      • test_oom_tracing
      • test_profiler_cuda_sync_events
      • test_disable_external_correlation
      • test_activity_filter_mixed_syntax
    • Move test cases that theoretically should run on multiple backends to a new class, TestProfilerDevice**. This includes the following cases (note that some may require @onlyOn(["cpu", "cuda"]) or skipIf due to internal test logic):
      • 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

The remaining classes, such as TestExperimentalUtils, TestProfilerDeviceStopped, and TestProfilerEventsParity, should follow a similar logic.

And suggest completing the removal of hard-coded values and the refactoring simultaneously while moving these cases.

@fffrog

fffrog commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Refactoring tests is no small feat. While some files are straightforward, others can be quite tricky—and test_profiler.py is definitely one of the more challenging ones.

Please don’t feel pressured to tackle everything at once; feel free to split the changes for this file into multiple PRs if that’s easier. If you have any questions or run into any roadblocks, don't hesitate to ping me. We really appreciate your hard work and contribution!

@RiyaP2508 RiyaP2508 changed the title [Test] Refactor use_cuda to device param and add get_profiler_activities helper in test_profiler [Test] Refactor use_cuda to device param in test_profiler May 11, 2026
…ler_activities helper in test_profiler"


## Summary
Replace the `use_cuda` boolean pattern in profiler tests with a device-agnostic `device` parameter.
**Changes:**
- Add `get_profiler_activities(device_type)` helper that dynamically builds the `ProfilerActivity` list for any device type
- Refactor `TestProfiler.payload(use_cuda=False)` → `payload(device="cpu")` using `.to(device)` pattern
- Refactor standalone `payload()` function in `test_kineto_profiler_with_environment_variable` subprocess script
- Update `sort_by="self_cuda_time_total"` → `"self_device_time_total"`
- Replace hardcoded `DeviceType.CUDA` with `getattr(DeviceType, device.upper())`
- Update all 8 callers: test_kineto, test_kineto_profiler_api, test_kineto_profiler_multiple_steppers, test_tensorboard_trace_handler, test_user_annotation, test_kineto_profiler_with_environment_variable, test_disable_external_correlation, test_profiler
## Test plan
- [x] Verified on CUDA: 110 passed, 2 skipped, 0 failures
- No behavioral changes - same tests, same logic, just device-agnostic API

CC: albanD fffrog mansiag05 

[ghstack-poisoned]
@RiyaP2508

Copy link
Copy Markdown
Collaborator Author

Hey @RiyaP2508

  • TestProfilerCUDA and TestProfilerITT are backend-specific and do not require any changes.

  • TestProfiler, by definition, should focus on testing the general mechanisms of the Profiler, independent of any specific accelerator implementation.

    • Move CUDA-specific test cases to TestProfilerCUDA. This includes the following cases (these can be moved here temporarily and may be relocated to TestProfilerDevice later as the architecture evolves):

      • test_kineto_multigpu
      • test_oom_tracing
      • test_profiler_cuda_sync_events
      • test_disable_external_correlation
      • test_activity_filter_mixed_syntax
    • Move test cases that theoretically should run on multiple backends to a new class, TestProfilerDevice**. This includes the following cases (note that some may require @onlyOn(["cpu", "cuda"]) or skipIf due to internal test logic):

      • 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

The remaining classes, such as TestExperimentalUtils, TestProfilerDeviceStopped, and TestProfilerEventsParity, should follow a similar logic.

And suggest completing the removal of hard-coded values and the refactoring simultaneously while moving these cases.

Hi @fffrog,

Apologies for the delayed response - really appreciate your patience and the detailed guidance you've provided. Your breakdown of the test structure made everything much clearer.
I've reworked the PR stack based on your feedback:
PR #182432 - Refactors payload() to use a device parameter instead of use_cuda, adds the get_profiler_activities() helper, and incorporates all your review fixes (moved helper to PR3, inlined use_device, added PrivateUse1 fallback).

PR #182433 - Moves the 5 CUDA-specific tests to TestProfilerCUDA:

  • test_kineto_multigpu
  • test_oom_tracing
  • test_profiler_cuda_sync_events
  • test_disable_external_correlation
  • test_activity_filter_mixed_syntax

PR #182434 - Creates TestProfilerDevice with all 19 multi-backend tests you listed, refactoring hardcoded values as part of the move. Using instantiate_device_type_tests() to enable parameterized device testing.

Follow-up PRs - Will tackle EventsParity, ExperimentalUtils, and DeviceStopped in subsequent PRs to keep each change focused and reviewable.

Thanks again for taking the time to outline the structure and for being so supportive throughout this process. Let me know if you'd like me to adjust anything!

@RiyaP2508
RiyaP2508 requested a review from fffrog May 11, 2026 20:01
Comment thread test/profiler/test_profiler.py Resolved

@fffrog fffrog left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

SGTM, thank you for updates.

@fffrog fffrog moved this from Ready for Review(Initial) to Ready for Review(Definitive) in PyTorch Test Refactoring May 13, 2026
## Summary

Replace the `use_cuda` boolean pattern in TestProfiler.payload() with a device parameter using `.to(device)` pattern. Update all callers including test_disable_external_correlation and test_kineto_kernel_metadata_in_trace.

Also update `sort_by` to use `self_device_time_total` (the non-deprecated replacement for `self_cuda_time_total`), simplify `use_device` variable, and add PrivateUse1 fallback for DeviceType lookup.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: albanD fffrog mansiag05 

[ghstack-poisoned]
@jbschlosser jbschlosser changed the title [Test] Refactor payload() use_cuda to device param in payload() of test_profiler [Test] Refactor payload()'s use_cuda to device param in test_profiler May 19, 2026

@albanD albanD left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thx

@jbschlosser

Copy link
Copy Markdown
Contributor

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 22, 2026
@jbschlosser jbschlosser moved this from Ready for Review(Definitive) to Ready for Merge in PyTorch Test Refactoring May 22, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-jammy-aarch64-py3.10 / test (default, 2, 5, linux.arm64.m7g.4xlarge)

Details for Dev Infra team Raised by workflow job

RiyaP2508 added 2 commits May 31, 2026 14:53
…st_profiler"


## Summary

Replace the use_cuda boolean pattern in TestProfiler.payload() with a device parameter using .to(device) pattern. Update all callers including test_disable_external_correlation and test_kineto_kernel_metadata_in_trace.

Also update sort_by to use self_device_time_total (the non-deprecated replacement for self_cuda_time_total) and simplify use_device variable.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: albanD fffrog mansiag05 

[ghstack-poisoned]
…st_profiler"


## Summary

Replace the use_cuda boolean pattern in TestProfiler.payload() with a device parameter using .to(device) pattern. Update all callers including test_disable_external_correlation and test_kineto_kernel_metadata_in_trace.

Also update sort_by to use self_device_time_total (the non-deprecated replacement for self_cuda_time_total) and simplify use_device variable.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: albanD fffrog mansiag05 

[ghstack-poisoned]
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Starting merge as part of PR stack under #182434

pytorchmergebot pushed a commit that referenced this pull request Jun 2, 2026
… in test_profiler (#182433)

## Summary

Move 5 tests that use CUDA-only APIs from TestProfiler to TestProfilerCUDA where they belong under the existing class-level CUDA skip guard.

**Moved tests:** test_kineto_multigpu, test_oom_tracing, test_profiler_cuda_sync_events, test_disable_external_correlation, test_activity_filter_mixed_syntax.

Also copies payload() and _check_stats() helper methods to TestProfilerCUDA since the moved tests depend on them, and removes redundant per-method @skipIf(not torch.cuda.is_available()) decorators that duplicate the class-level guard.

No logic changes - pure code relocation.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: @albanD @fffrog @mansiag05
Pull Request resolved: #182433
Approved by: https://github.com/fffrog, https://github.com/albanD, https://github.com/jbschlosser
ghstack dependencies: #182432
pytorchmergebot pushed a commit that referenced this pull request Jun 2, 2026
…est_profiler (#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: #182434
Approved by: https://github.com/fffrog, https://github.com/jansel, https://github.com/jbschlosser
ghstack dependencies: #182432, #182433
@github-project-automation github-project-automation Bot moved this from Ready for Merge to Done in PyTorch Test Refactoring Jun 2, 2026
@github-actions
github-actions Bot deleted the gh/RiyaP2508/7/head branch July 3, 2026 03:37
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…pytorch#182432)

## Summary

Replace the use_cuda boolean pattern in TestProfiler.payload() with a device parameter using .to(device) pattern. Update all callers including test_disable_external_correlation and test_kineto_kernel_metadata_in_trace.

Also update sort_by to use self_device_time_total (the non-deprecated replacement for self_cuda_time_total) and simplify use_device variable.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: @albanD @fffrog @mansiag05
Pull Request resolved: pytorch#182432
Approved by: https://github.com/fffrog, https://github.com/albanD, https://github.com/jbschlosser
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
… in test_profiler (pytorch#182433)

## Summary

Move 5 tests that use CUDA-only APIs from TestProfiler to TestProfilerCUDA where they belong under the existing class-level CUDA skip guard.

**Moved tests:** test_kineto_multigpu, test_oom_tracing, test_profiler_cuda_sync_events, test_disable_external_correlation, test_activity_filter_mixed_syntax.

Also copies payload() and _check_stats() helper methods to TestProfilerCUDA since the moved tests depend on them, and removes redundant per-method @skipIf(not torch.cuda.is_available()) decorators that duplicate the class-level guard.

No logic changes - pure code relocation.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: @albanD @fffrog @mansiag05
Pull Request resolved: pytorch#182433
Approved by: https://github.com/fffrog, https://github.com/albanD, https://github.com/jbschlosser
ghstack dependencies: pytorch#182432
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
…pytorch#182432)

## Summary

Replace the use_cuda boolean pattern in TestProfiler.payload() with a device parameter using .to(device) pattern. Update all callers including test_disable_external_correlation and test_kineto_kernel_metadata_in_trace.

Also update sort_by to use self_device_time_total (the non-deprecated replacement for self_cuda_time_total) and simplify use_device variable.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: @albanD @fffrog @mansiag05
Pull Request resolved: pytorch#182432
Approved by: https://github.com/fffrog, https://github.com/albanD, https://github.com/jbschlosser
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
… in test_profiler (pytorch#182433)

## Summary

Move 5 tests that use CUDA-only APIs from TestProfiler to TestProfilerCUDA where they belong under the existing class-level CUDA skip guard.

**Moved tests:** test_kineto_multigpu, test_oom_tracing, test_profiler_cuda_sync_events, test_disable_external_correlation, test_activity_filter_mixed_syntax.

Also copies payload() and _check_stats() helper methods to TestProfilerCUDA since the moved tests depend on them, and removes redundant per-method @skipIf(not torch.cuda.is_available()) decorators that duplicate the class-level guard.

No logic changes - pure code relocation.

## Test plan
- Verified on CUDA: 100 passed, 2 skipped, 0 failures

CC: @albanD @fffrog @mansiag05
Pull Request resolved: pytorch#182433
Approved by: https://github.com/fffrog, https://github.com/albanD, https://github.com/jbschlosser
ghstack dependencies: pytorch#182432
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