Skip to content

ggml-cuda : fix cpy transposed path corrupting non-contiguous dst - #27663

Merged
am17an merged 3 commits into
ggml-org:masterfrom
devYRPauli:fix/cuda-cpy-transposed-noncontiguous-dst
Oct 2, 2026
Merged

am17an merged 3 commits into
ggml-org:masterfrom
devYRPauli:fix/cuda-cpy-transposed-noncontiguous-dst

Conversation

@devYRPauli

@devYRPauli devYRPauli commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Overview

ggml_cuda_cpy's can_be_transposed gate only inspects the layout of src0. When the destination src1 is non-contiguous, for example a strided view_2d slot such as a KV-cache column write, a same-type F32/F16/BF16/I32 copy still takes the transposed scalar kernel.

That kernel writes the destination with a contiguous index derived from ne00 and ne01, and it ignores the destination strides nb10 to nb13. They are passed to GGML_UNUSED_VARS at ggml/src/ggml-cuda/cpy.cu:96. The result is silent corruption of the strided destination.

The fix requires ggml_is_contiguous(src1) for the transposed fast path. A non-contiguous destination now falls back to the general cpy_scalar kernel, which honors nb10 to nb13. A contiguous destination, which is the common case, takes the same path as before, so the normal path does not change.

The PR now has 2 commits: 53f32dff0 contains the 2-line CUDA fix in cpy.cu, and 0e2f7fe54 adds 2 regression cases to tests/test-backend-ops.cpp for F32 and F16 with a permuted source and strided dst_alloc.

Additional information

This is the same fix as ggml-org/ggml#1570, moved to this repository. That PR was closed on 2026-08-24.

The root-cause analysis and a reproduction, 16 ops plus a real transformer decode, are in ggml-org/ggml#1497. @OriPekelman pinpointed the exact gate and proposed this fix; the credit is theirs.

I re-verified the code path before opening this:

  • can_be_transposed in ggml/src/ggml-cuda/cpy.cu only tested the source layout and did not test whether the destination was contiguous.
  • cpy_scalar_transpose ignores nb10, nb11, nb12, and nb13, so a non-contiguous destination cannot be written correctly on that path.

I do not have a local CUDA build on macOS, so I could not run the CUDA kernel locally. @Jaydeep505 tested the change on a Tesla T4 (sm_75):

  • test-backend-ops -o CPY -b CUDA0 -p dst_alloc passes 2/4 without the fix; the 2 new F32/F16 cases fail with errors 1.903 and 1.974.
  • With the fix, the same filtered run passes 4/4.
  • Their nllb.cpp probe found 3 of 45 combinations differing from CPU output before the fix and 0 of 45 after it.

On Metal, the 2 new regression cases also pass: -o CPY -p dst_alloc is 4/4 and the full -o CPY run is 199/199. This only confirms that the new cases behave correctly on Metal against the CPU reference; it does not exercise the CUDA fix.

Requirements

can_be_transposed only inspected the source layout. A non-contiguous
destination still took the transposed scalar kernel.

That kernel derives the destination index from ne00 and ne01 and ignores
the destination strides nb10 to nb13, so a strided destination was
silently corrupted.

Require the destination to be contiguous for the transposed path. A
non-contiguous destination now falls back to the general kernel, which
honors the strides. The contiguous case is unchanged.

Assisted-by: Claude Opus 5
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Aug 24, 2026
@devYRPauli
devYRPauli marked this pull request as ready for review August 24, 2026 15:12
@devYRPauli
devYRPauli requested a review from a team as a code owner August 24, 2026 15:12

@Jaydeep505 Jaydeep505 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using one of this cuda kernal cpy.cu in an Independent real-world project of porting nllb to C++. Namely, while writing new tokens' values into transposed V cache. Resulting into hallucinaton of output at both fp32 and fp16 on 2 different Nvidia GPUs GTX 1650 and a T4.

test-backend-ops, T4 (sm_75)

Added after the existing // strided dst cases in tests/test-backend-ops.cpp:

test_cases.emplace_back(new test_cpy(GGML_TYPE_F32, GGML_TYPE_F32, {64, 16, 1, 1}, {1, 64, 16, 1}, {1, 2, 0, 3}, {0, 0, 0, 0}, false, {32, 64, 16, 1}));
test_cases.emplace_back(new test_cpy(GGML_TYPE_F16, GGML_TYPE_F16, {64, 16, 1, 1}, {1, 64, 16, 1}, {1, 2, 0, 3}, {0, 0, 0, 0}, false, {32, 64, 16, 1}));

test-backend-ops -o CPY -b CUDA0 -p dst_alloc

Without the fix (HEAD~1):

ggml_cuda_init: found 1 CUDA devices (Total VRAM: 14912 MiB):
  Device 0: Tesla T4, compute capability 7.5, VMM: yes, VRAM: 14912 MiB
Testing 2 devices

Backend 1/2: CUDA0
  Device description: Tesla T4
  Device memory: 14912 MB (14807 MB free)

  CPY(type_src=f32,type_dst=f32,ne_src=[128,2,3,1],ne_dst=[128,2,3,1],permute_src=[0,0,0,0],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[128,4,3,1]): OK
  CPY(type_src=f16,type_dst=f16,ne_src=[128,2,3,1],ne_dst=[128,2,3,1],permute_src=[0,0,0,0],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[128,4,3,1]): OK
[CPY] ERR = 1.903213131 > 0.000000000   CPY(type_src=f32,type_dst=f32,ne_src=[64,16,1,1],ne_dst=[1,64,16,1],permute_src=[1,2,0,3],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[32,64,16,1]): FAIL
[CPY] ERR = 1.974209135 > 0.000000000   CPY(type_src=f16,type_dst=f16,ne_src=[64,16,1,1],ne_dst=[1,64,16,1],permute_src=[1,2,0,3],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[32,64,16,1]): FAIL
  2/4 tests passed

Failing tests:
  CPY(type_src=f32,type_dst=f32,ne_src=[64,16,1,1],ne_dst=[1,64,16,1],permute_src=[1,2,0,3],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[32,64,16,1])
  CPY(type_src=f16,type_dst=f16,ne_src=[64,16,1,1],ne_dst=[1,64,16,1],permute_src=[1,2,0,3],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[32,64,16,1])
  Backend CUDA0: FAIL
Backend 2/2: CPU
  Skipping
1/2 backends passed
FAIL

With the fix:

ggml_cuda_init: found 1 CUDA devices (Total VRAM: 14912 MiB):
  Device 0: Tesla T4, compute capability 7.5, VMM: yes, VRAM: 14912 MiB
Testing 2 devices

Backend 1/2: CUDA0
  Device description: Tesla T4
  Device memory: 14912 MB (14807 MB free)

  CPY(type_src=f32,type_dst=f32,ne_src=[128,2,3,1],ne_dst=[128,2,3,1],permute_src=[0,0,0,0],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[128,4,3,1]): OK
  CPY(type_src=f16,type_dst=f16,ne_src=[128,2,3,1],ne_dst=[128,2,3,1],permute_src=[0,0,0,0],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[128,4,3,1]): OK
  CPY(type_src=f32,type_dst=f32,ne_src=[64,16,1,1],ne_dst=[1,64,16,1],permute_src=[1,2,0,3],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[32,64,16,1]): OK
  CPY(type_src=f16,type_dst=f16,ne_src=[64,16,1,1],ne_dst=[1,64,16,1],permute_src=[1,2,0,3],permute_dst=[0,0,0,0],_src_transpose=0,dst_alloc=[32,64,16,1]): OK
  4/4 tests passed
  Backend CUDA0: OK
Backend 2/2: CPU
  Skipping
2/2 backends passed
OK
full probe output (nllb.cpp, T4)

Before the fix: 3 of 45 combinations differ from the CPU output

device: CUDA0 (Tesla T4)
op                       Tn n_past  max rel      verdict
cpy K -> k_dst view       1      0  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       1      5  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       1     20  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       3      0  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       3      5  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       3     20  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       9      0  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       9      5  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       9     20  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       1      0  1.978e+00    BAD (507 floats differ)
cpy V -> v_dst view       1      5  1.943e+00    BAD (507 floats differ)
cpy V -> v_dst view       1     20  1.857e+00    BAD (507 floats differ)
cpy V -> v_dst view       3      0  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       3      5  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       3     20  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       9      0  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       9      5  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       9     20  0.000e+00    ok (0 floats differ)
mul_mat(K view, q)        1      0  1.411e-07    ok (3 floats differ)
mul_mat(K view, q)        1      5  1.693e-07    ok (19 floats differ)
mul_mat(K view, q)        1     20  1.150e-07    ok (59 floats differ)
mul_mat(K view, q)        3      0  1.230e-07    ok (23 floats differ)
mul_mat(K view, q)        3      5  1.230e-07    ok (68 floats differ)
mul_mat(K view, q)        3     20  1.150e-07    ok (203 floats differ)
mul_mat(K view, q)        9      0  1.216e-07    ok (247 floats differ)
mul_mat(K view, q)        9      5  2.432e-07    ok (382 floats differ)
mul_mat(K view, q)        9     20  2.299e-07    ok (796 floats differ)
mul_mat(cont(K), q)       1      0  1.411e-07    ok (3 floats differ)
mul_mat(cont(K), q)       1      5  1.693e-07    ok (19 floats differ)
mul_mat(cont(K), q)       1     20  1.150e-07    ok (59 floats differ)
mul_mat(cont(K), q)       3      0  1.230e-07    ok (23 floats differ)
mul_mat(cont(K), q)       3      5  1.230e-07    ok (68 floats differ)
mul_mat(cont(K), q)       3     20  1.150e-07    ok (203 floats differ)
mul_mat(cont(K), q)       9      0  1.216e-07    ok (247 floats differ)
mul_mat(cont(K), q)       9      5  2.432e-07    ok (382 floats differ)
mul_mat(cont(K), q)       9     20  2.299e-07    ok (796 floats differ)
mul_mat(V view, kq)       1      0  0.000e+00    ok (0 floats differ)
mul_mat(V view, kq)       1      5  7.795e-08    ok (143 floats differ)
mul_mat(V view, kq)       1     20  1.087e-07    ok (180 floats differ)
mul_mat(V view, kq)       3      0  6.153e-08    ok (272 floats differ)
mul_mat(V view, kq)       3      5  1.508e-07    ok (472 floats differ)
mul_mat(V view, kq)       3     20  1.479e-07    ok (601 floats differ)
mul_mat(V view, kq)       9      0  6.327e-08    ok (391 floats differ)
mul_mat(V view, kq)       9      5  1.028e-07    ok (527 floats differ)
mul_mat(V view, kq)       9     20  2.327e-07    ok (1759 floats differ)
FAIL - 3 of 45 combinations disagree with the CPU

After the fix: all combinations match the CPU output

device: CUDA0 (Tesla T4)
op                       Tn n_past  max rel      verdict
cpy K -> k_dst view       1      0  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       1      5  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       1     20  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       3      0  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       3      5  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       3     20  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       9      0  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       9      5  0.000e+00    ok (0 floats differ)
cpy K -> k_dst view       9     20  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       1      0  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       1      5  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       1     20  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       3      0  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       3      5  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       3     20  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       9      0  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       9      5  0.000e+00    ok (0 floats differ)
cpy V -> v_dst view       9     20  0.000e+00    ok (0 floats differ)
mul_mat(K view, q)        1      0  1.411e-07    ok (3 floats differ)
mul_mat(K view, q)        1      5  1.693e-07    ok (19 floats differ)
mul_mat(K view, q)        1     20  1.150e-07    ok (59 floats differ)
mul_mat(K view, q)        3      0  1.230e-07    ok (23 floats differ)
mul_mat(K view, q)        3      5  1.230e-07    ok (68 floats differ)
mul_mat(K view, q)        3     20  1.150e-07    ok (203 floats differ)
mul_mat(K view, q)        9      0  1.216e-07    ok (247 floats differ)
mul_mat(K view, q)        9      5  2.432e-07    ok (382 floats differ)
mul_mat(K view, q)        9     20  2.299e-07    ok (796 floats differ)
mul_mat(cont(K), q)       1      0  1.411e-07    ok (3 floats differ)
mul_mat(cont(K), q)       1      5  1.693e-07    ok (19 floats differ)
mul_mat(cont(K), q)       1     20  1.150e-07    ok (59 floats differ)
mul_mat(cont(K), q)       3      0  1.230e-07    ok (23 floats differ)
mul_mat(cont(K), q)       3      5  1.230e-07    ok (68 floats differ)
mul_mat(cont(K), q)       3     20  1.150e-07    ok (203 floats differ)
mul_mat(cont(K), q)       9      0  1.216e-07    ok (247 floats differ)
mul_mat(cont(K), q)       9      5  2.432e-07    ok (382 floats differ)
mul_mat(cont(K), q)       9     20  2.299e-07    ok (796 floats differ)
mul_mat(V view, kq)       1      0  0.000e+00    ok (0 floats differ)
mul_mat(V view, kq)       1      5  7.795e-08    ok (143 floats differ)
mul_mat(V view, kq)       1     20  1.087e-07    ok (180 floats differ)
mul_mat(V view, kq)       3      0  6.153e-08    ok (272 floats differ)
mul_mat(V view, kq)       3      5  1.508e-07    ok (472 floats differ)
mul_mat(V view, kq)       3     20  1.479e-07    ok (601 floats differ)
mul_mat(V view, kq)       9      0  6.327e-08    ok (391 floats differ)
mul_mat(V view, kq)       9      5  1.028e-07    ok (527 floats differ)
mul_mat(V view, kq)       9     20  2.327e-07    ok (1759 floats differ)
PASS - 0 of 45 combinations disagree with the CPU
example translation (deu_Latn → eng_Latn)

Source sentence:

Welches Sicherheitsrisiko von Russland ausgeht, das wird in der Bevölkerung unterschiedlich bewertet.

Before the fix (output loops):

The security risk to which security risks to which security risks to which ...

After the fix:

The security risks posed by Russia are assessed differently by the population.

@devYRPauli
devYRPauli requested a review from ggerganov as a code owner October 1, 2026 16:30
@devYRPauli

Copy link
Copy Markdown
Contributor Author

Thanks for testing this on real hardware and for sharing the repro cases. I added both test_cpy cases in 0e2f7fe54 after the existing // strided dst cases. The gap in the existing coverage is that those strided-destination cases use a contiguous source, so they do not reach the transposed CUDA kernel. Your cases permute the source, which matches the transposed V-cache write path you described.

On the T4, the filtered run goes from 2/4 without the fix, with ERR 1.903 for f32 and 1.974 for f16, to 4/4 with the fix. On my Mac, the two new cases pass on Metal; the full dst_alloc filter is 4/4 and the full -o CPY run is 199/199. BLAS reports these cases as unsupported, so the local result here only confirms the new cases behave correctly on Metal against the CPU reference.

I'd also be interested to know whether you see the same before/after result on the GTX 1650.

@ggerganov ggerganov left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ggml-org/ggml-cuda I think this is a valid fix.

An alternative solution would be to allow src1 to not be contiguous and update the kernels to take into account the dst strides. Not sure if it is worth.

@github-actions github-actions Bot added the testing Everything test related label Oct 1, 2026
@devYRPauli
devYRPauli force-pushed the fix/cuda-cpy-transposed-noncontiguous-dst branch from 0e2f7fe to f8133c3 Compare October 2, 2026 14:12
The existing strided dst tests use a contiguous src, so they do not
exercise the CUDA transposed cpy path with a strided destination. These
new cases permute the src before copying into a view of a larger buffer,
matching the layout used by a transposed V cache write.

The cases were suggested by Jaydeep505 during review. On a T4, both f32
and f16 fail without the fix and pass with it.

Assisted-by: Claude Opus 5.5
@am17an
am17an merged commit 134b2bb into ggml-org:master Oct 2, 2026
1 check passed
edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Oct 4, 2026
Wizard815 pushed a commit to Wizard815/mx-llama.cpp-Rocm10 that referenced this pull request Oct 6, 2026
Graffioh added a commit to Graffioh/lucebox-hub that referenced this pull request Oct 11, 2026
…ation

ggml_cuda_cpy chose the tiled transpose kernel from the source layout alone.
That kernel writes the destination densely and ignores its strides, so a
contiguous [1, n, m] source (ne00 == 1 also gives nb01 == element size)
copied into a strided view landed in the wrong elements and left the right
ones unwritten. The PFlash Qwen3.5 scorer hits exactly this when its chunked
logits copy ends on a one-key-wide chunk (S % key_chunk == 1, e.g. a
65,537-token prompt): the unwritten memory held NaN and the request failed
with non-finite scores.

Require a contiguous src1 for the transpose path, as upstream llama.cpp does
(134b2bb756, ggml-org/llama.cpp#27663). test_cpy_strided_dst runs the
scorer's chunked-copy pattern and the bare [1, n, m] copy on the GPU backend
against a host reference and the CPU backend, for key counts with remainders
0, 1, 2 and chunk-1, and keeps the legitimate transpose fast path covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Graffioh added a commit to Graffioh/lucebox-hub that referenced this pull request Oct 13, 2026
…ation

ggml_cuda_cpy chose the tiled transpose kernel from the source layout alone.
That kernel writes the destination densely and ignores its strides, so a
contiguous [1, n, m] source (ne00 == 1 also gives nb01 == element size)
copied into a strided view landed in the wrong elements and left the right
ones unwritten. The PFlash Qwen3.5 scorer hits exactly this when its chunked
logits copy ends on a one-key-wide chunk (S % key_chunk == 1, e.g. a
65,537-token prompt): the unwritten memory held NaN and the request failed
with non-finite scores.

Require a contiguous src1 for the transpose path, as upstream llama.cpp does
(134b2bb756, ggml-org/llama.cpp#27663). test_cpy_strided_dst runs the
scorer's chunked-copy pattern and the bare [1, n, m] copy on the GPU backend
against a host reference and the CPU backend, for key counts with remainders
0, 1, 2 and chunk-1, and keeps the legitimate transpose fast path covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
davide221 added a commit to Luce-Org/lucebox that referenced this pull request Oct 14, 2026
…request probes, strict budget selection, chat views, cache-aware admission, fallback (#746)

* fix(ggml-cuda): take the transpose copy only into a contiguous destination

ggml_cuda_cpy chose the tiled transpose kernel from the source layout alone.
That kernel writes the destination densely and ignores its strides, so a
contiguous [1, n, m] source (ne00 == 1 also gives nb01 == element size)
copied into a strided view landed in the wrong elements and left the right
ones unwritten. The PFlash Qwen3.5 scorer hits exactly this when its chunked
logits copy ends on a one-key-wide chunk (S % key_chunk == 1, e.g. a
65,537-token prompt): the unwritten memory held NaN and the request failed
with non-finite scores.

Require a contiguous src1 for the transpose path, as upstream llama.cpp does
(134b2bb756, ggml-org/llama.cpp#27663). test_cpy_strided_dst runs the
scorer's chunked-copy pattern and the bare [1, n, m] copy on the GPU backend
against a host reference and the CPU backend, for key counts with remainders
0, 1, 2 and chunk-1, and keeps the legitimate transpose fast path covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(pflash): Qwen3.5-0.8B drafter scorer with strict selection, chat views, request probe and resumable scoring sessions

PFlash compresses a long prompt by scoring it with a small drafter and
serving the target only the spans that matter. This commit holds the
scorer and everything the served view is built from.

Drafter and selection:
- The drafter is Qwen3.5-0.8B: blocks 0..14 run as a prefix and block 15's
  NoPE Q/K attention mass from the query window scores every key. Optional
  PFLASH_SCORING_HEAD_GGUF and PFLASH_SEGMENT_PROBE_GGUF companions are
  validated against an explicit contract and fail closed. The Qwen3-0.6B
  scorer is removed; src/pflash/ owns the pipeline and the IPC gains
  compress2/compress3.
- Strict selection (PFLASH_SELECT_MODE, PFLASH_SELECT_SCORE) keeps the
  structurally required spans and stops at the token budget. The scorer
  query comes from the latest user turn or the pflash_query field;
  pflash_required pins client spans; PFLASH_TRACE_PATH writes a record per
  compression.
- The causal mask is built in the graph, head+tail query windows
  (PFLASH_SELECT_QUERY_HEAD) and line-aligned splits are added, and a fold
  selection (PFLASH_SELECT_STRATEGY=fold) stays an off-by-default
  experiment with pflash_fold_replay.

Query:
- A request probe (PFLASH_REQUEST_PROBE_GGUF, PFLASH_SELECT_QUERY_PROBE=1)
  picks the scorer query from the human user messages, also on the chat
  parser. An optional stage 2 look-back (PFLASH_REQUEST_STAGE2_GGUF) and
  relative query candidates with a verbatim pin (PFLASH_QUERY_CANDIDATES,
  PFLASH_QUERY_PIN) refine it.
- An identifier query stays as an evaluation reference arm, the server
  validates the selection config at startup, and PFLASH_VIEW_TRACE_PATH
  records the served view with its provenance. Parity and capture scripts
  for the probes are included.

Chat views and admission:
- Per conversation the server keeps the prompt it served and, on a
  follow-up, appends a small new turn verbatim, recalls dropped passages
  the new turn needs and rebuilds a drifted view (PFLASH_CHAT_VIEW,
  PFLASH_CHAT_RECALL, PFLASH_CHAT_COMPRESS_NEW_TOKENS,
  PFLASH_CHAT_REBUILD_*).
- Cache-aware admission (PFLASH_ADMISSION=cache) compresses only when the
  target would otherwise prefill a threshold's worth of uncached droppable
  tokens, and PFLASH_ARRIVE=1 compresses just a large uncached chunk.

Scoring sessions:
- The drafter keeps per-conversation scoring sessions
  (PFLASH_DRAFTER_SESSIONS), so a shared prefix is scored once. Resume is
  exact by construction (the fresh call's ubatch and key-chunk partition,
  also for the query step), sessions are copied to host RAM across a
  drafter release (plain host memory by default,
  PFLASH_SESSION_OFFLOAD_PINNED=1 for pinned) and their capacity is
  clamped to the engine and drafter context.
- pflash_file_identity reads st_mtime on Windows, where MSVC's struct stat
  has no st_mtim (the identity is only compared on the machine that wrote
  it).

Unit tests cover selection, fold, request probe, stage 2, query
candidates, identifier query, scoring resume, session offload, the causal
mask and the drafter IPC; test_server_unit covers the server side.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(server): keep PFlash tool history raw with safe fallback and a context cap

Serve tool sessions raw under cache-aware auto admission. The opt-in
PFLASH_AGENT_PASTE switch compresses only a large newest user paste and
continues the resulting view while preserving history and tool outputs.

Fall back to the raw prompt on compression failure when it fits, with
telemetry and an optional fail-closed mode. Drop matching compressed chat
views after successful raw fallback so later requests cannot reuse stale
selections; preserve views when the request is refused. Includes a
multi-turn regression for fallback, retries and fail-closed preservation.

Apply relevance-spread fallback only to whole-prompt plans and cap PFlash
context at 225280 tokens. Include policy, admission and context tests and
README documentation for coding-agent sessions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(pflash): serve the measured release profile by default with a trained head

With a trained scoring head (PFLASH_SCORING_HEAD_GGUF) and compression on,
every PFlash setting left unset now takes the release profile the PFlash v2
results were measured with: the 16384 threshold, the curve
16384:0.315 32768:0.270 65536:0.270 120000:0.225, budget selection over
probe segments with density scores, the request-probe query with one
candidate and a 512-token pin, cache admission, arrival scoring and the
0.11 spread fallback. A run needs only the model files.

The profile lives next to the cluster defaults in launch_profiles.h and
installs the same way: a variable that is already set keeps its value, and
an explicit --prefill-threshold, --prefill-keep-ratio or --prefill-curve
wins. The query defaults step aside for experiment arms they cannot combine
with. Without a head the built-in defaults stay; before, a head without
PFLASH_SELECT_MODE failed every request. --prefill-skip-park stays opt-in.

The Docker entrypoint forwarded the old 0.05 ratio and 32000 threshold on
every PFlash run; it now passes them only when LUCE_PREFILL_KEEP or
LUCE_PREFILL_THRESHOLD is set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(pflash): bound PFlash prompts by --max-ctx instead of a fixed cap

How long a prompt the drafter can score depends on the card and on the
target resident beside it, so the 225,280-token constant measured on one
R9700 setup did not fit other setups. With compression on, --max-ctx is
now the longest raw prompt PFlash takes. A longer prompt gets a 400 in
OpenAI's prompt-overflow wording, which clients use to compact. A prompt
that fits but leaves no room for its reply is still compressed. If the
drafter runs out of memory, the request falls back to full prefill as
before.

The README gives the measured R9700 setting: with the 27B IQ4_XS target
resident, --max-ctx 204800 holds a 204K-token prompt at a 30.6 GiB peak
of 31.9 GiB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: mrciffa <[email protected]>
nicheng251 added a commit to nicheng251/bonsai-turboquant-llama.cpp that referenced this pull request Oct 23, 2026
Port five small upstream fixes that apply to code this fork ships:

- fattn-vec: sync the warp at the end of the VKQ loop (ggml-org#30573). The next
  iteration's KQ write reused the shared buffer while other lanes were
  still reading it.
- cpy: the transposed fast path requires a contiguous destination (ggml-org#27663).
  It wrote to a non-contiguous dst as if it were dense.
- llama-kv-cache: only upload k_rot when the tensor has a buffer (ggml-org#27967).
  An unquantized K cache has no k_rot buffer and context shift crashed.
- ggml_permute: keep dims and strides 64-bit (ggml-org#29227). The int temporaries
  truncated large tensors.
- convert: run contiguous conversions four elements per thread (ggml-org#29155).

Verified: FLASH_ATTN_EXT turbo 25/25, 27B Bonsai PTQ1_0 model smoke with
q8_0 K + turbo3 V (prefill 547 tok/s, decode 31.2 tok/s at 2K; 30.0 at 17.4K).

The stock q8_0/q8_0 long-sweep crash is not caused by the WAR hazard: it
still aborts after 361 cases with this fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants