Skip to content

Move undelegated constants #13606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/models/llama/export_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@ def _export_llama(llm_config: LlmConfig) -> LLMEdgeManager: # noqa: C901

from executorch.exir.passes.external_constants_pass import (
delegate_external_constants_pass_unlifted,
external_constants_pass,
)

assert (
Expand All @@ -1096,6 +1097,11 @@ def _export_llama(llm_config: LlmConfig) -> LLMEdgeManager: # noqa: C901
gen_tag_fn=gen_tag_fn,
)

# Also add a pass for 'to_executorch' to tag weights that aren't delegated.
additional_passes.append(
partial(external_constants_pass, gen_tag_fn=gen_tag_fn)
)

builder = _to_edge_and_lower_llama_xnnpack(
builder_exported,
modelname,
Expand Down
6 changes: 5 additions & 1 deletion exir/passes/external_constants_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def is_param_node(exp_prog: ExportedProgram, node: torch.fx.Node) -> bool:

def external_constants_pass(
gm: GraphModule,
gen_tag_fn: Optional[Callable[[torch.fx.Node], Optional[str]]] = None,
) -> PassResult:
"""
Move all non-lifted constants to external file.
Expand All @@ -42,7 +43,10 @@ def external_constants_pass(
if (node.op == "placeholder") and ("_lifted_tensor" not in node.name):
spec = node.meta.get("spec")
if isinstance(spec, TensorSpec) and spec.const:
node.meta["constant_tag"] = "_default_external_constant"
if gen_tag_fn is not None:
node.meta["constant_tag"] = gen_tag_fn(node)
else:
node.meta["constant_tag"] = "_default_external_constant"
mutated = True
return PassResult(gm, mutated)

Expand Down
2 changes: 1 addition & 1 deletion exir/program/_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,13 +808,13 @@ def edge_to_executorch_passes(
Get the pre memory planning passes based on the method name, if the pass is not in the dict, use the default pass.
"""
passes: List[PassType] = [
*config.passes,
SpecPropPass(),
# ExecuTorch backend ops are unable to handle unbacked symints. So after
# this pass, passes cannot be Interpreter-based, because it will fail if
# there exists an unbacked symint operation.
EdgeToBackendOpsPass(),
RemoveGraphAssertsPass(),
*config.passes,
Copy link
Contributor Author

@lucylq lucylq Aug 22, 2025

Choose a reason for hiding this comment

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

external_constants_pass has to run after SpecPropPass, which populates the tensor names. See if CI passes, not sure if this will break anything.

] + pre_memory_planning_passes(config, name)

return passes
Expand Down
Loading