Skip to content

Commit 5568c26

Browse files
committed
Update
[ghstack-poisoned]
2 parents 779b5df + f216521 commit 5568c26

29 files changed

Lines changed: 112 additions & 119 deletions

backends/vulkan/custom_ops_lib.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,13 @@ def linear_q4gsw_backward(ctx, grad_out):
335335
d_x = torch.ops.et_vk.linear_q4gsw_backward(
336336
grad_out, weights, weight_scales, ctx.group_size
337337
)
338-
return d_x, None, None, None, None # grads for (x, weights, scales, group_size, bias)
338+
return (
339+
d_x,
340+
None,
341+
None,
342+
None,
343+
None,
344+
) # grads for (x, weights, scales, group_size, bias)
339345

340346

341347
torch.library.register_autograd(
@@ -1197,7 +1203,6 @@ def fused_ce_backward(ctx, grad_loss, grad_dlogits):
11971203
fused_ce_op = getattr(getattr(torch.ops, namespace), name)
11981204

11991205

1200-
12011206
###########################
12021207
## adamw_step (training) ##
12031208
###########################
@@ -1272,7 +1277,6 @@ def linear_q4gsw_dw_meta(
12721277
linear_q4gsw_dw_op = getattr(getattr(torch.ops, namespace), name)
12731278

12741279

1275-
12761280
##################
12771281
## q4gsw_requant ##
12781282
##################

backends/vulkan/op_registry.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,6 @@ def register_fused_ce():
17691769
)
17701770

17711771

1772-
1773-
17741772
@update_features(
17751773
[
17761774
exir_ops.edge.aten.ne.Scalar,
@@ -1789,8 +1787,6 @@ def register_compare_scalar_ops():
17891787
)
17901788

17911789

1792-
1793-
17941790
@update_features(exir_ops.edge.aten.logical_not.default)
17951791
def register_logical_not():
17961792
return OpFeatures(
@@ -1801,7 +1797,6 @@ def register_logical_not():
18011797
)
18021798

18031799

1804-
18051800
@update_features("et_vk::adamw_step")
18061801
def register_adamw_step():
18071802
return OpFeatures(
@@ -1819,8 +1814,6 @@ def register_linear_q4gsw_dw():
18191814
)
18201815

18211816

1822-
1823-
18241817
@update_features(exir_ops.edge.et_vk.q4gsw_requant.default)
18251818
def register_q4gsw_requant():
18261819
return OpFeatures(

backends/webgpu/runtime/ops/compare/Compare.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ void compare_impl(
6969
const size_t out_bind_size = (out_tensor.nbytes + 3) & ~size_t(3);
7070
const uint32_t n_words = (numel + 3u) / 4u;
7171

72-
uint32_t wg_size = utils::clamp_workgroup_size(device, kCompareWorkgroupSizeX);
72+
uint32_t wg_size =
73+
utils::clamp_workgroup_size(device, kCompareWorkgroupSizeX);
7374
uint32_t workgroup_count =
7475
utils::compute_1d_workgroup_count(device, n_words, wg_size, op_name);
7576

@@ -139,20 +140,21 @@ void compare_impl(
139140
graph.add_dispatch({pipeline, bind_group, workgroup_count});
140141

141142
WGPUBuffer p_buf = params_buf;
142-
auto cmp_resize = [self_id, out_id, mode, scalar, wg_size, dispatch_idx,
143-
p_buf, op_name](WebGPUGraph& g) {
144-
const auto& d = g.cur_dims(self_id);
145-
uint32_t n = 1u;
146-
for (auto x : d) {
147-
n *= static_cast<uint32_t>(x);
148-
}
149-
g.set_cur_dims(out_id, d);
150-
CompareParams p = {n, mode, scalar, 0u};
151-
wgpuQueueWriteBuffer(g.queue(), p_buf, 0, &p, sizeof(p));
152-
const uint32_t nw = (n + 3u) / 4u;
153-
g.dispatch_at(dispatch_idx).workgroup_count_x =
154-
utils::compute_1d_workgroup_count(g.device(), nw, wg_size, op_name);
155-
};
143+
auto cmp_resize =
144+
[self_id, out_id, mode, scalar, wg_size, dispatch_idx, p_buf, op_name](
145+
WebGPUGraph& g) {
146+
const auto& d = g.cur_dims(self_id);
147+
uint32_t n = 1u;
148+
for (auto x : d) {
149+
n *= static_cast<uint32_t>(x);
150+
}
151+
g.set_cur_dims(out_id, d);
152+
CompareParams p = {n, mode, scalar, 0u};
153+
wgpuQueueWriteBuffer(g.queue(), p_buf, 0, &p, sizeof(p));
154+
const uint32_t nw = (n + 3u) / 4u;
155+
g.dispatch_at(dispatch_idx).workgroup_count_x =
156+
utils::compute_1d_workgroup_count(g.device(), nw, wg_size, op_name);
157+
};
156158
graph.add_tensor_resize_hook(self_id, cmp_resize);
157159

158160
wgpuShaderModuleRelease(shader);

backends/webgpu/runtime/ops/embedding/Embedding.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ void embedding_impl(WebGPUGraph& graph, const std::vector<int>& args) {
5454
if (out.nbytes != out_numel * sizeof(float) ||
5555
weight.nbytes % sizeof(float) != 0 ||
5656
indices.nbytes != index_numel * sizeof(int32_t)) {
57-
throw std::runtime_error("embedding: fp32 weight/out + i32 indices required");
57+
throw std::runtime_error(
58+
"embedding: fp32 weight/out + i32 indices required");
5859
}
5960
if (out_numel != index_numel * dim) {
6061
throw std::runtime_error("embedding: out numel != num_indices * dim");

backends/webgpu/runtime/ops/fill/Fill.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,20 +144,26 @@ void add_fill(
144144

145145
void full_impl(WebGPUGraph& graph, const std::vector<int>& args) {
146146
add_fill(
147-
graph, args.at(args.size() - 1), read_scalar(graph, args.at(1), "full"),
147+
graph,
148+
args.at(args.size() - 1),
149+
read_scalar(graph, args.at(1), "full"),
148150
"full");
149151
}
150152

151153
void full_like_impl(WebGPUGraph& graph, const std::vector<int>& args) {
152154
add_fill(
153-
graph, args.at(args.size() - 1),
154-
read_scalar(graph, args.at(1), "full_like"), "full_like");
155+
graph,
156+
args.at(args.size() - 1),
157+
read_scalar(graph, args.at(1), "full_like"),
158+
"full_like");
155159
}
156160

157161
void scalar_tensor_impl(WebGPUGraph& graph, const std::vector<int>& args) {
158162
add_fill(
159-
graph, args.at(args.size() - 1),
160-
read_scalar(graph, args.at(0), "scalar_tensor"), "scalar_tensor");
163+
graph,
164+
args.at(args.size() - 1),
165+
read_scalar(graph, args.at(0), "scalar_tensor"),
166+
"scalar_tensor");
161167
}
162168

163169
} // namespace

backends/webgpu/runtime/ops/log_softmax/LogSoftmax.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ struct LogSoftmaxParams {
2929
uint32_t inner;
3030
uint32_t pad_;
3131
};
32-
static_assert(sizeof(LogSoftmaxParams) == 16, "LogSoftmaxParams must be 16 bytes");
32+
static_assert(
33+
sizeof(LogSoftmaxParams) == 16,
34+
"LogSoftmaxParams must be 16 bytes");
3335

3436
// Decompose dims into [outer, R, inner] for a reduction along `dim`.
3537
void decompose(
@@ -85,7 +87,8 @@ void log_softmax_impl(WebGPUGraph& graph, const std::vector<int>& args) {
8587
for (int64_t d : in.dims) {
8688
numel *= static_cast<uint64_t>(d);
8789
}
88-
if (in.nbytes != numel * sizeof(float) || out.nbytes != numel * sizeof(float)) {
90+
if (in.nbytes != numel * sizeof(float) ||
91+
out.nbytes != numel * sizeof(float)) {
8992
throw std::runtime_error(
9093
"WebGPU log_softmax: fp32-only (byte-size mismatch)");
9194
}
@@ -205,7 +208,9 @@ void log_softmax_impl(WebGPUGraph& graph, const std::vector<int>& args) {
205208
wgpuQueueWriteBuffer(g.queue(), params_buf, 0, &p, sizeof(p));
206209
g.dispatch_at(dispatch_idx).workgroup_count_x =
207210
utils::compute_1d_workgroup_count(
208-
g.device(), static_cast<uint32_t>(live_lines), wg_size,
211+
g.device(),
212+
static_cast<uint32_t>(live_lines),
213+
wg_size,
209214
"log_softmax(resize)");
210215
g.set_cur_dims(out_id, std::vector<int64_t>(d.begin(), d.end()));
211216
});

backends/webgpu/runtime/ops/logical_not/LogicalNot.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,21 @@ void logical_not_impl(WebGPUGraph& graph, const std::vector<int>& args) {
120120
graph.add_dispatch({pipeline, bind_group, workgroup_count});
121121

122122
WGPUBuffer p_buf = params_buf;
123-
auto resize = [self_id, out_id, wg_size, dispatch_idx, p_buf](
124-
WebGPUGraph& g) {
125-
const auto& d = g.cur_dims(self_id);
126-
uint32_t n = 1u;
127-
for (auto x : d) {
128-
n *= static_cast<uint32_t>(x);
129-
}
130-
g.set_cur_dims(out_id, d);
131-
LogicalNotParams p = {n, 0u, 0u, 0u};
132-
wgpuQueueWriteBuffer(g.queue(), p_buf, 0, &p, sizeof(p));
133-
const uint32_t nw = (n + 3u) / 4u;
134-
g.dispatch_at(dispatch_idx).workgroup_count_x =
135-
utils::compute_1d_workgroup_count(g.device(), nw, wg_size, "logical_not");
136-
};
123+
auto resize =
124+
[self_id, out_id, wg_size, dispatch_idx, p_buf](WebGPUGraph& g) {
125+
const auto& d = g.cur_dims(self_id);
126+
uint32_t n = 1u;
127+
for (auto x : d) {
128+
n *= static_cast<uint32_t>(x);
129+
}
130+
g.set_cur_dims(out_id, d);
131+
LogicalNotParams p = {n, 0u, 0u, 0u};
132+
wgpuQueueWriteBuffer(g.queue(), p_buf, 0, &p, sizeof(p));
133+
const uint32_t nw = (n + 3u) / 4u;
134+
g.dispatch_at(dispatch_idx).workgroup_count_x =
135+
utils::compute_1d_workgroup_count(
136+
g.device(), nw, wg_size, "logical_not");
137+
};
137138
graph.add_tensor_resize_hook(self_id, resize);
138139

139140
wgpuShaderModuleRelease(shader);

backends/webgpu/runtime/ops/quantized_linear/QuantizedLinearBackward.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ void q4gsw_backward_impl(WebGPUGraph& graph, const std::vector<int>& args) {
8181
if (dout.nbytes != static_cast<uint64_t>(M) * N * sizeof(float)) {
8282
throw std::runtime_error("q4gsw_backward: d_out fp32/shape mismatch");
8383
}
84-
if (scales.nbytes != static_cast<uint64_t>(num_groups) * padded_N * sizeof(float)) {
84+
if (scales.nbytes !=
85+
static_cast<uint64_t>(num_groups) * padded_N * sizeof(float)) {
8586
throw std::runtime_error("q4gsw_backward: scales fp32/shape mismatch");
8687
}
8788
if (weight.nbytes != static_cast<uint64_t>(N) * K_packed) {

backends/webgpu/runtime/ops/reduce/Reduce.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ void reduce_impl(
227227
wgpuQueueWriteBuffer(g.queue(), params_buf, 0, &p, sizeof(p));
228228
g.dispatch_at(dispatch_idx).workgroup_count_x =
229229
utils::compute_1d_workgroup_count(
230-
g.device(), static_cast<uint32_t>(live_outputs), wg_size,
230+
g.device(),
231+
static_cast<uint32_t>(live_outputs),
232+
wg_size,
231233
"reduce(resize)");
232234
// Propagate reduced output dims for downstream resize hooks.
233235
int64_t nd = static_cast<int64_t>(d.size());

backends/webgpu/runtime/ops/softmax/Softmax.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ void softmax_impl(WebGPUGraph& graph, const std::vector<int>& args) {
173173

174174
// Dynamic shapes: recompute the decomposition for the reduced dim + dispatch.
175175
WGPUBuffer params_buf = uniform_buffer;
176-
const uint64_t build_numel =
177-
static_cast<uint64_t>(outer) * r * inner;
176+
const uint64_t build_numel = static_cast<uint64_t>(outer) * r * inner;
178177
graph.add_tensor_resize_hook(
179178
in_id,
180179
[in_id, out_id, dim, build_numel, wg_size, dispatch_idx, params_buf](
@@ -198,7 +197,9 @@ void softmax_impl(WebGPUGraph& graph, const std::vector<int>& args) {
198197
wgpuQueueWriteBuffer(g.queue(), params_buf, 0, &p, sizeof(p));
199198
g.dispatch_at(dispatch_idx).workgroup_count_x =
200199
utils::compute_1d_workgroup_count(
201-
g.device(), static_cast<uint32_t>(live_lines), wg_size,
200+
g.device(),
201+
static_cast<uint32_t>(live_lines),
202+
wg_size,
202203
"softmax(resize)");
203204
g.set_cur_dims(out_id, d);
204205
});

0 commit comments

Comments
 (0)