pytorch / pytorch/executorch

Performance - No constant folding/propagation happens on final .pte

Open
#8,446 11 comments 1 reaction 1 assignee View on GitHub

@tarun292 is already working on this.

Since Feb 13, 2025.

module: exir triaged
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

🐛 Describe the bug

After exporting a model with torch.export.export, to_edge_ and even applying several passes to propagate/fold constants, the final .pte still containing several nodes operating only on constants.

I find, specifically, nodes like:

t1 = aten::add(const, const, const)
t2 = aten::mul(t1, const)
t3 = aten::permute_copy(t2)
t4 = aten::unsqueeze_copy(t3)

t5 = aten::add(const, const, const)
t6 = aten::mul(t5, const)
t7 = aten::permute_copy(t6)

t8 = aten::index(tensor, t4, t7)

Why all these operations are not folded even when applying the passes?

This is how I exported and applied the passes:

from executorch.exir.passes.constant_prop_pass import constant_prop_pass
from executorch.exir.passes.const_prop_pass import ConstPropPass
from executorch import exir

self.model.eval()
aten_dialect_program = torch.export.export(self.model, (self.input,))
aten_dialect_program = constant_prop_pass(aten_dialect_program)
edge_dialect_program = exir.to_edge_transform_and_lower(aten_dialect_program, transform_passes=[ConstPropPass()])
executorch_program = edge_dialect_program.to_executorch(
    exir.ExecutorchBackendConfig(
        passes=[]
    )
)

Is there a way of making sure no constants are operations are left on the final .pte before inference? For performance reasons.

Versions
Versions of relevant libraries:
[pip3] executorch==0.6.0a0+4e3a8bd
[pip3] numpy==2.0.0
[pip3] torch==2.7.0.dev20250131+cpu
[pip3] torchao==0.8.0+git11333ba2
[pip3] torchaudio==2.6.0.dev20250131+cpu
[pip3] torchsr==1.0.4
[pip3] torchvision==0.22.0.dev20250131+cpu

cc @JacobSzwejbka @angelayi

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.