Skip to content

View on edges -> Tensor shape #669

Closed

Description

@simplew2011

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
        break

This 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:

  1. Single-output ops with multiple consumers (torch.cat → two downstream nodes)
  2. Multi-output ops (torch.chunk → returns tuple)

Both scenarios now produce correct sourceNodeOutputId values.

Image

test_new.json
test_old.json

Activity

  1. simplew2011 commented on Jun 22, 2026

    @simplew2011
    Author

    src/server/package/src/model_explorer/pytorch_exported_program_adater_impl.py#L138
    Image

  2. self-assigned this
    on Jun 23, 2026
  3. added
    bug
    stat:contribution welcome
    on Jun 25, 2026
  4. shivvaam0001 commented on Jun 26, 2026

    @shivvaam0001
    Collaborator

    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!

  5. added
    status:awaiting user response
    on Jun 29, 2026
  6. github-actions commented on Jul 7, 2026

    @github-actions

    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.

  7. added
    status:stale
    on Jul 7, 2026
  8. github-actions commented on Jul 15, 2026

    @github-actions

    This issue was closed because it has been inactive for 14 days. Please post a new issue if you need further assistance. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugstat:contribution welcomestatus:awaiting user responsestatus:stale

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions