Skip to content

Commit ab7a616

Browse files
[executorch][native-vk] Lower q4 linears over directly quantized weights (pytorch#23473)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: pytorch#23439 by @digantdesai ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/digantdesai/133/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/digantdesai/133/head Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/digantdesai/132/orig Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/digantdesai/133/orig Differential Revision: [D121704330](https://our.internmc.facebook.com/intern/diff/D121704330/) @diff-train-skip-merge Co-authored-by: Digant Desai <digantdesai@meta.com>
1 parent d1b868e commit ab7a616

5 files changed

Lines changed: 720 additions & 240 deletions

File tree

‎backends/native/runtime/vulkan/VulkanEngineExecutable.cpp‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,14 @@ bool is_functional_in_place(const std::string& target) {
176176
// Ops whose ET-VK implementations require width-packed operands. This list
177177
// seeds layout assignment; propagation below determines the final layouts.
178178
bool is_width_packed_op(std::string_view key) {
179-
constexpr std::array<std::string_view, 10> kOps{
179+
constexpr std::array<std::string_view, 11> kOps{
180180
"aten.linear.default",
181181
"aten.addmm.default",
182182
"aten.mm.default",
183183
"aten.bmm.default",
184184
"et_vk.apply_rotary_emb_hf.default",
185185
"et_vk.linear_dq8ca_q4gsw.default",
186+
"et_vk.linear_q4gsw.default",
186187
"et_vk.rms_norm.default",
187188
"llama.custom_sdpa.default",
188189
"update_cache.default",
@@ -862,6 +863,11 @@ class VulkanEngineExecutable final : public EngineExecutable {
862863
const Package& package,
863864
const DataBinding& b,
864865
const Value& v) {
866+
if (v.tensor_meta().quant.has_value()) {
867+
throw std::runtime_error(
868+
"vulkan: quantized constant '" + b.key +
869+
"' is read by an op the Vulkan engine does not lower");
870+
}
865871
const std::optional<ConstantInfo> info = package.constant_info(b.key);
866872
if (!info) {
867873
throw std::runtime_error(
@@ -961,6 +967,9 @@ class VulkanEngineExecutable final : public EngineExecutable {
961967
}
962968

963969
void validate_zero_points(const Package& package, ValueId zero_points_id) {
970+
if (!valid(zero_points_id)) {
971+
return;
972+
}
964973
validate_zero_constant(package, zero_points_id, "q4 weight zero points");
965974
}
966975

@@ -1480,6 +1489,7 @@ class VulkanEngineExecutable final : public EngineExecutable {
14801489
std::optional<utils::StorageType> activation_storage;
14811490
if (key == "aten.linear.default" ||
14821491
key == "et_vk.linear_dq8ca_q4gsw.default" ||
1492+
key == "et_vk.linear_q4gsw.default" ||
14831493
key == "et_vk.apply_rotary_emb_hf.default") {
14841494
const auto output =
14851495
std::ranges::find_if(n.outputs, [this](const Output& candidate) {

0 commit comments

Comments
 (0)