Skip to content

Fix tensor name/type disagreement on multi-output nodes - #22319

Open
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:export-D118035167
Open

Fix tensor name/type disagreement on multi-output nodes#22319
psiddh wants to merge 1 commit into
pytorch:mainfrom
psiddh:export-D118035167

Conversation

@psiddh

@psiddh psiddh commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary:
define_tensor decides twice whether the tensor it is defining is a graph
output: once for the tensor name (get_tensor_name -> is_graph_output, which
prefixes output_) and once for the tensor type (get_tensor_type ->
is_graph_output, which returns QNN_TENSOR_TYPE_APP_READ). Since
is_graph_output gained an output_index parameter, only the type path has been
passing it:

output_index = wrapper_idx if tensor_source_node is target_build_node else None

The name path still passed the raw wrapper_idx. wrapper_idx only indexes a
node's own outputs when the tensor being defined belongs to that node; builders
also use it to key scratch tensors sourced from some other node (see
op_scatter_elements), where it carries no output meaning. For a non-owner
multi-output source node at a partition boundary the two paths therefore answer
differently: the tensor gets an output_-prefixed name while its type stays
NATIVE, or gets APP_READ without the name the runtime expects. QNN graph
construction then fails, and because it depends on partitioning order it fails
intermittently -- this is the flake in test-qnn-testsuite-linux /
test-backend-linux (qnn, models).

This computes output_index once and feeds it to both paths, so naming and
typing can no longer disagree. get_tensor_name takes output_index as a new
optional argument that defaults to None, preserving the behavior of any
external caller that does not pass it.

The fbcode/ and xplat/ copies of node_visitor.py are byte-identical
mirrors, so both are updated.

Authored with AI assistance (Claude Code).

Differential Revision: D118035167

Summary:
`define_tensor` decides twice whether the tensor it is defining is a graph
output: once for the tensor *name* (`get_tensor_name` -> `is_graph_output`, which
prefixes `output_`) and once for the tensor *type* (`get_tensor_type` ->
`is_graph_output`, which returns `QNN_TENSOR_TYPE_APP_READ`). Since
`is_graph_output` gained an `output_index` parameter, only the type path has been
passing it:

    output_index = wrapper_idx if tensor_source_node is target_build_node else None

The name path still passed the raw `wrapper_idx`. `wrapper_idx` only indexes a
node's own outputs when the tensor being defined belongs to that node; builders
also use it to key scratch tensors sourced from some *other* node (see
`op_scatter_elements`), where it carries no output meaning. For a non-owner
multi-output source node at a partition boundary the two paths therefore answer
differently: the tensor gets an `output_`-prefixed name while its type stays
NATIVE, or gets APP_READ without the name the runtime expects. QNN graph
construction then fails, and because it depends on partitioning order it fails
intermittently -- this is the flake in `test-qnn-testsuite-linux` /
`test-backend-linux (qnn, models)`.

This computes `output_index` once and feeds it to both paths, so naming and
typing can no longer disagree. `get_tensor_name` takes `output_index` as a new
optional argument that defaults to `None`, preserving the behavior of any
external caller that does not pass it.

The `fbcode/` and `xplat/` copies of `node_visitor.py` are byte-identical
mirrors, so both are updated.

Authored with AI assistance (Claude Code).

Differential Revision: D118035167
Copilot AI lite review requested due to automatic review settings August 30, 2026 07:36
@pytorch-bot

pytorch-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22319

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 1 Unrelated Failure

As of commit f9e248a with merge base c27baa8 (image):

NEW FAILURES - The following jobs have failed:

  • Cadence Build & Test / hifi-build / hifi4 (gh)
    ##[error]Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.
  • Cadence Build & Test / vision-build / vision (gh)
    ##[error]Refusing to check out fork pull request code from a 'pull_request_target' workflow. This workflow runs with the base repository's GITHUB_TOKEN, secrets, default-branch cache scope, and runner access. Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities. To opt in, review the risks at https://gh.io/securely-using-pull_request_target and set 'allow-unsafe-pr-checkout: true' on the actions/checkout step.

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 30, 2026
@meta-codesync

meta-codesync Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

@psiddh has exported this pull request. If you are a Meta employee, you can view the originating Diff in D118035167.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

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

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants