Repository navigation
Conversation
🔗 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 FailuresAs of commit bcc400d with merge base 019cea9 ( 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]
| from torch.autograd.profiler_util import FunctionEvent | ||
|
|
||
|
|
||
| def get_profiler_activities(device_type): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
We can safely remove use_device, and using device instead
with _profile(use_device=device, use_kineto=True):
self.payload(device=device)There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
self_cuda_time_total is a built-in term, so we can not change it.
There was a problem hiding this comment.
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", |
| 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", |
| @@ -513,18 +516,19 @@ def _check_stats(self, profiler_stats): | |||
| @unittest.skipIf(not kineto_available(), "Kineto is required") | |||
| def test_kineto(self): | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
|
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. |
|
Hey @RiyaP2508
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. |
|
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! |
…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]
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. PR #182433 - Moves the 5 CUDA-specific tests to TestProfilerCUDA:
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! |
fffrog
left a comment
There was a problem hiding this comment.
SGTM, thank you for updates.
## 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]
|
@pytorchbot merge |
Merge startedYour 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 |
Merge failedReason: 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 teamRaised by workflow job |
…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]
|
Starting merge as part of PR stack under #182434 |
… 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
…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
…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
… 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
…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
…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
… 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
…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
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
CC: @albanD @fffrog @mansiag05