Repository navigation
Description
Fix: Incorrect sourceNodeOutputId for single-output ops with multiple consumers
Problem
When visualizing PyTorch models in Model Explorer, some edges display ? instead of the correct tensor shape, even though the source node has valid outputsMetadata.
Example:
cat.output[1] → sin ❌ (shows "?" on edge)
cos ← cat.output[0] ✅ (shows correct shape)
The cat node only has one output (output[0]), but the edge to sin incorrectly references output[1].
Root Cause
The issue is in pytorch_exported_program_adater_impl.py:add_incoming_edges():
# Current implementation (buggy)
for idx, user in enumerate(input_fx_node.users):
if user == fx_node:
source_node_output_id = str(idx) # ← Uses users list index as output ID
breakThis logic incorrectly uses the index in the users list as the sourceNodeOutputId. For single-output operations (like torch.cat) that are consumed by multiple downstream nodes:
cat.users = ['mul', 'mul_1'] # cat consumed by two operations
Processing mul: idx=0 → sourceNodeOutputId='0' ✓
Processing mul_1: idx=1 → sourceNodeOutputId='1' ✗ (wrong!)
The cat operation only produces a single output tensor, so outputsMetadata only contains id: "0". When the edge references output[1], the frontend cannot find matching metadata and displays ?.
Solution
Only use the users list index as sourceNodeOutputId when the source node actually has multiple outputs (i.e., when meta['val'] is a tuple/list):
def add_incoming_edges(self, fx_node: torch.fx.node.Node, node: GraphNode):
for target_input_id, input_fx_node in enumerate(fx_node.all_input_nodes):
source_node_output_id = '0' # default to the first output
# Only use users index as output ID when source node has multiple outputs
# (i.e., when meta['val'] is a tuple/list).
# For single-output ops (like torch.cat), always use '0'.
out_val = input_fx_node.meta.get('val')
has_multiple_outputs = isinstance(out_val, (tuple, list))
if has_multiple_outputs:
for idx, user in enumerate(input_fx_node.users):
if user == fx_node:
source_node_output_id = str(idx)
break
node.incomingEdges.append(
IncomingEdge(
sourceNodeId=input_fx_node.name,
sourceNodeOutputId=source_node_output_id,
targetNodeInputId=str(target_input_id),
)
)Behavior Summary
| Scenario | meta['val'] type |
has_multiple_outputs |
sourceNodeOutputId |
|---|---|---|---|
| Single-output op (cat, mul, etc.) | FakeTensor |
False |
Always '0' |
| Multi-output op (chunk, etc.) | tuple/list |
True |
Uses users index |
Impact
- Affected classes:
PytorchExportedProgramAdapterImpl,PytorchEnhanceAdapterImpl - Not affected: Other adapters (TFLite, TF, MLIR, etc.)
- Risk: Low - only changes behavior for single-output ops that were previously incorrect
Testing
Verified with:
- Single-output ops with multiple consumers (torch.cat → two downstream nodes)
- Multi-output ops (torch.chunk → returns tuple)
Both scenarios now produce correct sourceNodeOutputId values.
Activity
simplew2011 commentedon Jun 22, 2026
src/server/package/src/model_explorer/pytorch_exported_program_adater_impl.py#L138

shivvaam0001 commentedon Jun 26, 2026
Hi @simplew2011
Thanks for the detailed analysis and proposed fix. If you have already implemented and verified the solution, could you please open a PR with the changes? That would make it easier for us to review and discuss the implementation.
Thanks!
github-actions commentedon Jul 7, 2026
Marking this issue as stale since it has been open for 7 days with no activity. This issue will be closed if no further activity occurs.
github-actions commentedon Jul 15, 2026
This issue was closed because it has been inactive for 14 days. Please post a new issue if you need further assistance. Thanks!