onnxruntime: [WebGPU] `Kernel "[GroupQueryAttention] /model/layers.0/attn/GroupQueryAttention" failed. Error: Input "key" is expected to have 3, 4, or 5 dimensions".`
Describe the issue
The following error occurs when trying to run https://huggingface.co/HuggingFaceTB/SmolVLM-Instruct on WebGPU.
Note that the CPU implementation operates correctly, so this is indeed a bug with the WebGPU EP. Moreover, the zero-dimension tensor is by design, and is used for the first generation step.
To reproduce
- Install and build Transformers.js from source (https://github.com/huggingface/transformers.js)
- Run the following code in-browser:
import {
AutoProcessor,
AutoModelForVision2Seq,
load_image,
} from "@huggingface/transformers";
// Initialize processor and model
const model_id = "HuggingFaceTB/SmolVLM-Instruct";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await AutoModelForVision2Seq.from_pretrained(model_id, {
dtype: {
embed_tokens: "fp16", // "fp32", "fp16", "q8"
vision_encoder: "q4", // "fp32", "fp16", "q8", "q4", "q4f16"
decoder_model_merged: "q4", // "q8", "q4", "q4f16"
},
device: 'webgpu',
});
// Load images
const image1 = await load_image("https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg");
const image2 = await load_image("https://huggingface.co/spaces/merve/chameleon-7b/resolve/main/bee.jpg");
// Create input messages
const messages = [
{
role: "user",
content: [
{ type: "image" },
{ type: "image" },
{ type: "text", text: "Can you describe the two images?" },
],
},
];
// Prepare inputs
const text = processor.apply_chat_template(messages, { add_generation_prompt: true });
const inputs = await processor(text, [image1, image2], {
// Set `do_image_splitting: true` to split images into multiple patches.
// NOTE: This uses more memory, but can provide more accurate results.
do_image_splitting: false,
});
// Generate outputs
const generated_ids = await model.generate({
...inputs,
max_new_tokens: 500,
});
const generated_texts = processor.batch_decode(
generated_ids.slice(null, [inputs.input_ids.dims.at(-1), null]),
{ skip_special_tokens: true },
);
console.log(generated_texts[0]);
// ' In the first image, there is a green statue of liberty on a pedestal in the middle of the water. The water is surrounded by trees and buildings in the background. In the second image, there are pink and red flowers with a bee on the pink flower.'
Urgency
This blocks SmolVLM usage in Transformers.js.
ONNX Runtime Installation
Released Package
ONNX Runtime Version or Commit ID
1.20.1
Execution Provider
‘webgpu’ (WebGPU)
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 29 (27 by maintainers)
Commits related to this issue
- [JSEP/WebGPU] Add a fatal error message for unsupported GQA do_rotary attribute. (#23287) ### Description <!-- Describe your changes. --> Added a fatal error message for unsupported GroupQuerryAt... — committed to microsoft/onnxruntime by satyajandhyala 2 years ago
- [JSEP/WebGPU] Add a fatal error message for unsupported GQA do_rotary attribute. (#23287) ### Description <!-- Describe your changes. --> Added a fatal error message for unsupported GroupQuerryAt... — committed to microsoft/onnxruntime by satyajandhyala 2 years ago
- [JSEP/WebGPU] Add a fatal error message for unsupported GQA do_rotary attribute. (#23287) ### Description <!-- Describe your changes. --> Added a fatal error message for unsupported GroupQuerryAt... — committed to microsoft/onnxruntime by satyajandhyala 2 years ago
but Canary does have Float16Array enabled too (I’m sure because it complained on me in onnxruntime-common 😃)
For now we recommend to use plain GQA because we plan to switch to a new webgpu ep that supports things like flashattention2 and is going to be a magnitude faster. That new ep does not support do_rotary for FA2 yet and we want to avoid that models work on 1 EP but not on the other one. Once we have the functionality the same everywhere we’ll switch model builder to use do_rotary.
The Following PR supports do_rotary attribute on GQA. https://github.com/microsoft/onnxruntime/pull/23524
we’ll add support for do_rotary in the near future
yes
Indeed, that error message was added with https://github.com/microsoft/onnxruntime/pull/23287
using transformers.js-examples/smollm-webgpu with SmolLM2-135M-Instruct: my MHA model is fine my GQA model does not crash but has wrong output or hangs depending on the query
for me https://huggingface.co/HuggingFaceTB/SmolLM2-135M-Instruct does not crash and instead produces garbage. llama3.2-1b with gqa is working fine. I created my own gqa model, output is:
Just to be sure I tried MHA:
With MHA if I do something like summarize the model is doing a little better initially but then doesn’t know how to stop and repeats the same sentence over and over.
looking
looking