Skip to content

Commit 3ed223f

Browse files
committed
Update
[ghstack-poisoned]
1 parent fc322db commit 3ed223f

6 files changed

Lines changed: 30 additions & 30 deletions

File tree

backends/vulkan/custom_ops_lib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,25 +1154,25 @@ def rms_norm_impl(
11541154

11551155

11561156
# STE weight gradient d_out^T @ x through the frozen 4-bit linear_q4gsw base.
1157-
def linear_q4gsw_dW_impl(
1157+
def linear_dW_impl(
11581158
d_out: torch.Tensor,
11591159
x: torch.Tensor,
11601160
) -> torch.Tensor:
11611161
return d_out.reshape(-1, d_out.shape[-1]).t() @ x.reshape(-1, x.shape[-1])
11621162

11631163

1164-
def linear_q4gsw_dW_meta(
1164+
def linear_dW_meta(
11651165
d_out: torch.Tensor,
11661166
x: torch.Tensor,
11671167
) -> torch.Tensor:
11681168
return d_out.new_empty((d_out.shape[-1], x.shape[-1]))
11691169

11701170

1171-
name = "linear_q4gsw_dW"
1171+
name = "linear_dW"
11721172
lib.define(f"{name}(Tensor d_out, Tensor x) -> Tensor")
1173-
lib.impl(name, linear_q4gsw_dW_impl, "CompositeExplicitAutograd")
1174-
lib.impl(name, linear_q4gsw_dW_meta, "Meta")
1175-
linear_q4gsw_dW_op = getattr(getattr(torch.ops, namespace), name)
1173+
lib.impl(name, linear_dW_impl, "CompositeExplicitAutograd")
1174+
lib.impl(name, linear_dW_meta, "Meta")
1175+
linear_dW_op = getattr(getattr(torch.ops, namespace), name)
11761176

11771177

11781178
##################

backends/vulkan/op_registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,8 +1784,8 @@ def register_logical_not():
17841784
)
17851785

17861786

1787-
@update_features(exir_ops.edge.et_vk.linear_q4gsw_dW.default)
1788-
def register_linear_q4gsw_dW():
1787+
@update_features(exir_ops.edge.et_vk.linear_dW.default)
1788+
def register_linear_dW():
17891789
return OpFeatures(
17901790
inputs_storage=utils.CONTIGUOUS_ANY,
17911791
inputs_dtypes=utils.FP_T,

backends/webgpu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ set(WEBGPU_SRCS
6868
runtime/ops/dim_order/DimOrder.cpp
6969
runtime/ops/linear/Linear.cpp
7070
runtime/ops/embedding/Embedding.cpp
71-
runtime/ops/quantized_linear/QuantizedLinearDw.cpp
71+
runtime/ops/quantized_linear/LinearDw.cpp
7272
runtime/ops/quantized_linear/QuantizedLinearRequant.cpp
7373
)
7474

backends/webgpu/runtime/ops/quantized_linear/QuantizedLinearDw.cpp renamed to backends/webgpu/runtime/ops/quantized_linear/LinearDw.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <executorch/backends/webgpu/runtime/WebGPUGraph.h>
1010
#include <executorch/backends/webgpu/runtime/WebGPUUtils.h>
1111
#include <executorch/backends/webgpu/runtime/ops/OperatorRegistry.h>
12-
#include <executorch/backends/webgpu/runtime/ops/quantized_linear/q4gsw_dW_wgsl.h>
12+
#include <executorch/backends/webgpu/runtime/ops/quantized_linear/linear_dW_wgsl.h>
1313

1414
#include <webgpu/webgpu.h>
1515

@@ -21,16 +21,16 @@ namespace executorch::backends::webgpu {
2121

2222
namespace {
2323

24-
struct Q4gswDwParams {
24+
struct LinearDwParams {
2525
uint32_t M;
2626
uint32_t N;
2727
uint32_t K;
2828
uint32_t _pad;
2929
};
30-
static_assert(sizeof(Q4gswDwParams) == 16, "params must be 16 bytes");
30+
static_assert(sizeof(LinearDwParams) == 16, "params must be 16 bytes");
3131

3232
// STE weight gradient d_W[N,K] = d_out^T @ x.
33-
void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
33+
void linear_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
3434
const int dout_id = args.at(0);
3535
const int x_id = args.at(1);
3636
const int dw_id = args.at(2);
@@ -41,12 +41,12 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
4141
const auto& dw = graph.get_tensor(dw_id);
4242

4343
if (dw.dims.size() != 2 || dout.dims.empty() || x.dims.empty()) {
44-
throw std::runtime_error("q4gsw_dW: bad tensor ranks");
44+
throw std::runtime_error("linear_dW: bad tensor ranks");
4545
}
4646
const uint32_t N = static_cast<uint32_t>(dw.dims[0]);
4747
const uint32_t K = static_cast<uint32_t>(dw.dims[1]);
4848
if (N == 0 || K == 0) {
49-
throw std::runtime_error("q4gsw_dW: N or K == 0");
49+
throw std::runtime_error("linear_dW: N or K == 0");
5050
}
5151

5252
uint64_t dout_numel = 1;
@@ -59,42 +59,42 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
5959
}
6060
if (static_cast<uint32_t>(dout.dims.back()) != N ||
6161
static_cast<uint32_t>(x.dims.back()) != K) {
62-
throw std::runtime_error("q4gsw_dW: d_out/x last dim mismatch");
62+
throw std::runtime_error("linear_dW: d_out/x last dim mismatch");
6363
}
6464
const uint32_t M = static_cast<uint32_t>(dout_numel / N);
6565
if (dout_numel % N != 0 || x_numel % K != 0 || x_numel / K != M) {
66-
throw std::runtime_error("q4gsw_dW: M mismatch across d_out/x");
66+
throw std::runtime_error("linear_dW: M mismatch across d_out/x");
6767
}
6868

6969
// fp32-only byte-size guards (mirror the forward's byte checks).
7070
if (dw.nbytes != static_cast<uint64_t>(N) * K * sizeof(float) ||
7171
dout.nbytes != dout_numel * sizeof(float) ||
7272
x.nbytes != x_numel * sizeof(float)) {
73-
throw std::runtime_error("q4gsw_dW: fp32-only (byte-size mismatch)");
73+
throw std::runtime_error("linear_dW: fp32-only (byte-size mismatch)");
7474
}
7575

76-
Q4gswDwParams params = {};
76+
LinearDwParams params = {};
7777
params.M = M;
7878
params.N = N;
7979
params.K = K;
8080

8181
const uint32_t wg_size =
82-
utils::clamp_workgroup_size(device, kQ4gswDwWorkgroupSizeX);
82+
utils::clamp_workgroup_size(device, kLinearDwWorkgroupSizeX);
8383
const uint64_t tiles =
8484
utils::div_up<uint64_t>(N, 4u) * utils::div_up<uint64_t>(K, 4u);
8585
if (tiles > UINT32_MAX) {
86-
throw std::runtime_error("q4gsw_dW: tile count exceeds u32");
86+
throw std::runtime_error("linear_dW: tile count exceeds u32");
8787
}
8888
const uint32_t workgroup_count = utils::compute_1d_workgroup_count(
89-
device, static_cast<uint32_t>(tiles), wg_size, "q4gsw_dW");
89+
device, static_cast<uint32_t>(tiles), wg_size, "linear_dW");
9090

9191
WGPUBuffer uniform_buffer =
9292
utils::make_uniform(device, &params, sizeof(params));
9393
graph.add_uniform_buffer_bytes(sizeof(params));
9494

9595
WGPUShaderSourceWGSL wgsl_desc = {};
9696
wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
97-
wgsl_desc.code = {kQ4gswDwWGSL, WGPU_STRLEN};
97+
wgsl_desc.code = {kLinearDwWGSL, WGPU_STRLEN};
9898
WGPUShaderModuleDescriptor shader_desc = {};
9999
shader_desc.nextInChain = &wgsl_desc.chain;
100100
WGPUShaderModule shader = wgpuDeviceCreateShaderModule(device, &shader_desc);
@@ -156,7 +156,7 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
156156
bg_desc.entries = bg_entries;
157157
WGPUBindGroup bind_group = wgpuDeviceCreateBindGroup(device, &bg_desc);
158158

159-
graph.add_dispatch({pipeline, bind_group, workgroup_count, "q4gsw_dW"});
159+
graph.add_dispatch({pipeline, bind_group, workgroup_count, "linear_dW"});
160160

161161
wgpuShaderModuleRelease(shader);
162162
wgpuBindGroupLayoutRelease(bgl);
@@ -167,7 +167,7 @@ void q4gsw_dW_impl(WebGPUGraph& graph, const std::vector<int>& args) {
167167
} // namespace
168168

169169
WEBGPU_REGISTER_OPERATORS {
170-
WEBGPU_REGISTER_OP(et_vk.linear_q4gsw_dW.default, q4gsw_dW_impl);
170+
WEBGPU_REGISTER_OP(et_vk.linear_dW.default, linear_dW_impl);
171171
}
172172

173173
} // namespace executorch::backends::webgpu

backends/webgpu/runtime/ops/quantized_linear/q4gsw_dW.wgsl renamed to backends/webgpu/runtime/ops/quantized_linear/linear_dW.wgsl

File renamed without changes.

backends/webgpu/runtime/ops/quantized_linear/q4gsw_dW_wgsl.h renamed to backends/webgpu/runtime/ops/quantized_linear/linear_dW_wgsl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
namespace executorch::backends::webgpu {
1414

15-
// @generated from q4gsw_dW.wgsl - DO NOT EDIT.
15+
// @generated from linear_dW.wgsl - DO NOT EDIT.
1616
// wgsl-sha256: be50075764ccd87e0d0c86124f13fd753aa618f994c9a5e1b8b631516aa51f84
17-
inline constexpr const char* kQ4gswDwWGSL = R"(
17+
inline constexpr const char* kLinearDwWGSL = R"(
1818
// STE weight-gradient d_W[N,K] = sum_m d_out[m,N]*x[m,K] (operands f32).
1919
2020
@group(0) @binding(0) var<storage, read_write> t_dw: array<f32>; // [N, K]
@@ -86,8 +86,8 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
8686
}
8787
)";
8888

89-
inline constexpr uint32_t kQ4gswDwWorkgroupSizeX = 64;
90-
inline constexpr uint32_t kQ4gswDwWorkgroupSizeY = 1;
91-
inline constexpr uint32_t kQ4gswDwWorkgroupSizeZ = 1;
89+
inline constexpr uint32_t kLinearDwWorkgroupSizeX = 64;
90+
inline constexpr uint32_t kLinearDwWorkgroupSizeY = 1;
91+
inline constexpr uint32_t kLinearDwWorkgroupSizeZ = 1;
9292

9393
} // namespace executorch::backends::webgpu

0 commit comments

Comments
 (0)