model : optimize DSA RoPE, remove some ggml_concat - #27091
Conversation
|
thanks @AesSedai for testing, the results with dsv4-flash: master - build 16d222f (10437)
PR - build 0ef788f (10433)
Gain
however, note that it comes with a drift because we are now having to calculate rope freq_factors in a hacky way: Drift by position (4096-token run): Verdict1.5% perf gain could worth it, but probably better to ask users to reconvert gguf, rather than adding more hacks to dsv4 nevertheless, the dsv3.2 and glm-dsa case are applied cleanly |
| ggml_row_size(comp->type, n_embd_head_nope)); | ||
|
|
||
| comp_pe = ggml_rope_ext(ctx0, comp_pe, comp_pos, nullptr, n_embd_head_rope, rope_type, n_ctx_orig, | ||
| comp = build_rope_trail(comp, comp_pos, n_embd_head, n_embd_head_rope, n_ctx_orig, |
There was a problem hiding this comment.
Can't you instead keep the comp_pe view and do ggml_rope_ext_inplace() on it? This avoids the concat too, but I guess you'd need to call ggml_build_forward_expand() on the result.
There was a problem hiding this comment.
ggml_rope_ext_inplace is tricky because it will break if tensor and the ops are not on the same device, I ran into the exact same problem back then with 2D RoPE
I think it's better to just add a new n_offset param to rope kernel
There was a problem hiding this comment.
ggml_rope_ext_inplaceis tricky because it will break if tensor and the ops are not on the same device, I ran into the exact same problem back then with 2D RoPEI think it's better to just add a new
n_offsetparam to rope kernel
@ngxson Perhaps a boolen flag would be enough (what to RoPE - head or tail).
There was a problem hiding this comment.
ggml_rope_ext_inplaceis tricky because it will break if tensor and the ops are not on the same device, I ran into the exact same problem back then with 2D RoPE
I think it's better to just add a newn_offsetparam to rope kernel@ngxson Perhaps a boolen flag would be enough (what to RoPE - head or tail).
@ngxson A better idea - if n_dims is negative then rope tail, otherwise rope head. No need to change the API (lazy way is the best way).
There was a problem hiding this comment.
that will still require changing the kernel anyway, the API can be just ggml_rope_set_offset(op, offset), similar to ggml_mul_mat_set_prec, so no breaking change in API
also having offset will allow much flexible usage, like for example if there are 3 rope sections (for example, 3D rope), the middle section can be controlled using the combination of offset+n_rot
|
Anyway I think that DeepSeek V3.2 and GLM changes are fine (I have no idea who wrote that crappy code 😉), I think we can merge them right now, so perhaps it would be best to split this into two PRs? (looks like the offset part will still take some time) |
👍 |
|
closing this and will replace with another PR after #27120 is merged |
Overview
DSA indexer head layout is:
Next PR: apply same fix to dflash
Requirements