This document is relevant for: Inf2, Trn1, Trn2, Trn3
Hierarchy Viewer#
Important
Upcoming change: In a future Neuron release, the Unified Trace Viewer will replace the Hierarchy Viewer in Neuron Explorer. You will still be able to view the framework hierarchy: the Unified Trace Viewer shows it as a collapsible Hierarchy group in each device profile. For details, see Announcing the Unified Trace Viewer as the default timeline in a future Neuron release.
The Hierarchy Viewer shows your model’s device execution in the terms of your own code. Use it to see how long each layer and operator ran, drill down from a model layer to the operators and NKI kernels inside it, and go from any of them to the hardware instructions they ran.
The viewer lays out the execution as nested levels on a timeline: the framework layers of your model, then the HLO operations within them. When the model calls NKI kernels, each kernel call also appears as a node under the framework operator (or operators) it ran within (see NKI kernel calls). The viewer is linked to the Device Trace Viewer. Right-click a node to highlight its instructions there, or click an instruction to highlight the nodes that contain it (see Highlighting).
Tip
The Unified Trace Viewer (Developer Preview) shows the hierarchy as a collapsible Hierarchy group in each device profile, on the same timeline as the system profile events.
Calling modules#
In PyTorch device profiles, the Hierarchy Viewer shows the host module calls that launched each device execution, as nodes above that execution. This works for eager mode, torch.compile, and workloads that mix the two. It matters most in eager mode: every call of a kernel runs the same NEFF, so without these nodes, repeated calls from different modules look identical in the hierarchy.
The calls come from the framework trace that the PyTorch profiler records. They are nn.Module calls, recorded when you profile with with_stack=True, and ranges you add with torch.profiler.record_function. Nested calls appear as nested nodes, outermost first. Each call is one node labeled <name> [<index>], where <index> is the execution index of the first execution the call launched. Executions launched from the same call share its node, and the node spans those executions on the device timeline. For a torch.compile run, the module path inside the NEFF still appears below the execution.
To get calling modules:
Profile with the PyTorch profiler, as in Capture PyTorch profiles with Neuron Explorer, and upload the whole session directory, so the framework trace (
trace.json) is uploaded with the device profiles.For PyTorch’s module names, pass
with_stack=Truetotorch.profiler.profile(see Capture PyTorch profiles with Neuron Explorer). The names are the module class and an instance counter, such asnn.Module: ConvBlock_2, not the attribute name.with_stack=Truealso makes the framework trace much larger.To choose the names yourself, wrap calls in
record_function. This works withoutwith_stackand keeps the trace small:with torch.profiler.record_function("conv_in"): x = self.conv_in(x)
The same calls also appear in these places:
The Operator Table, as parent rows above their executions.
The Hierarchy field of the instruction hover, when it is turned on in Settings > Hover Options.
The
caller_namesandcaller_idscolumns of ExecutionInfo.
Limitations:
A device-only upload (NEFF and NTFF files) has no framework trace, so the hierarchy shows no calling modules.
With Adaptive Eager Execution (
TORCH_NEURONX_ENABLE_CONCATENATION=1), one execution can hold operations from more than one module call. Such an execution can appear with no calling modules above it.
Zooming#
You can zoom in on the Hierarchy Viewer in a couple of ways:
Click-drag your mouse across the graph (support in both directions)
Scroll down using your mouse wheel, with the mouse cursor on the x-axis
Zoom in and out buttons in the top-right corner
With the keyboard:
W and S for zooming in and out, respectively
Up and down arrow keys for zooming in and out, respectively
To zoom out, simply scroll up with your mouse wheel when you place your mouse cursor on the x-axis.
Highlighting#
Right-clicking an operator in the Hierarchy Viewer highlights all the corresponding instructions in the Device Trace Viewer for the operator using the same color, and the Device Trace Viewer scrolls to the first highlighted instruction. Multiple operators can be highlighted at once. Right-clicking a highlighted operator again clears only its highlight. In the other direction, clicking an instruction in the Device Trace Viewer highlights the operators in the Hierarchy Viewer that contain it.
NKI kernel calls#
When a model calls NKI kernels, each kernel call appears in the Hierarchy Viewer as a node labeled [NKI_Kernel_Call], nested under the framework operator (or operators) it ran within. Right-click an NKI kernel node to highlight its instructions in the Device Trace Viewer. Clicking one of those instructions highlights the node.
NKI kernel nodes require NKI_DEBUG_INFO=True when you compile the model. Without it, the Hierarchy Viewer shows the framework operators but no NKI kernel nodes. See Source code and debug info.
This document is relevant for: Inf2, Trn1, Trn2, Trn3