Repository navigation
Commit 29557f1
authored
Fix constant_prop_pass fqn collision with state_dict (pytorch#23266)
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
Pull Request resolved: pytorch#232661 parent d67aa29 commit 29557f1
2 files changed
Lines changed: 34 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
217 | 223 | | |
218 | 224 | | |
219 | 225 | | |
220 | | - | |
| 226 | + | |
221 | 227 | | |
222 | 228 | | |
223 | 229 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1690 | 1690 | | |
1691 | 1691 | | |
1692 | 1692 | | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
1693 | 1719 | | |
1694 | 1720 | | |
1695 | 1721 | | |
| |||
0 commit comments