Repository navigation
metal: custom KV set_rows/cpy for TBQ3_0/TBQ4_0/Q4_POLAR; device-gated FA dequant - #34
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Triage (#11386 M1): NOT superseded — keeping open. This adds Metal Two follow-ups before it can land, both out of scope for the M1 pointer reconciliation:
Leaving open and tracking separately. |
…equant by device Add Metal quantize/dequantize helpers plus SET_ROWS and CPY (f32->q, q->f32/f16) kernels for TBQ3_0, TBQ4_0 and Q4_POLAR, and advertise them in ggml_metal_device_supports_op, so these KV cache types can be written and read on Metal. Flash attention dequant: TBQ3_0/TBQ4_0/Q4_POLAR are scored natively by the CPU FA kernel (vec_dot/to_float traits), so they are no longer cast F32->F16 unconditionally. llama_context now probes each offloaded KV layer's device with FLASH_ATTN_EXT on the requested cache types and sets cparams.fa_dequant_kv only when a non-CPU device cannot run FA on them natively (e.g. Metal). The always-dequant set (QJL1_256/TBQ3_TCQ K, Q4_POLAR V) is unchanged, so CPU/Android graphs get no extra casts. test-backend-ops: SET_ROWS cases for the three types and Q4_POLAR->F32 CPY coverage. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6e83e4b to
f12871e
Compare
Summary
Rebased onto
eliza/develop-pin-ea8b3f2(single commit on top of c6e523b).SET_ROWS(i32/i64) andCPY(f32→q, q→f32/f16) kernels forTBQ3_0,TBQ4_0,Q4_POLAR; advertised inggml_metal_device_supports_op(CPY/CONT and SET_ROWS only). Conflict with develop-pin'squantize_iq4_nl_full/kernel_cpy_f32_iq4_nl_fullresolved by keeping both.llama_contextprobes each offloaded KV layer's (non-CPU) device with aFLASH_ATTN_EXTon the requested cache types and setscparams.fa_dequant_kvonly when that device lacks native FA support (e.g. Metal). The existing always-dequant set (QJL1_256/TBQ3_TCQ K, Q4_POLAR V) is unchanged. CPU-only,--no-kv-offloadand CPU-assigned layers never take the extra cast.Test evidence (Apple M4 Max, Metal)
test-backend-ops -b MTL0 -o SET_ROWS: 147/147 passed (12 new tbq3_0/tbq4_0/q4_polar cases OK vs CPU)test-backend-ops -b MTL0 -o CPY: 99/99 passed (f32↔tbq3_0/tbq4_0/q4_polar OK)test-backend-ops -b MTL0 -o FLASH_ATTN_EXT: 4752/4752 passedtest-backend-ops -b MTL0 -o MUL_MAT -p "type_a=(f32|f16|bf16|q4_0|q4_1|q5_0|q5_1|q8_0|q2_K|q3_K|q4_K|q5_K|q6_K|iq4_nl|iq4_xs),": 868/868 passed. (Unfiltered MUL_MAT aborts onq1_0_g32— Metal mul_mv has no case for it; pre-existing, not touched here.)llama-completionwith eliza-1-2b-32k,-fa on -ctk/-ctv tbq3_0andtbq4_0,-ngl 99: Metal logs the probe ("device MTL0 has no native flash attention … dequantizing") and outputs "Paris."; graph nodes 1491.GGML_METAL=OFF): builds; same run with tbq3_0 shows no probe/dequant (graph nodes 1467, i.e. no cast nodes) and outputs "Paris."🤖 Generated with Claude Code