Skip to content

Commit 19ff441

Browse files
[executorch][native-vk] Reconcile storage around unquantized linear, view and embedding (pytorch#23468)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: pytorch#23433 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/128/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/digantdesai/128/head Merge bot PR base: https://github.com/pytorch/executorch/tree/gh/digantdesai/127/orig Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/digantdesai/128/orig Differential Revision: [D121864326](https://our.internmc.facebook.com/intern/diff/D121864326/) @diff-train-skip-merge Co-authored-by: Digant Desai <digantdesai@meta.com>
1 parent cbdaae1 commit 19ff441

1 file changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,8 @@ class VulkanEngineExecutable final : public EngineExecutable {
13371337
}
13381338
const bool width = is_width_packed_op(key);
13391339
std::optional<utils::StorageType> activation_storage;
1340-
if (key == "et_vk.linear_dq8ca_q4gsw.default") {
1340+
if (key == "aten.linear.default" ||
1341+
key == "et_vk.linear_dq8ca_q4gsw.default") {
13411342
const auto output =
13421343
std::ranges::find_if(n.outputs, [this](const Output& candidate) {
13431344
return valid(candidate.value_id) &&
@@ -1373,6 +1374,25 @@ class VulkanEngineExecutable final : public EngineExecutable {
13731374
}
13741375
}
13751376
}
1377+
// ET-VK's view_copy shaders read and write one storage type.
1378+
if (key == "aten.view_copy.default" && na.name == "self" &&
1379+
na.arg.kind() == ArgKind::Tensor) {
1380+
const ValueId in_id = na.arg.as_tensor().id;
1381+
ValueId out_id = kInvalid;
1382+
for_each_output_value(n, [&](ValueId id) { out_id = id; });
1383+
if (valid(in_id) && valid(out_id) &&
1384+
storage_at(in_id) != storage_at(out_id)) {
1385+
const Value& v = g().value(in_id);
1386+
const VkRef dst = graph_->add_tensor(
1387+
v.tensor_meta().sizes,
1388+
to_vk_dtype(device_dtype(v.tensor_meta().dtype)),
1389+
storage_at(out_id),
1390+
layout_at(in_id));
1391+
std::vector<VkRef> clone_args = {a, none_ref_, dst};
1392+
VK_GET_OP_FN("aten.clone.default")(*graph_, clone_args);
1393+
a = dst;
1394+
}
1395+
}
13761396
args.push_back(a);
13771397
}
13781398

@@ -1382,6 +1402,20 @@ class VulkanEngineExecutable final : public EngineExecutable {
13821402
std::vector<VkRef> outs;
13831403
for_each_output_value(
13841404
n, [&](ValueId output_id) { outs.push_back(vref_at(output_id)); });
1405+
// ET-VK's embedding only writes channels-packed outputs.
1406+
if (key == "aten.embedding.default" && outs.size() == 1 &&
1407+
graph_->packed_dim_of(outs[0]) != vkcompute::WHCN::kChannelsDim) {
1408+
const VkRef tmp = graph_->add_tensor(
1409+
graph_->sizes_of(outs[0]),
1410+
graph_->dtype_of(outs[0]),
1411+
graph_->storage_type_of(outs[0]),
1412+
utils::kChannelsPacked);
1413+
args.push_back(tmp);
1414+
VK_GET_OP_FN(key)(*graph_, args);
1415+
std::vector<VkRef> clone_args = {tmp, none_ref_, outs[0]};
1416+
VK_GET_OP_FN("aten.clone.default")(*graph_, clone_args);
1417+
return;
1418+
}
13851419
const bool returns_list =
13861420
std::ranges::any_of(n.outputs, [](const Output& output) {
13871421
return output.kind == OutputValueKind::TensorList;

0 commit comments

Comments
 (0)