Repository navigation
meta: support GLM-5.3 next sm tensor - #30499
Conversation
|
Tried on 2x DGX Sparks and crashes like this: The startup command is: bin/llama-server -hf ggml-org/GLM-5.3-Flash-GGUF:Q4_K \
--spec-default --spec-type draft-mtp --spec-draft-n-max 3 \
-b 8192 -ub 2048 -c 262144 -np 1 -lv 4 \
--top-p 0.95 --top-k 0 --temp 1.0 \
--rpc 192.168.100.2:50052,192.168.100.1:50052 -dev RPC0,RPC1 \
--host 0.0.0.0 --port 8013 -lm dio --alias agent-glm -sm tensorBumping the |
JohannesGaessler
left a comment
There was a problem hiding this comment.
I am not saying that it should be done in this PR but I think that we should at some point look into modularizing llama_meta_device_get_split_state via the per-model subclasses.
|
@ggerganov there are extra views created per |
Is it these views? llama.cpp/src/models/delta-net-base.cpp Lines 501 to 518 in 0ce8cd1 |
|
Yes I think if less n_rs your command will also not crash. |
|
I was thinking this loop over |
|
Even now we can do the it via one extra ggml_get_rows, I think. This is what my agent suggested: |
|
If it works as suggested, I think it's an improvement to the current state. Though we should still leave a TODO to try to rearrange the states so that their order is the same and be able to copy directly without |
| const int64_t head_dim = hparams.n_embd_head_kda; | ||
| const int64_t blck_size_perf = std::lcm(blck_size, 128); | ||
| const int64_t granularity_qkv = std::lcm(blck_size_perf, head_dim); | ||
| if (std::regex_match(tensor_name, pattern_q_weight) || std::regex_match(tensor_name, pattern_kv_weight) || |
There was a problem hiding this comment.
The granularity needed for the Q and K/V matrices will in general be different. One K/V head needs to align with n_gqa Q heads. The granularity is the minimum chunk size with which a tensor can be subdivided so it needs to be bigger by a factor of n_gqa for Q than it is for K/V. You can look at the code further down for an example. What you are calculating here should be the granularity needed for K/V.
There was a problem hiding this comment.
This model has Q size 192 and K/V size has 128 iirc, that's why it's weird
There was a problem hiding this comment.
Actually, I just looked at how the tensors are created:
const int64_t head_dim = hparams.n_embd_head_kda;
const int64_t d_conv = hparams.ssm_d_conv;
const int64_t d_inner = head_dim * n_head;
if (hparams.is_recr(i)) {
auto conv = [&](llm_tensor tid) {
ggml_tensor * t = create_tensor(tn(tid, "weight", i), {d_conv, 1, d_inner, 1}, TENSOR_NOT_REQUIRED);
return t ? t : create_tensor(tn(tid, "weight", i), {d_conv, 1, d_inner}, flags);
};
layer.ssm_q_conv = conv(LLM_TENSOR_SSM_CONV1D_Q);
layer.ssm_k_conv = conv(LLM_TENSOR_SSM_CONV1D_K);
layer.ssm_v_conv = conv(LLM_TENSOR_SSM_CONV1D_V);
create_tensor_qkv(layer, i, n_embd, d_inner, d_inner, d_inner, flags);Q, K and V all have the same size for the recurrent layers so the way this is implemented is correct after all.
|
Please also check whether the added |
|
It does make a small negative difference, but it's not worth blocking this for. |
a68f5eb to
fa7d812
Compare
|
It still crashes - the branch is pretty much the same as git diff gg/glm5diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp
index a72a4e6d4..2d3356d69 100644
--- a/ggml/src/ggml-backend-meta.cpp
+++ b/ggml/src/ggml-backend-meta.cpp
@@ -1019,14 +1019,12 @@ static struct ggml_backend_meta_split_state ggml_backend_meta_get_split_state(
case GGML_OP_PAD: {
split_state = handle_pad(src_ss);
} break;
- case GGML_OP_PAD_REFLECT_1D:
- case GGML_OP_ROLL: {
- split_state = handle_generic(src_ss, /*scalar_only =*/ true);
- } break;
case GGML_OP_ARANGE: {
- // no sources, every device computes the full range
+ // no srcs, every device computes the same values
split_state = {GGML_BACKEND_SPLIT_AXIS_MIRRORED, {0}, {1}, 1};
} break;
+ case GGML_OP_PAD_REFLECT_1D:
+ case GGML_OP_ROLL:
case GGML_OP_TIMESTEP_EMBEDDING: {
split_state = handle_generic(src_ss, /*scalar_only =*/ true);
} break;Bumping the |
|
did you try the latest commit? |
|
With the latest commit there is progress - it processed the first prompt and started generating. But mid-generation it crashed like this: RPC logs: |
|
Hmm.. that's the exact bug that was fixed here 910cc2a#diff-e99ef25367982c0e888a9360c7a1e542dd59126411dbee9f04ab5e39d7b59964 (it's a related bug in the RPC backend with re-allocs) |
|
@ggerganov can we merge this? We can leave the MTP stuff for a follow up. I'm hitting the compute headroom stuff for dsv4.1 flash too, and I had to bump it to 4096 there. So we need a generic solution rather than fixing it in the model. |
|
the |
The MLA cache has a single KV head, so the heads on a device are its GQA ratio. The HIP tile FA kernel for D=512 needs an even GQA ratio; with 3 devices the 16 heads of the test model were split 5/5/6 and it aborted.
With a non-unified KV cache, build_attn_mha splits q into streams with a view. For a permuted q, e.g. the absorbed query of glm5-next, that view aborted with "view of permuted tensor not implemented". The split is now kept if every other dim of the source and the view stays inside one slab of the split axis. The per-device strides are only rescaled above it. From tetherto#353. Co-authored-by: Pratik Narola <[email protected]>
The meta backend can now split the per-stream view of the permuted q, so the cont is not needed for -sm tensor with a non-unified KV cache. With the cont, the q of flash attention was not contiguous, and when FA ran on the CPU (WebGPU) the meta get_tensor aborted.
49a581a to
1f5161c
Compare
am17an
left a comment
There was a problem hiding this comment.
@ggerganov can we merge this too? the metal failures seem unrelated to this PR
* meta: support GLM-5.3 next sm tensor * glm5-next : cont q_absorbed for -sm tensor with non-unified KV * meta : keep GGML_OP_ARANGE in ggml.h order * glm5-next : split MLA heads in pairs for -sm tensor The MLA cache has a single KV head, so the heads on a device are its GQA ratio. The HIP tile FA kernel for D=512 needs an even GQA ratio; with 3 devices the 16 heads of the test model were split 5/5/6 and it aborted. * meta : keep the split for views inside one slab of the split axis With a non-unified KV cache, build_attn_mha splits q into streams with a view. For a permuted q, e.g. the absorbed query of glm5-next, that view aborted with "view of permuted tensor not implemented". The split is now kept if every other dim of the source and the view stays inside one slab of the split axis. The per-device strides are only rescaled above it. From tetherto#353. Co-authored-by: Pratik Narola <[email protected]> * glm5-next : drop the q_absorbed cont The meta backend can now split the per-stream view of the permuted q, so the cont is not needed for -sm tensor with a non-unified KV cache. With the cont, the q of flash attention was not contiguous, and when FA ran on the CPU (WebGPU) the meta get_tensor aborted. --------- Co-authored-by: Pratik Narola <[email protected]>
Overview
Add
-sm tensorsupport for GLM 5.3 next.Additional information
Requirements