Repository navigation
[Profiler] Add priority key to EventsMetadata - #180100
ryanzhang22 wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180100
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ No FailuresAs of commit 563bb25 with merge base d15b805 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
115ab2d to
23d7b69
Compare
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
23d7b69 to
563bb25
Compare
|
@ryanzhang22, do we need to wait until we do another Kineto release that has pytorch/kineto#1361 before merging this one? I don't see any logic that connects the C++ layer to what's in the Python, which I was expecting to see. |
Shouldn't need to -- this just shows up as None if it can't be parsed from the JSON |
|
@ryanzhang22 has imported this pull request. If you are a Meta employee, you can view this in D100688145. |
|
@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: 8 mandatory check(s) failed. The first few are:
Dig deeper by viewing the failures on hud |
|
@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 |
As titled Demo, on top of pytorch/kineto#1361 ``` with torch.profiler.profile( activities=[torch.profiler.ProfilerActivity.CUDA], experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True) ) as prof: x = torch.randn(500, 500, device='cuda') y = torch.randn(500, 500, device='cuda') result = torch.matmul(x, y) ``` ``` EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None) ``` Pull Request resolved: #180100 Approved by: https://github.com/scotts
This was failing on ROCm and recently exposed by removing the early exit hack. Taking this as an opportunity to beef it up some more. Basically this will loop through events() and json outputs, fetch all the events, match them, and compare to make sure that every key in json is present in events and that the two match. Sample failure that I artificially induced: ``` AssertionError: ==================================================================================== IMPORTANT: Are you making a Kineto change or bumping the third_party/kineto submodule hash and seeing this message? New metadata keys (see below) were found in the Chrome trace JSON that are not yet exposed through the profiler's events() API (i.e. EventMetadata in torch/autograd/profiler_util.py). To fix this properly, you need to make sure the new Kineto data makes its way to the events() property. The steps are: 1. Add the new key(s) to _EVENT_METADATA_KEYS in torch/autograd/profiler_util.py with the appropriate field name and type converter. 2. Add corresponding field(s) to the EventMetadata dataclass in the same file. 3. If the key should NOT be mapped (e.g. it duplicates an existing FunctionEvent attribute), add it to allowed_non_structured_trace_keys in this test instead. For a model PR to follow, see: #180100 ==================================================================================== Unmapped keys: Memcpy DtoH (Device -> Pageable) (gpu_memcpy): 'device' ampere_sgemm_32x128_nn (kernel): 'device' cudaDeviceGetAttribute (cuda_runtime): 'cbid' cudaDeviceGetStreamPriorityRange (cuda_runtime): 'cbid' cudaFree (cuda_runtime): 'cbid' cudaGetDriverEntryPoint (cuda_runtime): 'cbid' cudaGetSymbolAddress (cuda_runtime): 'cbid' cudaLaunchKernel (cuda_runtime): 'cbid' cudaMalloc (cuda_runtime): 'cbid' cudaMemcpyAsync (cuda_runtime): 'cbid' cudaOccupancyMaxActiveBlocksPerMultiprocessor (cuda_runtime): 'cbid' cudaStreamGetCaptureInfo_v2 (cuda_runtime): 'cbid' cudaStreamIsCapturing (cuda_runtime): 'cbid' cudaStreamSynchronize (cuda_runtime): 'cbid' void at::native::(anonymous namespace)::distribution_elementwise_grid_stride_kernel<float, 4, at::na (kernel): 'device' void at::native::vectorized_elementwise_kernel<4, at::native::CUDAFunctor_add<float>, std::array<cha (kernel): 'device' ``` Pull Request resolved: #180085 Approved by: https://github.com/scotts
As titled Demo, on top of pytorch/kineto#1361 ``` with torch.profiler.profile( activities=[torch.profiler.ProfilerActivity.CUDA], experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True) ) as prof: x = torch.randn(500, 500, device='cuda') y = torch.randn(500, 500, device='cuda') result = torch.matmul(x, y) ``` ``` EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None) ``` Pull Request resolved: pytorch#180100 Approved by: https://github.com/scotts
This was failing on ROCm and recently exposed by removing the early exit hack. Taking this as an opportunity to beef it up some more. Basically this will loop through events() and json outputs, fetch all the events, match them, and compare to make sure that every key in json is present in events and that the two match. Sample failure that I artificially induced: ``` AssertionError: ==================================================================================== IMPORTANT: Are you making a Kineto change or bumping the third_party/kineto submodule hash and seeing this message? New metadata keys (see below) were found in the Chrome trace JSON that are not yet exposed through the profiler's events() API (i.e. EventMetadata in torch/autograd/profiler_util.py). To fix this properly, you need to make sure the new Kineto data makes its way to the events() property. The steps are: 1. Add the new key(s) to _EVENT_METADATA_KEYS in torch/autograd/profiler_util.py with the appropriate field name and type converter. 2. Add corresponding field(s) to the EventMetadata dataclass in the same file. 3. If the key should NOT be mapped (e.g. it duplicates an existing FunctionEvent attribute), add it to allowed_non_structured_trace_keys in this test instead. For a model PR to follow, see: pytorch#180100 ==================================================================================== Unmapped keys: Memcpy DtoH (Device -> Pageable) (gpu_memcpy): 'device' ampere_sgemm_32x128_nn (kernel): 'device' cudaDeviceGetAttribute (cuda_runtime): 'cbid' cudaDeviceGetStreamPriorityRange (cuda_runtime): 'cbid' cudaFree (cuda_runtime): 'cbid' cudaGetDriverEntryPoint (cuda_runtime): 'cbid' cudaGetSymbolAddress (cuda_runtime): 'cbid' cudaLaunchKernel (cuda_runtime): 'cbid' cudaMalloc (cuda_runtime): 'cbid' cudaMemcpyAsync (cuda_runtime): 'cbid' cudaOccupancyMaxActiveBlocksPerMultiprocessor (cuda_runtime): 'cbid' cudaStreamGetCaptureInfo_v2 (cuda_runtime): 'cbid' cudaStreamIsCapturing (cuda_runtime): 'cbid' cudaStreamSynchronize (cuda_runtime): 'cbid' void at::native::(anonymous namespace)::distribution_elementwise_grid_stride_kernel<float, 4, at::na (kernel): 'device' void at::native::vectorized_elementwise_kernel<4, at::native::CUDAFunctor_add<float>, std::array<cha (kernel): 'device' ``` Pull Request resolved: pytorch#180085 Approved by: https://github.com/scotts
As titled Demo, on top of pytorch/kineto#1361 ``` with torch.profiler.profile( activities=[torch.profiler.ProfilerActivity.CUDA], experimental_config=torch._C._profiler._ExperimentalConfig(expose_kineto_event_metadata=True) ) as prof: x = torch.randn(500, 500, device='cuda') y = torch.randn(500, 500, device='cuda') result = torch.matmul(x, y) ``` ``` EventMetadata(registers_per_thread=84, shared_memory=12672, grid=[7, 7, 1], block=[64, 1, 1], priority=4, blocks_per_sm=0.331081, warps_per_sm=0.662162, occupancy=1.0, queued=0, graph_id=0, graph_node_id=0, stream=7, context=1, bytes=None, bandwidth_gb_s=None, collective_name=None, dtype=None, in_msg_nelems=None, out_msg_nelems=None, in_split_size=None, out_split_size=None, global_rank_start=None, global_rank_stride=None, group_size=None, process_group_name=None, process_group_desc=None, group_ranks=None, rank=None, src_rank=None, dst_rank=None, seq=None, is_async=None) ``` Pull Request resolved: pytorch#180100 Approved by: https://github.com/scotts
This was failing on ROCm and recently exposed by removing the early exit hack. Taking this as an opportunity to beef it up some more. Basically this will loop through events() and json outputs, fetch all the events, match them, and compare to make sure that every key in json is present in events and that the two match. Sample failure that I artificially induced: ``` AssertionError: ==================================================================================== IMPORTANT: Are you making a Kineto change or bumping the third_party/kineto submodule hash and seeing this message? New metadata keys (see below) were found in the Chrome trace JSON that are not yet exposed through the profiler's events() API (i.e. EventMetadata in torch/autograd/profiler_util.py). To fix this properly, you need to make sure the new Kineto data makes its way to the events() property. The steps are: 1. Add the new key(s) to _EVENT_METADATA_KEYS in torch/autograd/profiler_util.py with the appropriate field name and type converter. 2. Add corresponding field(s) to the EventMetadata dataclass in the same file. 3. If the key should NOT be mapped (e.g. it duplicates an existing FunctionEvent attribute), add it to allowed_non_structured_trace_keys in this test instead. For a model PR to follow, see: pytorch#180100 ==================================================================================== Unmapped keys: Memcpy DtoH (Device -> Pageable) (gpu_memcpy): 'device' ampere_sgemm_32x128_nn (kernel): 'device' cudaDeviceGetAttribute (cuda_runtime): 'cbid' cudaDeviceGetStreamPriorityRange (cuda_runtime): 'cbid' cudaFree (cuda_runtime): 'cbid' cudaGetDriverEntryPoint (cuda_runtime): 'cbid' cudaGetSymbolAddress (cuda_runtime): 'cbid' cudaLaunchKernel (cuda_runtime): 'cbid' cudaMalloc (cuda_runtime): 'cbid' cudaMemcpyAsync (cuda_runtime): 'cbid' cudaOccupancyMaxActiveBlocksPerMultiprocessor (cuda_runtime): 'cbid' cudaStreamGetCaptureInfo_v2 (cuda_runtime): 'cbid' cudaStreamIsCapturing (cuda_runtime): 'cbid' cudaStreamSynchronize (cuda_runtime): 'cbid' void at::native::(anonymous namespace)::distribution_elementwise_grid_stride_kernel<float, 4, at::na (kernel): 'device' void at::native::vectorized_elementwise_kernel<4, at::native::CUDAFunctor_add<float>, std::array<cha (kernel): 'device' ``` Pull Request resolved: pytorch#180085 Approved by: https://github.com/scotts
) TestProfilerEventsParity::test_structured_metadata_matches_chrome_trace fails on ROCm because kernel and copy events carry kineto's `hsa_queue` metadata field (libkineto MetadataFieldCatalog kHsaQueue, the HSA queue the activity was dispatched to), which `_EVENT_METADATA_KEYS` never mapped, so the parity check reports it as an unmapped key on four kernels. Following the test's own fix recipe (and the model in #180100): add the key to `_EVENT_METADATA_KEYS`, add the corresponding field to `EventMetadata` (None on CUDA; `EventMetadata` has a single keyword-only construction site, so the added field is backward-safe), and remove the test's ROCm skip. Test plan, on gfx950 (ROCm 10.0, HIP 7.15): the parity test passes (previously failed with unmapped 'hsa_queue'), 25 consecutive runs clean, and the 12 surrounding metadata/events tests pass. ``` PYTORCH_TEST_WITH_ROCM=1 python test/profiler/test_profiler.py -k test_structured_metadata_matches_chrome_trace ``` gfx942/gfx90a validation via the ciflow labels below; the auto-disabler remains as the safety net. This PR was authored with the assistance of an AI agent (Claude). The analysis and test results were verified by hand. Pull Request resolved: #196487 Approved by: https://github.com/jeffdaily Co-authored-by: Jeff Daily <[email protected]>
As titled
Demo, on top of pytorch/kineto#1361