Summary:
Problem
The PyTorch profiler crashes when an active backend produces duplicate async-flow correlation IDs. TransferEvents::setParents() asserts on collisions outside ROCm builds, so workloads abort instead of completing.
Why
The assert was originally added in PR #102424 to defend against a libkineto segfault class that is independent of flow_map. flow_map only affects parent-tree linkage in the PyTorch event tree; a duplicate ID can produce wrong CPU-op attribution for a GPU kernel in key_averages() / tree views but never a memory-safety issue. Crashing is disproportionate.
Fix
On collision, poison the flow_map slot (set to null) so the second-pass lookup produces no override. The colliding flow end then retains its kineto runtime-correlation parent set earlier in the first pass — approximate but never wrong. The change also removes the #ifdef USE_ROCM gate so all backends benefit. Count dropped links and emit a single summary TORCH_WARN so the symptom is discoverable beyond the rate-limited TORCH_WARN_ONCE.
Test
A new test_profiler_collection.cpp covers the duplicate-flow path. It uses
the PrivateUse1 machinery to mock the profiler. We can put new unit tests for
collection.cpp in this file.
Reviewed By: aaronenyeshi, NicolasHug
Differential Revision: D105979688
Pull Request resolved: #184792
Approved by: https://github.com/NicolasHug, https://github.com/malfet, https://github.com/aaronenyeshi