[executorch][webgpu] Preserve embedding packing on resize - #21405
Conversation
This PR needs a
|
|
@claude Thoroughly review for redundancy or areas of modularization or any high value changes |
|
Claude finished @JCNTH's task in 1m 2s —— View job Review: Preserve embedding packing on resizeThe fix is correct and minimal — That said, since you asked specifically about redundancy / modularization, this diff is a good illustration of a latent structural issue rather than a problem with the change itself. High-value observation: the resize path re-derives params instead of reusing them
On resize, only two fields are actually dynamic: This duplication is precisely the bug this PR fixes. A more robust shape would be to capture the fully-populated base void resize_embedding_q4gsw(
WebGPUGraph& g,
int indices_id,
int out_id,
EmbeddingParams base, // graph-invariant fields already set
uint32_t wg_size,
size_t dispatch_idx,
WGPUBuffer params_buf) {
const auto& id = g.cur_dims(indices_id);
const uint64_t ni = utils::numel_of(id);
if (ni == 0) {
throw std::runtime_error("WebGPU embedding_q4gsw: zero indices");
}
const uint64_t total_blocks = ni * base.blocks_per_row;
if (total_blocks > UINT32_MAX) {
throw std::runtime_error("WebGPU embedding_q4gsw: total_blocks exceeds uint32");
}
std::vector<int64_t> od = id;
od.push_back(static_cast<int64_t>(base.embed_dim));
g.set_cur_dims(out_id, od);
base.num_indices = static_cast<uint32_t>(ni);
base.total_blocks = static_cast<uint32_t>(total_blocks);
wgpuQueueWriteBuffer(g.queue(), params_buf, 0, &base, sizeof(base));
g.dispatch_at(dispatch_idx).workgroup_count_x =
utils::compute_1d_workgroup_count(
g.device(), static_cast<uint32_t>(total_blocks), wg_size,
"embedding_q4gsw(resize)");
}Benefits:
Minor notes
Net: the diff is correct — approve on merit. The refactor above is the higher-value follow-up and would retire this bug class rather than one instance of it. --- · branch |
SS-JIA
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Stack from ghstack (oldest at bottom):
Dynamic Q4 embedding reuse now preserves the complete packing configuration.
A resize used to rebuild the uniform field by field, which dropped
is_linear_weight. The resize hook now captures the fully initializedEmbeddingParamsand rewrites onlynum_indicesandtotal_blocks.Key changes:
EmbeddingQ4gsw.cpp— pass a 32-byte base parameter struct by value through the resize callback.EmbeddingQ4gsw.cpp, which retainsis_linear_weightin push-constant state across resize.Static and nonlinear embedding behavior is unchanged.
Co-authored-with: Claude Code.
@exported-using-ghexport
Differential Revision: D113627870
Differential Revision: D113627870