Skip to content

[ET-VK][ez] Fix handling of assert ops #11349

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

Merged
merged 5 commits into from
Jun 4, 2025
Merged
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
5 changes: 4 additions & 1 deletion backends/vulkan/_passes/fuse_quantized_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from executorch.exir import ExportedProgram
from executorch.exir.dialects._ops import ops as exir_ops
from executorch.exir.pass_base import ExportPass, PassResult
from executorch.exir.passes import dead_code_elimination_pass

#################
## linear_qcnw ##
Expand Down Expand Up @@ -224,6 +225,8 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
)

graph_module.recompile()
graph_module = super().call(graph_module).graph_module
dead_code_elimination_pass(graph_module)

# Re-trace the graph since new nodes were (potentially) inserted
graph_module = super().call(graph_module).graph_module
return PassResult(graph_module, True)
7 changes: 7 additions & 0 deletions backends/vulkan/op_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,13 @@ def update_features_impl(op: OpKey):
# Symbolic integer ops
torch.ops.aten.sym_size.int,
operator.add,
operator.lt,
operator.gt,
operator.ge,
operator.le,
# Guard and assert ops
torch.ops.aten._assert_scalar.default,
torch.ops.aten.sym_constrain_range_for_size.default,
]
)
def register_ephemeral_op(features: OpFeatures):
Expand Down
7 changes: 4 additions & 3 deletions backends/vulkan/partitioner/vulkan_partitioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,11 @@ def op_node_is_compatible( # noqa: C901: Function is too complex
def node_is_compatible(
self, node: torch.fx.Node, features: Optional[OpFeatures] = None
) -> Tuple[bool, str]:
if utils.is_symint_node(node):
return node.target in vulkan_supported_ops, "Op is compatible"
elif utils.is_tensor_node(node):
if utils.is_tensor_node(node):
return self.op_node_is_compatible(node, features=features)
# For non-tensor nodes, just check if the op is registered
elif hasattr(node, "target"):
return node.target in vulkan_supported_ops, "Op is compatible"

return False, f"Unsupported node type: {node.format_node()}"

Expand Down
2 changes: 2 additions & 0 deletions backends/vulkan/vulkan_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
SqueezeUnsqueezeInputs,
TagMemoryMetaPass,
)
from executorch.backends.vulkan._passes.remove_asserts import RemoveAssertsTransform

from executorch.backends.vulkan.serialization.vulkan_graph_builder import VkGraphBuilder
from executorch.backends.vulkan.serialization.vulkan_graph_schema import (
Expand Down Expand Up @@ -172,6 +173,7 @@ def preprocess( # noqa: C901
program = apply_passes(
program,
[
RemoveAssertsTransform(),
# Since this pass may replace a scalar argument with a tensor argument,
# this pass may result in a non ATen compliant graph structure.
RemoveLocalScalarDenseOpsTransform(),
Expand Down
1 change: 0 additions & 1 deletion examples/models/llama/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ runtime.python_library(
":source_transformation",
"//ai_codesign/gen_ai/fast_hadamard_transform:fast_hadamard_transform",
"//caffe2:torch",
"//executorch/backends/vulkan/_passes:vulkan_passes",
"//executorch/exir/passes:init_mutable_pass",
"//executorch/examples/models:model_base",
"//executorch/examples/models:models",
Expand Down
4 changes: 0 additions & 4 deletions examples/models/llama/export_llama_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pkg_resources
import torch

from executorch.backends.vulkan._passes.remove_asserts import remove_asserts
from executorch.devtools.backend_debug import print_delegation_info

from executorch.devtools.etrecord import generate_etrecord as generate_etrecord_func
Expand Down Expand Up @@ -880,9 +879,6 @@ def _to_edge_and_lower_llama( # noqa: C901
)
modelname = f"vulkan_{modelname}"

# Need to remove asserts from the graph to prevent graph breaks
remove_asserts(builder_exported_to_edge.edge_manager.exported_program())

if mps:
partitioners.append(get_mps_partitioner(use_kv_cache))
modelname = f"mps_{modelname}"
Expand Down
Loading