Compare commits

...
2 Commits
Author SHA1 Message Date
Wenyu Chen 212c547fe9 ui: add cancel button to cancel model loading (#32225) 2026-11-23 09:27:44 +01:00
Leon f5e6915c28 webgpu : add ROLL support (#31887)
* webgpu : add ROLL support

* tests : keep ROLL cases portable across backends
2026-11-23 09:56:54 +02:00
8 changed files with 77 additions and 21 deletions
+1 -1
View File
@@ -97,7 +97,7 @@ Legend:
| REPEAT_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| RMS_NORM | ❌ | ✅ | ✅ | ✅ | 🟡 | ✅ | ✅ | 🟡 | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
| RMS_NORM_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| ROLL | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| ROLL | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ❌ |
| ROPE | ❌ | ✅ | ✅ | ✅ | 🟡 | 🟡 | ✅ | 🟡 | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| ROPE_BACK | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ |
| ROUND | ❌ | ❌ | ✅ | 🟡 | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ❌ |
+7 -1
View File
@@ -12345,7 +12345,13 @@
"WebGPU: WebGPU","PAD_REFLECT_1D","type=f32,ne_a=[257,7,1,1],pad_0=0,pad_1=256,view=0","support","1","yes","WebGPU"
"WebGPU: WebGPU","PAD_REFLECT_1D","type=f32,ne_a=[2,16777217,1,1],pad_0=1,pad_1=1,view=0","support","1","yes","WebGPU"
"WebGPU: WebGPU","PAD_REFLECT_1D","type=f32,ne_a=[3000,384,4,1],pad_0=10,pad_1=9,view=0","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=3,shift1=-2,shift3=1,shift4=-1","support","0","no","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=3,shift1=-2,shift3=1,shift4=-1,permute=0,ne_a=[10,5,4,3]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=3,shift1=-2,shift3=1,shift4=-1,permute=1,ne_a=[10,5,4,3]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=0,shift1=0,shift3=0,shift4=0,permute=0,ne_a=[1,1,1,1]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=256,shift1=0,shift3=0,shift4=0,permute=0,ne_a=[257,1,1,1]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=-16,shift1=6,shift3=-2,shift4=1,permute=0,ne_a=[17,7,3,2]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=4,shift1=0,shift3=0,shift4=0,permute=0,ne_a=[42,512,1,1]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ROLL","shift0=4,shift1=0,shift3=0,shift4=0,permute=0,ne_a=[380,512,1,1]","support","1","yes","WebGPU"
"WebGPU: WebGPU","ARANGE","type=f32,start=0.000000,stop=10.000000,step=1.000000","support","1","yes","WebGPU"
"WebGPU: WebGPU","ARANGE","type=f32,start=3.000000,stop=3.500000,step=1.000000","support","1","yes","WebGPU"
"WebGPU: WebGPU","ARANGE","type=f32,start=-10.000000,stop=10.000000,step=0.300000","support","1","yes","WebGPU"
Can't render this file because it is too large.
@@ -2117,7 +2117,7 @@ class ggml_webgpu_shader_lib {
webgpu_pipeline get_pad_pipeline(const ggml_webgpu_shader_lib_context & context) {
ggml_webgpu_pad_pipeline_key key = {};
key.reflect = context.dst->op == GGML_OP_PAD_REFLECT_1D;
key.circular = !key.reflect && ggml_get_op_params_i32(context.dst, 8) != 0;
key.circular = context.dst->op == GGML_OP_ROLL || (!key.reflect && ggml_get_op_params_i32(context.dst, 8) != 0);
auto it = pad_pipelines.find(key);
if (it != pad_pipelines.end()) {
+13 -9
View File
@@ -964,16 +964,18 @@ static webgpu_encoded_op ggml_webgpu_pad(webgpu_context & ctx, ggml_tensor * src
(uint32_t) dst->ne[1],
(uint32_t) dst->ne[2],
(uint32_t) dst->ne[3],
// Pad sizes
(uint32_t) ggml_get_op_params_i32(dst, 0),
(uint32_t) ggml_get_op_params_i32(dst, 1),
(uint32_t) ggml_get_op_params_i32(dst, 2),
(uint32_t) ggml_get_op_params_i32(dst, 3),
(uint32_t) ggml_get_op_params_i32(dst, 4),
(uint32_t) ggml_get_op_params_i32(dst, 5),
(uint32_t) ggml_get_op_params_i32(dst, 6),
(uint32_t) ggml_get_op_params_i32(dst, 7),
};
for (int i = 0; i < 4; i++) {
if (dst->op == GGML_OP_ROLL) {
// Circular padding with unchanged dimensions implements a roll.
const int64_t shift = ggml_get_op_params_i32(dst, i);
params.push_back((uint32_t) (shift < 0 ? shift + src->ne[i] : shift));
params.push_back(0);
} else {
params.push_back((uint32_t) ggml_get_op_params_i32(dst, 2 * i));
params.push_back((uint32_t) ggml_get_op_params_i32(dst, 2 * i + 1));
}
}
std::vector<wgpu::BindGroupEntry> entries = {
ggml_webgpu_make_tensor_bind_group_entry(ctx, 0, src),
@@ -3740,6 +3742,7 @@ static std::optional<webgpu_encoded_op> ggml_webgpu_encode(webgpu_context ctx,
return ggml_webgpu_pool2d(ctx, src0, node);
case GGML_OP_COL2IM_1D:
return ggml_webgpu_col2im_1d(ctx, src0, node);
case GGML_OP_ROLL:
case GGML_OP_PAD_REFLECT_1D:
case GGML_OP_PAD:
return ggml_webgpu_pad(ctx, src0, node);
@@ -5299,6 +5302,7 @@ static bool ggml_backend_webgpu_device_supports_op(ggml_backend_dev_t dev, const
case GGML_OP_PAD_REFLECT_1D:
supports_op = op->type == GGML_TYPE_F32 && src0->type == GGML_TYPE_F32;
break;
case GGML_OP_ROLL:
case GGML_OP_PAD:
supports_op = op->type == GGML_TYPE_F32 && src0->type == GGML_TYPE_F32;
break;
+14 -5
View File
@@ -9087,17 +9087,18 @@ struct test_roll : public test_case {
const int shift3;
const int shift4;
const bool permute;
const std::array<int64_t, 4> ne_a;
std::string vars() override {
return VARS_TO_STR5(shift0, shift1, shift3, shift4, permute);
return VARS_TO_STR6(shift0, shift1, shift3, shift4, permute, ne_a);
}
test_roll(int shift0 = 3, int shift1 = -2, int shift3 = 1, int shift4 = -1, bool permute = false)
: shift0(shift0), shift1(shift1), shift3(shift3), shift4(shift4), permute(permute) {}
test_roll(int shift0 = 3, int shift1 = -2, int shift3 = 1, int shift4 = -1, bool permute = false,
std::array<int64_t, 4> ne_a = {10, 5, 4, 3})
: shift0(shift0), shift1(shift1), shift3(shift3), shift4(shift4), permute(permute), ne_a(ne_a) {}
ggml_tensor * build_graph(ggml_context * ctx) override {
int64_t ne[4] = {10, 5, 4, 3};
ggml_tensor * a = ggml_new_tensor(ctx, GGML_TYPE_F32, 4, ne);
ggml_tensor * a = ggml_new_tensor(ctx, GGML_TYPE_F32, 4, ne_a.data());
ggml_set_name(a, "a");
if (permute) {
@@ -13183,6 +13184,11 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_eval() {
test_cases.emplace_back(new test_pad_reflect_1d(GGML_TYPE_F32, {3000, 384, 4, 1}));
test_cases.emplace_back(new test_roll());
test_cases.emplace_back(new test_roll(3, -2, 1, -1, true));
test_cases.emplace_back(new test_roll(0, 0, 0, 0, false, {1, 1, 1, 1}));
test_cases.emplace_back(new test_roll(256, 0, 0, 0, false, {257, 1, 1, 1}));
test_cases.emplace_back(new test_roll(-16, 6, -2, 1, false, {17, 7, 3, 2}));
test_cases.emplace_back(new test_roll(4, 0, 0, 0, false, {42, 512, 1, 1}));
test_cases.emplace_back(new test_roll(4, 0, 0, 0, false, {380, 512, 1, 1}));
test_cases.emplace_back(new test_arange());
test_cases.emplace_back(new test_arange(GGML_TYPE_F32, 3.0f, 3.5f, 1.0f));
test_cases.emplace_back(new test_arange(GGML_TYPE_F32, -10.0f, 10.0f, 0.3f));
@@ -13916,6 +13922,9 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_perf() {
test_cases.emplace_back(new test_arange(GGML_TYPE_F32, 0.0f, n, 1.0f));
}
test_cases.emplace_back(new test_roll(4, 0, 0, 0, false, {42, 512, 1, 1}));
test_cases.emplace_back(new test_roll(4, 0, 0, 0, false, {380, 512, 1, 1}));
// embedding lookups: one token (decode) and one batch of 2048 tokens (prefill)
for (int r : {16, 32768}) {
test_cases.emplace_back(new test_get_rows(GGML_TYPE_F8_E4M3, 160, 2000000, r, 1, 1, false)); // Qwen4-Exp n-gram table, 16 rows per token
@@ -31,7 +31,29 @@
<div class={['flex w-5 shrink-0 items-center justify-center', className]}>
{#if isLoading}
<MODEL_LOAD_ICONS.loading class="{ICON_CLASS_DEFAULT} animate-spin text-muted-foreground" />
<MODEL_LOAD_ICONS.loading
class="{ICON_CLASS_DEFAULT} animate-spin text-muted-foreground {showAction && revealOnHover
? 'group-hover:hidden [@media(pointer:coarse)]:hidden'
: ''}"
/>
<div
class={!showAction
? 'hidden'
: revealOnHover
? 'hidden group-hover:flex [@media(pointer:coarse)]:flex'
: 'flex'}
>
<ActionIcon
class="h-5 w-5 hover:text-foreground"
icon={MODEL_LOAD_ICONS.cancel}
iconSize="h-4 w-4"
onclick={() => modelsStore.status.cancelLoad(option.model)}
stopPropagationOnClick
tooltip="Cancel loading model"
tooltipAsTitle
/>
</div>
{:else}
<!-- the state dot is what the row shows at rest; the action takes its place on hover -->
{#if showAction && revealOnHover}
@@ -22,6 +22,7 @@ import LoadIcon from '@lucide/svelte/icons/power';
import RetryIcon from '@lucide/svelte/icons/rotate-cw';
import PromptCommandIcon from '@lucide/svelte/icons/sparkles';
import VideoIcon from '@lucide/svelte/icons/video';
import CancelLoadIcon from '@lucide/svelte/icons/x';
import { ChatFormCommandAction, FileTypeCategory, ModelCapability } from '#lib/enums/index.ts';
import type { ModelCapabilities } from '#lib/types/models.js';
import type { Component } from 'svelte';
@@ -80,6 +81,7 @@ export const MODEL_DOWNLOAD_ICONS = {
/** Icons the model load control shows for its states and actions. */
export const MODEL_LOAD_ICONS = {
cancel: CancelLoadIcon,
failed: LoadFailedIcon,
load: LoadIcon,
loading: LoadingIcon,
@@ -152,6 +152,8 @@ export class ModelStatusManager {
private listedSidecarsByRepo = $derived.by(() =>
ModelsService.draftSidecarsByRepo(this.host.routerModels)
);
/** Models whose load the user cancelled; the failure the force-kill triggers is intentional, not a load failure. */
private loadCancelRequests = new SvelteSet<string>();
private loadingStates = new SvelteMap<string, boolean>();
private loadProgress = new SvelteMap<string, ModelLoadProgress>();
/** Paused downloads with their last reported progress, or null when none arrived before the pause. */
@@ -198,8 +200,8 @@ export class ModelStatusManager {
});
// /models/sse feed state, the single source of truth for status and load progress
private statusAbort: AbortController | null = null;
private statusReaderActive = false;
private statusReaderActive = false;
private statusWaiters = new SvelteMap<
string,
{ target: ServerModelStatus; resolve: () => void; reject: (e: Error) => void }[]
@@ -269,10 +271,15 @@ export class ModelStatusManager {
this.subscribe();
// mark before the kill: the feed can report the child's death before
// this request returns, and load() must not toast it as a failure
this.loadCancelRequests.add(modelId);
try {
await ModelsService.unload(modelId);
toast.info(`Load cancelled: ${this.host.toDisplayName(modelId)}`);
} catch (error) {
this.loadCancelRequests.delete(modelId);
toast.error(`Failed to cancel load: ${this.host.toDisplayName(modelId)}`);
throw error;
@@ -516,11 +523,17 @@ export class ModelStatusManager {
toast.success(`Model loaded: ${this.host.toDisplayName(modelId)}`);
} catch (error) {
this.rejectStatus(modelId, error instanceof Error ? error : new Error('load failed'));
this.host.error = error instanceof Error ? error.message : 'Failed to load model';
toast.error(`Failed to load model: ${this.host.toDisplayName(modelId)}`);
// a user cancel force-kills the child, which settles this waiter as a
// failure; cancelLoad already reported the cancel, so stay silent
if (!this.loadCancelRequests.delete(modelId)) {
this.host.error = error instanceof Error ? error.message : 'Failed to load model';
toast.error(`Failed to load model: ${this.host.toDisplayName(modelId)}`);
}
throw error;
} finally {
this.loadCancelRequests.delete(modelId);
this.loadingStates.set(modelId, false);
}
}