Skip to content

Fix constant_prop_pass fqn collision with state_dict (#23266) - #23266

Open
pcwu0329 wants to merge 1 commit into
pytorch:mainfrom
pcwu0329:export-D122298673
Open

pcwu0329 wants to merge 1 commit into
pytorch:mainfrom
pcwu0329:export-D122298673

Conversation

@pcwu0329

@pcwu0329 pcwu0329 commented Sep 29, 2026 •

Copy link
Copy Markdown

Summary:

replace_with_constant_node names propagated constants
_prop_tensor_constant{len(exported_program.constants)}, then checks for a
collision. Both the check and the max-suffix rescan look only at
exported_program.constants.

A program re-entering this pass can already carry a _prop_tensor_constant* in
exported_program.state_dict from an earlier run. That name is invisible to
both, so the pass reuses it and writes its tensor into constants alongside the
stale state_dict entry. Emission then resolves the placeholder against
state_dict before constants (exir/emit/_emitter.py:2044), picks up the
stale tensor, and fails the size check at _emitter.py:513:

InternalError: Tensor spec has buffer of size 48, but expected nbytes of 4

The spec is correct at 4 bytes; the tensor bound to it is the wrong one. Note
the existing comment already reads "If prop_constant_tensor_fqn already exists
in the state dict" -- the implementation never matched that intent.

Widen the collision check and the suffix rescan to span state_dict as well as
constants.

Observed on a Turing/Coleman hand-tracking model compiled with
fx_options.allow_quant_dequant_on_tce=True, which folds a scalar 1 from a
1 - valid_multi_view expression whose name was already taken in state_dict.
Instrumenting the pass showed the collision directly:

fqn=_prop_tensor_constant20 new_nbytes=4
already_in_constants=False already_in_state_dict=True

With the fix the model compiles to a .pte (3 TCE delegates, 84.19% delegation);
without it emission aborts.

Differential Revision: D122298673

@pytorch-bot

pytorch-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 0fe4ca4 with merge base 273cb33 (image):

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.

@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 Sep 29, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: pcwu0329 / name: Po-Chen Wu (a0df710)

@meta-codesync

meta-codesync Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

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

@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.

@meta-codesync meta-codesync Bot changed the title Fix constant_prop_pass fqn collision with state_dict Fix constant_prop_pass fqn collision with state_dict (#23266) Sep 30, 2026
pcwu0329 added a commit to pcwu0329/executorch that referenced this pull request Sep 30, 2026
Summary:

`replace_with_constant_node` names propagated constants
`_prop_tensor_constant{len(exported_program.constants)}`, then checks for a
collision. Both the check and the max-suffix rescan look only at
`exported_program.constants`.

A program re-entering this pass can already carry a `_prop_tensor_constant*` in
`exported_program.state_dict` from an earlier run. That name is invisible to
both, so the pass reuses it and writes its tensor into `constants` alongside the
stale `state_dict` entry. Emission then resolves the placeholder against
`state_dict` before `constants` (`exir/emit/_emitter.py:2044`), picks up the
stale tensor, and fails the size check at `_emitter.py:513`:

  InternalError: Tensor spec has buffer of size 48, but expected nbytes of 4

The spec is correct at 4 bytes; the tensor bound to it is the wrong one. Note
the existing comment already reads "If prop_constant_tensor_fqn already exists
in the state dict" -- the implementation never matched that intent.

Widen the collision check and the suffix rescan to span `state_dict` as well as
`constants`.

Observed on a Turing/Coleman hand-tracking model compiled with
`fx_options.allow_quant_dequant_on_tce=True`, which folds a scalar `1` from a
`1 - valid_multi_view` expression whose name was already taken in `state_dict`.
Instrumenting the pass showed the collision directly:

  fqn=_prop_tensor_constant20 new_nbytes=4
  already_in_constants=False already_in_state_dict=True

With the fix the model compiles to a .pte (3 TCE delegates, 84.19% delegation);
without it emission aborts.

Differential Revision: D122298673
pcwu0329 added a commit to pcwu0329/executorch that referenced this pull request Sep 30, 2026
Summary:

`replace_with_constant_node` names propagated constants
`_prop_tensor_constant{len(exported_program.constants)}`, then checks for a
collision. Both the check and the max-suffix rescan look only at
`exported_program.constants`.

A program re-entering this pass can already carry a `_prop_tensor_constant*` in
`exported_program.state_dict` from an earlier run. That name is invisible to
both, so the pass reuses it and writes its tensor into `constants` alongside the
stale `state_dict` entry. Emission then resolves the placeholder against
`state_dict` before `constants` (`exir/emit/_emitter.py:2044`), picks up the
stale tensor, and fails the size check at `_emitter.py:513`:

  InternalError: Tensor spec has buffer of size 48, but expected nbytes of 4

The spec is correct at 4 bytes; the tensor bound to it is the wrong one. Note
the existing comment already reads "If prop_constant_tensor_fqn already exists
in the state dict" -- the implementation never matched that intent.

Widen the collision check and the suffix rescan to span `state_dict` as well as
`constants`.

Observed on a Turing/Coleman hand-tracking model compiled with
`fx_options.allow_quant_dequant_on_tce=True`, which folds a scalar `1` from a
`1 - valid_multi_view` expression whose name was already taken in `state_dict`.
Instrumenting the pass showed the collision directly:

  fqn=_prop_tensor_constant20 new_nbytes=4
  already_in_constants=False already_in_state_dict=True

With the fix the model compiles to a .pte (3 TCE delegates, 84.19% delegation);
without it emission aborts.

Differential Revision: D122298673
Summary:
Pull Request resolved: pytorch#23266

`replace_with_constant_node` names propagated constants
`_prop_tensor_constant{len(exported_program.constants)}`, then checks for a
collision. Both the check and the max-suffix rescan look only at
`exported_program.constants`.

A program re-entering this pass can already carry a `_prop_tensor_constant*` in
`exported_program.state_dict` from an earlier run. That name is invisible to
both, so the pass reuses it and writes its tensor into `constants` alongside the
stale `state_dict` entry. Emission then resolves the placeholder against
`state_dict` before `constants` (`exir/emit/_emitter.py:2044`), picks up the
stale tensor, and fails the size check at `_emitter.py:513`:

  InternalError: Tensor spec has buffer of size 48, but expected nbytes of 4

The spec is correct at 4 bytes; the tensor bound to it is the wrong one. Note
the existing comment already reads "If prop_constant_tensor_fqn already exists
in the state dict" -- the implementation never matched that intent.

Widen the collision check and the suffix rescan to span `state_dict` as well as
`constants`.

Observed on a Turing/Coleman hand-tracking model compiled with
`fx_options.allow_quant_dequant_on_tce=True`, which folds a scalar `1` from a
`1 - valid_multi_view` expression whose name was already taken in `state_dict`.
Instrumenting the pass showed the collision directly:

  fqn=_prop_tensor_constant20 new_nbytes=4
  already_in_constants=False already_in_state_dict=True

With the fix the model compiles to a .pte (3 TCE delegates, 84.19% delegation);
without it emission aborts.

Differential Revision: D122298673

This branch has not been deployed

No deployments
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.

1 participant