Skip to content
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
38 changes: 38 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,21 @@
"rhs": "Darwin"
}
},
{
"name": "llm-debug-vulkan",
"displayName": "LLM debug build with Vulkan",
"inherits": [
"llm-debug"
],
"cacheVariables": {
"EXECUTORCH_BUILD_VULKAN": "ON"
},
"condition": {
"type": "inList",
"string": "${hostSystemName}",
"list": ["Linux", "Windows"]
}
},
{
"name": "llm-metal-stats",
"displayName": "LLM Metal build with stats collection and logging",
Expand Down Expand Up @@ -354,6 +369,15 @@
],
"jobs": 0
},
{
"name": "llm-debug-vulkan-install",
"displayName": "Build and install LLM extension debug artifacts (Vulkan)",
"configurePreset": "llm-debug-vulkan",
"targets": [
"install"
],
"jobs": 0
},
{
"name": "llm-metal-stats-install",
"displayName": "Build and install LLM extension artifacts with Metal stats",
Expand Down Expand Up @@ -449,6 +473,20 @@
}
]
},
{
"name": "llm-debug-vulkan",
"displayName": "Configure, build and install ExecuTorch LLM extension with Vulkan enabled (Debug)",
"steps": [
{
"type": "configure",
"name": "llm-debug-vulkan"
},
{
"type": "build",
"name": "llm-debug-vulkan-install"
}
]
},
{
"name": "llm-metal-stats",
"displayName": "Configure, build and install ExecuTorch LLM extension with Metal stats and logging",
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
#
# ==============================================================================

.PHONY: voxtral-cuda voxtral-cpu voxtral-metal voxtral_realtime-cuda voxtral_realtime-cpu voxtral_realtime-metal whisper-cuda whisper-cuda-debug whisper-cpu whisper-metal parakeet-cuda parakeet-cuda-debug parakeet-cpu parakeet-metal dinov2-cuda dinov2-cuda-debug sortformer-cuda sortformer-cpu silero-vad-cpu llama-cuda llama-cuda-debug llama-cpu llava-cpu gemma3-cuda gemma3-cpu clean help
.PHONY: voxtral-cuda voxtral-cpu voxtral-metal voxtral_realtime-cuda voxtral_realtime-cpu voxtral_realtime-metal whisper-cuda whisper-cuda-debug whisper-cpu whisper-metal parakeet-cuda parakeet-cuda-debug parakeet-cpu parakeet-metal parakeet-vulkan dinov2-cuda dinov2-cuda-debug sortformer-cuda sortformer-cpu silero-vad-cpu llama-cuda llama-cuda-debug llama-cpu llava-cpu gemma3-cuda gemma3-cpu clean help

help:
@echo "This Makefile adds targets to build runners for various models on various backends. Run using \`make <target>\`. Available targets:"
Expand All @@ -109,6 +109,7 @@ help:
@echo " parakeet-cuda-debug - Build Parakeet runner with CUDA backend (debug mode)"
@echo " parakeet-cpu - Build Parakeet runner with CPU backend"
@echo " parakeet-metal - Build Parakeet runner with Metal backend (macOS only)"
@echo " parakeet-vulkan - Build Parakeet runner with Vulkan backend"
@echo " dinov2-cuda - Build DINOv2 runner with CUDA backend"
@echo " dinov2-cuda-debug - Build DINOv2 runner with CUDA backend (debug mode)"
@echo " sortformer-cuda - Build Sortformer runner with CUDA backend"
Expand Down Expand Up @@ -221,6 +222,15 @@ parakeet-metal:
@echo "✓ Build complete!"
@echo " Binary: cmake-out/examples/models/parakeet/parakeet_runner"

parakeet-vulkan:
@echo "==> Building and installing ExecuTorch with Vulkan..."
cmake --workflow --preset llm-debug-vulkan
@echo "==> Building Parakeet runner with Vulkan..."
cd examples/models/parakeet && cmake --workflow --preset parakeet-vulkan
@echo ""
@echo "✓ Build complete!"
@echo " Binary: cmake-out/examples/models/parakeet/parakeet_runner"

dinov2-cuda:
@echo "==> Building and installing ExecuTorch with CUDA..."
cmake --workflow --preset llm-release-cuda
Expand Down
5 changes: 2 additions & 3 deletions backends/vulkan/custom_ops_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import executorch.backends.vulkan.patterns as vk_patterns
import torch.library

from torch._subclasses.fake_tensor import FakeTensor

namespace = "et_vk"
Expand Down Expand Up @@ -259,7 +258,7 @@ def linear_q4gsw(
weights, [1, group_size], weight_scales, weight_zeros, torch.int8, -8, 7
)

out = torch.nn.functional.linear(x, weights)
out = torch.nn.functional.linear(x, weights, bias)
return out


Expand All @@ -273,7 +272,7 @@ def linear_dq8ca_q4gsw(
group_size: int,
bias: Optional[torch.Tensor] = None,
):
return linear_q4gsw(x, weights, weight_scales, group_size)
return linear_q4gsw(x, weights, weight_scales, group_size, bias)


name = "linear_q4gsw"
Expand Down
69 changes: 54 additions & 15 deletions backends/vulkan/op_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def update_features_impl(op: OpKey):
torch.ops.aten.sym_size.int,
operator.add,
operator.sub,
operator.floordiv,
operator.mul,
operator.lt,
operator.gt,
operator.ge,
Expand Down Expand Up @@ -279,6 +281,26 @@ def register_bitwise_and():
)


@update_features(exir_ops.edge.aten.bitwise_not.default)
def register_bitwise_not():
return OpFeatures(
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.BOOL_T,
supports_resize=True,
supports_highdim=True,
)


@update_features(exir_ops.edge.aten.logical_and.default)
def register_logical_and():
return OpFeatures(
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.BOOL_T,
supports_resize=True,
supports_highdim=True,
)


# =============================================================================
# BinaryScalarOp.cpp
# =============================================================================
Expand All @@ -301,16 +323,22 @@ def register_pow_tensor_scalar():

@update_features(exir_ops.edge.aten._to_copy.default)
def register_to_copy():
def check_to_copy_node(node: torch.fx.Node) -> bool:
# Only single-arg _to_copy is supported
return len(node.args) == 1
def pick_to_copy_storage(
node: torch.fx.Node,
) -> Tuple[utils.TensorRepSet, utils.TensorRepSet]:
in_dtype = node.args[0].meta["val"].dtype # type: ignore[union-attr]
out_dtype = node.meta["val"].dtype
fp_types = {torch.float16, torch.float32}
if in_dtype in fp_types and out_dtype in fp_types:
return utils.ANY_STORAGE, utils.ANY_STORAGE
return utils.CONTIGUOUS_BUFFER, utils.CONTIGUOUS_BUFFER

return OpFeatures(
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_INT_T,
outputs_dtypes=utils.FP_INT_T,
inputs_dtypes=utils.FP_INT_BOOL_T,
outputs_dtypes=utils.FP_INT_BOOL_T,
supports_resize=True,
are_node_inputs_supported_fn=check_to_copy_node,
pick_io_storage_fn=pick_to_copy_storage,
)


Expand All @@ -327,7 +355,7 @@ def check_to_copy_node(node: torch.fx.Node) -> bool:
)
def register_softmax_cpp_ops():
return OpFeatures(
inputs_storage=utils.ANY_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_T,
supports_resize=True,
)
Expand Down Expand Up @@ -705,7 +733,7 @@ def register_reduce_cpp_ops():
)
def register_argreduce_cpp_ops():
return OpFeatures(
inputs_storage=utils.ANY_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_T,
outputs_dtypes=utils.INT_T,
supports_resize=True,
Expand Down Expand Up @@ -1120,7 +1148,7 @@ def register_gather():
@update_features(exir_ops.edge.aten.expand_copy.default)
def register_expand_copy():
return OpFeatures(
inputs_storage=utils.ANY_BUFFER,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_INT_BOOL_T,
supports_resize=False,
supports_highdim=True,
Expand Down Expand Up @@ -1285,7 +1313,7 @@ def check_index_tensor_node(node: torch.fx.Node) -> bool:
@update_features(exir_ops.edge.aten.arange.start_step)
def register_arange():
return OpFeatures(
inputs_storage=utils.CHANNELS_PACKED_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_INT_T,
)

Expand All @@ -1298,8 +1326,9 @@ def register_arange():
@update_features(exir_ops.edge.aten.constant_pad_nd.default)
def register_constant_pad_nd():
return OpFeatures(
inputs_storage=utils.CHANNELS_PACKED_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_INT_BOOL_T,
supports_resize=True,
)


Expand All @@ -1320,7 +1349,7 @@ def register_constant_pad_nd():
)
def register_full_cpp_ops():
return OpFeatures(
inputs_storage=utils.CHANNELS_PACKED_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_INT_BOOL_T,
)

Expand All @@ -1335,6 +1364,7 @@ def register_scalar_tensor():
return OpFeatures(
inputs_storage=utils.CHANNELS_PACKED_TEXTURE,
inputs_dtypes=utils.FP_INT_T,
supports_resize=True,
)


Expand Down Expand Up @@ -1377,7 +1407,7 @@ def register_grid_priors():
@update_features(exir_ops.edge.aten.repeat.default)
def register_repeat():
return OpFeatures(
inputs_storage=utils.ANY_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_INT_BOOL_T,
)

Expand All @@ -1389,11 +1419,20 @@ def register_repeat():

@update_features(exir_ops.edge.aten.embedding.default)
def register_embedding():
def check_embedding_weight_size(node: torch.fx.Node) -> bool:
weight = node.args[0]
if isinstance(weight, torch.fx.Node) and utils.is_tensor_node(weight):
numel = weight.meta["val"].numel()
if numel > utils.DEFAULT_BUFFER_LIMIT:
return False
return True

return OpFeatures(
inputs_storage=utils.CHANNELS_PACKED_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=[utils.FP_T, utils.INT_T],
supports_prepacking=True,
supports_resize=True,
are_node_inputs_supported_fn=check_embedding_weight_size,
)


Expand Down Expand Up @@ -1439,7 +1478,7 @@ def register_native_group_norm():
@update_features(exir_ops.edge.aten.native_layer_norm.default)
def register_native_layer_norm():
return OpFeatures(
inputs_storage=utils.ANY_TEXTURE,
inputs_storage=utils.ANY_STORAGE,
inputs_dtypes=utils.FP_T,
supports_prepacking=True,
supports_resize=True,
Expand Down
26 changes: 15 additions & 11 deletions backends/vulkan/patterns/quantized_linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,22 @@
# LICENSE file in the root directory of this source tree.

import operator

from typing import Optional

import executorch.backends.vulkan.utils as utils

import torch
import torch.nn.functional as F

from executorch.backends.transforms.utils import (
create_constant_placeholder,
get_param_tensor,
)

from executorch.backends.vulkan.patterns.pattern_registry import (
PatternMatch,
register_pattern_detector,
register_pattern_replacement,
)

from executorch.exir import ExportedProgram
from executorch.exir.dialects._ops import ops as exir_ops

from torch.export.graph_signature import InputKind


Expand Down Expand Up @@ -398,6 +392,12 @@ def make_linear_q4gsw_op(
force_update=True,
)

# Pad bias to multiple of 4 if present
if match.bias_node is not None:
bias_tensor = get_param_tensor(ep, match.bias_node)
if bias_tensor is not None:
utils.align_width_and_update_state_dict(ep, match.bias_node, bias_tensor)

with graph_module.graph.inserting_before(match.output_node):
linear_q4gsw_node = graph_module.graph.create_node(
"call_function",
Expand All @@ -407,6 +407,7 @@ def make_linear_q4gsw_op(
match.weight_node,
match.weight_scales_node,
group_size,
match.bias_node,
),
)

Expand Down Expand Up @@ -445,6 +446,12 @@ def make_linear_dq8ca_q4gsw_op(
force_update=True,
)

# Pad bias to multiple of 4 if present
if match.bias_node is not None:
bias_tensor = get_param_tensor(ep, match.bias_node)
if bias_tensor is not None:
utils.align_width_and_update_state_dict(ep, match.bias_node, bias_tensor)

first_graph_node = list(graph_module.graph.nodes)[0]
with graph_module.graph.inserting_before(first_graph_node):
weight_tensor_name = utils.get_tensor_name(ep, match.weight_node)
Expand Down Expand Up @@ -474,6 +481,7 @@ def make_linear_dq8ca_q4gsw_op(
weight_sums_node,
match.weight_scales_node,
group_size,
match.bias_node,
),
)

Expand Down Expand Up @@ -538,6 +546,7 @@ def make_linear_q8ta_q8csw_custom_op(
match.weight_node,
weight_sums_node,
match.weight_scales_node,
match.bias_node,
),
)

Expand Down Expand Up @@ -637,7 +646,6 @@ def replace_quantized_linear_patterns(
assert weight_zeros_tensor is not None

# Route to appropriate custom op.
# q8ta_linear supports bias, so check it first before the bias guard.
if (
match.is_input_static_per_tensor_quantized()
and match.is_weight_perchannel_quantized()
Expand All @@ -646,10 +654,6 @@ def replace_quantized_linear_patterns(
make_q8ta_linear_custom_op(ep, graph_module, match, weight_tensor)
return

# Remaining ops do not support bias
if match.bias_node is not None:
return

if (
match.is_weight_only_quantized()
and match.is_weight_pergroup_quantized()
Expand Down
Loading
Loading