Repository navigation
Conversation
d80f553 to
e89e9c6
Compare
| bool status = send_rpc_cmd(ctx->sock, RPC_CMD_SET_TENSOR, input.data(), input.size()); | ||
| RPC_STATUS_ASSERT(status); | ||
|
|
||
| ggml_backend_rpc_retype_converted_tq4_1s(buffer, tensor); |
There was a problem hiding this comment.
This call is skipped when the hash check above finds the data already on the server (the return in the response.result branch). TQ4_1S weights are almost always above HASH_THRESHOLD, so with a server cache dir the second load takes that path, the server converts, and the client keeps TQ4_1S, which is the original bug. Run the retype on that path too.
There was a problem hiding this comment.
Fixed. The early return is gone: the hash hit now only skips the upload, and the retype runs on both paths.
bool cached = false;
if (size > HASH_THRESHOLD) {
...
cached = response.result != 0;
}
if (!cached) {
... send the data ...
}
ggml_backend_rpc_retype_converted_tq4_1s(buffer, tensor, offset, size);
The server converts the weight either way. On the hash path it calls ggml_backend_tensor_set() with the cached file, which goes through the same backend conversion, so the buffer holds q8_0 and the client has to retype.
It matters because the client is the side that carries the type into the graph: the server deserializes each graph's tensors from the client's serialization, so a client that still says TQ4_1S makes the server read q8_0 bytes as TQ4_1S.
Verified with the server's cache enabled (ggml-rpc-server -c): the first load sends the data and the second load takes the hash path. Both answer the prompt correctly now; before the fix the second load answered !!!!!!!!!!!!!!.
| bool status = send_rpc_cmd(ctx->sock, RPC_CMD_SET_TENSOR, input.data(), input.size()); | ||
| RPC_STATUS_ASSERT(status); | ||
|
|
||
| ggml_backend_rpc_retype_converted_tq4_1s(buffer, tensor); |
There was a problem hiding this comment.
ggml_backend_cuda_buffer_set_tensor converts only when offset == 0 && size == ggml_nbytes(tensor). The alloc size answers whether the server would convert a full write, so a partial write still matches and the client retypes over unconverted bytes. Any later chunk is then serialized as q8_0 and the server writes it raw. Gate the retype on offset == 0 && size == ggml_nbytes(tensor), checked before the type changes.
There was a problem hiding this comment.
Fixed. The helper takes the offset and the size and returns early unless
offset == 0 && size == ggml_nbytes(tensor)
which is the same condition ggml_backend_cuda_buffer_set_tensor uses, and it is evaluated before the type changes, so ggml_nbytes() is still the TQ4_1S size when it is read.
A partial write therefore leaves the TQ4_1S bytes on both sides: the server does not convert either, and the client does not retype, so the two agree. Without the gate the client retyped over bytes the server had not converted, and the next chunk was serialized as q8_0 and written raw.
| return response.alloc_size; | ||
| } | ||
|
|
||
| // The server converts TQ4_1S weights to q8_0 when it loads them (the conversion |
There was a problem hiding this comment.
Cut this block, the one at line 518 and the one at line 679 down to one or two lines each. Say what the code checks, not the story of the bug. This one also says the test is alloc larger than nbytes, but the code compares against the exact q8_0 size.
There was a problem hiding this comment.
Fixed. All three blocks are one or two lines now and say what the code checks:
- the helper: the server may have converted a TQ4_1S weight to q8_0, and the alloc size tells which it is;
- the alloc formula: the q8_0 alloc size, n_blocks * sizeof(block_q8_0) plus the q8_0 sized row padding;
- the get_alloc_size call site: the server may convert TQ4_1S to q8_0, so ask it for the real size.
The "larger than nbytes" wording is gone with them: the code compares the alloc size with the exact q8_0 size, not with nbytes.
|
Thanks @superbudvar. The RPC retype diagnosis is right. Two gaps and a comment trim are inline. |
e89e9c6 to
4cd1458
Compare
The three review comments are addressedOne new commit on top of the previous head:
The hash path is the bug you described, and it is now reproduced and fixedThe server's cache was on ( Previous head:
This head:
Prompt "What is 17 plus 25? Answer with just the number.", TQ4_1S model, greedy, seed 42. So the second load with the previous head took the hash path, the server converted the weight when it took it from the cache, and the client kept TQ4_1S - the original bug, reproduced on the path you pointed at. The retype now runs on both paths and the hash path gives the same answer as the upload path. The reason the client has to be the one to retype is that the client is the side that carries the type into the graph: the server deserializes each graph's tensors from the client's serialization, so a client that still says TQ4_1S makes the server read q8_0 bytes as TQ4_1S. The full-write gate
The comment blocksAll three are one or two lines now and say what the code checks. The "larger than nbytes" wording is gone with them: the code compares the alloc size with the exact q8_0 size, not with nbytes. RebasedThe branch is now the fork base
|
The server converts TQ4_1S weights to q8_0 when it loads them (the conversion is on by default for prefill speed), so the buffer it allocates holds q8_0 - 1.7x the tensor's own size. The client sized the RPC buffer with ggml_nbytes(), which is the TQ4_1S size, and told the server to allocate that much. The server then converted in place and wrote past the end of it. Ask the server for the size instead, the way the client already does for padded quantised tensors, FLASH_ATTN_EXT and MUL_MAT_ID.
The base size was already the q8_0 size the load-time conversion writes, but the MATRIX_ROW_PADDING term was still computed with the TQ4_1S row size, so a tensor with ne[0] % 512 != 0 was under-allocated per row: a converted row holds q8_0, and q8_0 is 34 bytes per 32 values against TQ4_1S's 20.
The local CUDA path retypes the tensor after the conversion:
// Update tensor metadata to q8_0
tensor->type = GGML_TYPE_Q8_0;
Over RPC that retyping happened on the server only. The client kept the
TQ4_1S type while the buffer held q8_0, so every matmul read q8_0 bytes
as TQ4_1S and the model produced garbage. A TQ4_1S model served over the
RPC peer answered "17 + 25" with "!!!!!!!!!!!!!!".
TQ3_1S is unaffected: it is never converted, so both sides agree on the
type.
The client asks the server how much it allocated for the tensor and
compares it with the size a converted TQ4_1S tensor would need
(n_blocks * sizeof(block_q8_0) plus the q8_0 row padding). If they
match, the server converted it and the client retypes the tensor the
same way the local path does. The comparison is exact, so it cannot fire
when the server kept the TQ4_1S bytes, which is the case for a server
running with GGML_TQ_NATIVE=1.
Measured over RPC (RTX 3960 Ti), prompt "What is 17 plus 25? Answer with
just the number.":
Polaris-13B-TQ4_1S over RPC before: "!!!!!!!!!!!!!!" after: "17 + 25 = 42"
Qwopus-9B-TQ4_1S over RPC before: "!!!!!!!!!!!!!!" after: "17 + 25 = 42."
…write The server converts TQ4_1S weights to q8_0 whether it takes them from the cache or from the write, so the client has to retype in both cases. The server converts only on a full write, so a partial write leaves the TQ4_1S bytes in place and the client must not retype it.
4cd1458 to
40533a4
Compare
|
Rebased onto the current fork base ( It picks up #414 (src1 column count in the TQ fused and cuBLAS paths), #412 (null
|
…heTom#417, TheTom#371, TheTom#401, TheTom#419) # Conflicts: # AGENTS.md # docs/KV-cache-quantization.md # tests/CMakeLists.txt
Overview
A TQ4_1S model served over the RPC peer produces garbage. The model answers "What is 17 plus 25?" with
!!!!!!!!!!!!!!.TQ4_1S is converted to q8_0 when it loads (the conversion is on by default, because q8_0 prefill is much faster than the native TQ path), and the conversion expands the data by 1.7x. Three things had to line up, and each was broken on its own:
ggml_nbytes(), which is the TQ4_1S size, and told the server to allocate that much. The server then converted in place and wrote past the end of it. The client now asks the server for the size, the way it already does for padded quantised tensors, FLASH_ATTN_EXT and MUL_MAT_ID.MATRIX_ROW_PADDINGterm was still computed with the TQ4_1S row size - 20 bytes per 32 values against q8_0's 34.Over RPC that retyping happened on the server only. The client kept the TQ4_1S type while the buffer held q8_0, so every matmul read q8_0 bytes as TQ4_1S.
TQ3_1S is unaffected: it is never converted, so both sides agree on the type. That is why a TQ3_1S model worked over RPC while the TQ4_1S one did not.
Additional information
How it was found
Reproduced over RPC with TQ4_1S models. The same prompt, the same peer:
17 + 25 = 42--rpc!!!!!!!!!!!!!!--rpc17 + 25 = 42The client's env var made no difference - the client does not hold the weights - and neither did the client's own size fix, which is why this survived the earlier TQ4_1S-over-RPC work and why replacing the server binaries changed nothing.
Instrumenting the client to print what the server reports as the allocated size showed the cause directly:
1.7x, which is the q8_0-to-TQ4_1S size ratio. The server was behaving as designed; the client just did not follow.
The retyping test is exact
The client asks the server how much it allocated for the tensor and compares it with the size a converted TQ4_1S tensor would need:
If they match, the server converted it and the client retypes the tensor the same way the local path does. The comparison is exact rather than "bigger than nbytes", so it cannot fire when the server kept the TQ4_1S bytes - which is the case for a server running with
GGML_TQ_NATIVE=1, and it also cannot fire on a padded row whose padding term the server still sizes as TQ4_1S, which is what commit 2 fixes.Measurements
Prompt "What is 17 plus 25? Answer with just the number.", RPC peer (RTX 3960 Ti):
!!!!!!!!!!!!!!17 + 25 = 42Scope
GGML_TYPE_TQ4_1S.ne[0] % 512 != 0; the base size was already correct.Requirements
🤖 Generated with opencode