Skip to content

Commit dee69c9

Browse files
lucylqfacebook-github-bot
authored andcommitted
Move user-defined passes after SpecPropPass
Summary: 1. Use `ExecutorchBackendConfig` instead of inserting the pass. 2. Move SpecPropPass after user-defined passes. It was originally swapped here: D80840528. cc ethansfng, who has a pass that should run before SpecPropPass Differential Revision: D87576772
1 parent 4614144 commit dee69c9

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

examples/models/llama/export_llama_lib.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,6 @@ def _to_edge_and_lower_llama_xnnpack(
895895
if gen_tag_fn is not None:
896896
from executorch.exir.passes.external_constants_pass import (
897897
delegate_external_constants_pass_unlifted,
898-
external_constants_pass,
899898
)
900899

901900
assert (
@@ -906,18 +905,12 @@ def _to_edge_and_lower_llama_xnnpack(
906905
gen_tag_fn=gen_tag_fn,
907906
)
908907

909-
# Also add a pass for 'to_executorch' to tag weights that aren't delegated.
910-
additional_passes.append(
911-
partial(external_constants_pass, gen_tag_fn=gen_tag_fn)
912-
)
913-
914908
builder = builder.to_edge_transform_and_lower(partitioners)
915909
if verbose:
916910
print_delegation_info(builder.edge_manager.exported_program().graph_module)
917911

918-
# we need builder.export_program
919-
920-
return builder.to_executorch(passes=additional_passes)
912+
# Add gen_tag_fn to tag non-delegated weights as well.
913+
return builder.to_executorch(passes=additional_passes, external_constants_tag=gen_tag_fn)
921914

922915

923916
def _to_edge_and_lower_llama_openvino(

exir/program/_program.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -839,13 +839,11 @@ def edge_to_executorch_passes(
839839
Get the pre memory planning passes based on the method name, if the pass is not in the dict, use the default pass.
840840
"""
841841
passes: List[PassType] = [
842-
SpecPropPass(),
843842
# ExecuTorch backend ops are unable to handle unbacked symints. So after
844843
# this pass, passes cannot be Interpreter-based, because it will fail if
845844
# there exists an unbacked symint operation.
846845
*config.passes,
847-
# config.passes may contain external_constants_pass. This pass has to
848-
# run after SpecPropPass, which populates tensor names.
846+
SpecPropPass(),
849847
EdgeToBackendOpsPass(),
850848
RemoveGraphAssertsPass(),
851849
] + pre_memory_planning_passes(config, name)

extension/llm/export/builder.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,9 @@ def to_edge_transform_and_lower(
473473
return self
474474

475475
def to_executorch(
476-
self, passes: Optional[List[ExportPass]] = None
476+
self,
477+
passes: Optional[List[ExportPass]] = None,
478+
external_constants_tag: Optional[Callable[[torch.fx.Node], Optional[str]]] = None,
477479
) -> "LLMEdgeManager":
478480
"""
479481
Lower the model to executorch and get an ExecutorchProgram.
@@ -506,6 +508,7 @@ def to_executorch(
506508
do_quant_fusion_and_const_prop=True,
507509
memory_planning_pass=MemoryPlanningPass(alloc_graph_input=False),
508510
sym_shape_eval_pass=ConstraintBasedSymShapeEvalPass(),
511+
external_constants=external_constants_tag,
509512
)
510513
)
511514
logging.info(

0 commit comments

Comments
 (0)