mirror of
https://github.com/ollama/ollama.git
synced 2026-04-17 19:54:03 +02:00
* bench: add prompt calibration, context size flag, and NumCtx reporting Add --num-ctx flag to set context size, and report NumCtx in model info header. Calibrate tokens-per-word ratio during warmup using actual tokenization metrics from the model, replacing the fixed 1.3 heuristic. This produces more accurate prompt token counts for --prompt-tokens. Also add fetchContextLength() to query running model context via /api/ps. * integration: improve vision test robustness and add thinking tests Add skipIfNoVisionOverride() to skip vision tests when OLLAMA_TEST_MODEL is set to a non-vision model. Add Think:false to context exhaustion test to prevent thinking models from using all context before the test can measure it. Add third test image (ollama homepage) and replace OCR test with ImageDescription test using it. Relax match strings for broader model compatibility. Add TestThinkingEnabled and TestThinkingSuppressed to verify thinking output and channel tag handling. * gemma4: add Gemma 4 GGML model support Add full Gemma 4 model family support (E2B, E4B, 26B MoE, 31B Dense) for the GGML backend including text, vision, converter, parser, and renderer. Text model features: - Sliding window + full attention with per-layer patterns - KV sharing across layers with donor map - Per-layer embeddings (PLE) with learned projections - MoE routing with RMSNorm + learned scale - Proportional RoPE with freq_factors for global attention - Final logit softcapping Vision model features: - SigLIP vision encoder with 2D RoPE - ClippableLinear with input/output clamping via packed v.clamp_data - Adaptive average pooling with nMerge kernel - Multi-modal projection with unweighted RMSNorm Converter: - Safetensors to GGUF with vision tensor renaming - Fused MoE gate_up_proj splitting - Vision patch embedding reshape (HF to Conv2D layout) - Packed clamp data tensor for ClippableLinear bounds - Proportional RoPE freq_factors generation Also includes: - BackendGet() on ml.Tensor for reading weight tensor data - Q6_K CUDA get_rows kernel support - MoE-aware ffn_down quantization layer counting - Gemma4 parser with tool calling and thinking support - Gemma4 renderer with structured tool format - Architecture-based auto-detection of renderer/parser/stop tokens - Integration test gemma4 model list additions * gemma4: add audio support with USM conformer encoder Add audio encoding for Gemma 4 using the USM conformer architecture: - Converter: audio tensor mapping, SSCP/conformer/embedder name replacements, softplus repacker for per_dim_scale, F32 enforcement for conv weights - GGML backend: Conv1DDW and PadExt tensor ops - Audio encoder: SSCP Conv2D, 12 conformer blocks (FFW + block-local attention with relative position embeddings + LightConv1d + FFW), output projection, audio-to-text embedding projector - Audio preprocessing: WAV decode, mel spectrogram, FFT (pure Go) - Model wiring: WAV detection, audio token handling, unified PostTokenize Correctly transcribes "why is the sky blue" from test audio. * integration: add gemma4 audio tests including OpenAI API coverage Test audio transcription and response via the Ollama native API, plus two new tests exercising the OpenAI-compatible endpoints: - /v1/audio/transcriptions (multipart form upload) - /v1/chat/completions with input_audio content type All tests use capability checks and skip models without audio support. * gemma4: add OpenAI audio API support and capability detection - Add CapabilityAudio and detect from audio.block_count in GGUF - Add /v1/audio/transcriptions endpoint with TranscriptionMiddleware - Add input_audio content type support in /v1/chat/completions - Add TranscriptionRequest/Response types in openai package * gemma4: add audio input support for run command - /audio toggle in interactive mode for voice chat - Platform-specific microphone recording (AVFoundation on macOS, PulseAudio/ALSA on Linux, WASAPI on Windows) - Space to start/stop recording, automatic chunking for long audio * gemma4: add transcribe command (ollama transcribe MODEL) - Interactive mode with readline prompt and slash commands - Non-interactive mode for piped audio or record-until-Ctrl+C - Chunked streaming transcription for long recordings - Word-wrapped output matching run command style * gemma4: add parser, renderer, and integration test plumbing * gemma4: fix renderer to emit BOS token * gemma4: add OpenAI audio transcription API and input_audio support * gemma4: update converter for new weight drop naming * gemma4: add per_expert_scale to MoE router and fix moe_intermediate_size config * gemma4: rewrite renderer to match HF Jinja2 template exactly Fix 8 bugs found by building 55 reference tests verified against the HF Jinja2 chat template (VERIFY_JINJA2=1 shells out to Python): - Tool responses use separate <|turn>tool turns (not inline tags) - Tool calls emitted before content in assistant messages - Thinking content stripped from assistant history (strip_thinking) - User, tool, and system content trimmed (template does | trim) - Empty system message still emits system turn (check role, not content) - Nested object properties rendered recursively with required field - Array items specification rendered for array-type properties - OBJECT/ARRAY type-specific rendering comma logic matches template Also adds Required field to api.ToolProperty for nested object schemas, replaces old gemma4_test.go with comprehensive gemma4_reference_test.go, and commits the Jinja2 template as testdata for verification. * gemma4: fix MoE fused gate_up split and multiline tool-call arg parsing - Text MoE: split `ffn_gate_up_exps` into contiguous `[gate|up]` halves instead of stride-2 slices. - Parser: escape control characters in `<|"|>...<|"|>` string literals when converting tool-call args to JSON. - Fixes warnings like `invalid character '\n' in string literal` for multiline tool arguments. - Add Gemma4 parser regressions for multiline tool-call args and `gemma4ArgsToJSON`. * cmd: simplify audio input to dropped file attachments * gemma4: use full SWA memory for better cache reuse * gemma4: initialize clamps after backend load * convert: align gemma4 audio tensor renames with llama.cpp * Remove redundant comments in gemma4 vision model * Format Gemma4 MoE block field alignment * use 4096 kvcache.NewSWAMemCache * convert: support new Gemma4 audio_tower tensor naming (#15221) Co-authored-by: jmorganca <jmorganca@gmail.com> * fix integration test defaults for audio * review comments and lint fixes * remove unused audio/video files --------- Co-authored-by: jmorganca <jmorganca@gmail.com>
122 lines
5.5 KiB
Diff
122 lines
5.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Hiltgen <daniel@ollama.com>
|
|
Date: Fri, 20 Mar 2026 18:50:38 -0700
|
|
Subject: [PATCH] CUDA get_rows q6_k support
|
|
|
|
---
|
|
ggml/src/ggml-cuda/getrows.cu | 80 ++++++++++++++++++++++++++++++++-
|
|
ggml/src/ggml-cuda/ggml-cuda.cu | 1 +
|
|
2 files changed, 80 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/ggml/src/ggml-cuda/getrows.cu b/ggml/src/ggml-cuda/getrows.cu
|
|
index 2fab33243..dc5c4f57a 100644
|
|
--- a/ggml/src/ggml-cuda/getrows.cu
|
|
+++ b/ggml/src/ggml-cuda/getrows.cu
|
|
@@ -155,6 +155,81 @@ static void get_rows_cuda_float(
|
|
s10, s11, s12/*, s13*/);
|
|
}
|
|
|
|
+// Specialized GET_ROWS kernel for Q6_K — the k_get_rows template doesn't work for K-quants
|
|
+// because they lack the simple dequantize_kernel_t (float2) interface.
|
|
+// Based on dequantize_block_q6_K from convert.cu with row-selection logic added.
|
|
+template<typename dst_t>
|
|
+static __global__ void k_get_rows_q6_K(
|
|
+ const void * __restrict__ src0, const int32_t * __restrict__ src1, dst_t * __restrict__ dst,
|
|
+ const int64_t ne00,
|
|
+ const int64_t ne11, const int64_t ne12,
|
|
+ const size_t s1, const size_t s2, const size_t s3,
|
|
+ const size_t nb01, const size_t nb02, const size_t nb03,
|
|
+ const size_t s10, const size_t s11, const size_t s12) {
|
|
+
|
|
+ const int64_t i10 = blockIdx.x; // row index into src1
|
|
+ const int64_t z = blockIdx.z;
|
|
+ const int64_t i11 = z / ne12;
|
|
+ const int64_t i12 = z % ne12;
|
|
+
|
|
+ const int i01 = src1[i10*s10 + i11*s11 + i12*s12];
|
|
+
|
|
+ dst_t * dst_row = dst + i10*s1 + i11*s2 + i12*s3;
|
|
+ const char * src0_row = (const char *)src0 + i01*nb01 + i11*nb02 + i12*nb03;
|
|
+
|
|
+ const int64_t nb = ne00 / QK_K; // number of Q6_K blocks per row
|
|
+
|
|
+ // blockIdx.y iterates over Q6_K blocks within the row
|
|
+ for (int64_t iblk = blockIdx.y; iblk < nb; iblk += gridDim.y) {
|
|
+ const block_q6_K * x = (const block_q6_K *)src0_row + iblk;
|
|
+
|
|
+ // Same dequantization as dequantize_block_q6_K (assumes 64 threads)
|
|
+ const int64_t tid = threadIdx.x;
|
|
+ const int64_t ip = tid / 32; // 0 or 1
|
|
+ const int64_t il = tid - 32*ip; // 0..31
|
|
+ const int64_t is = 8*ip + il/16;
|
|
+
|
|
+ const int64_t y_offset = iblk * QK_K + 128*ip + il;
|
|
+
|
|
+ const float d = x->d;
|
|
+ const uint8_t * ql = x->ql + 64*ip + il;
|
|
+ const uint8_t qh = x->qh[32*ip + il];
|
|
+ const int8_t * sc = x->scales + is;
|
|
+
|
|
+ if (y_offset + 0 < ne00) dst_row[y_offset + 0] = ggml_cuda_cast<dst_t>(d * sc[0] * ((int8_t)((ql[ 0] & 0xF) | (((qh >> 0) & 3) << 4)) - 32));
|
|
+ if (y_offset + 32 < ne00) dst_row[y_offset + 32] = ggml_cuda_cast<dst_t>(d * sc[2] * ((int8_t)((ql[32] & 0xF) | (((qh >> 2) & 3) << 4)) - 32));
|
|
+ if (y_offset + 64 < ne00) dst_row[y_offset + 64] = ggml_cuda_cast<dst_t>(d * sc[4] * ((int8_t)((ql[ 0] >> 4) | (((qh >> 4) & 3) << 4)) - 32));
|
|
+ if (y_offset + 96 < ne00) dst_row[y_offset + 96] = ggml_cuda_cast<dst_t>(d * sc[6] * ((int8_t)((ql[32] >> 4) | (((qh >> 6) & 3) << 4)) - 32));
|
|
+ }
|
|
+}
|
|
+
|
|
+template<typename dst_t>
|
|
+static void get_rows_cuda_q6_K(
|
|
+ const void * src0_d, const int32_t * src1_d, dst_t * dst_d,
|
|
+ const int64_t ne00, const size_t nb01, const size_t nb02, const size_t nb03,
|
|
+ const int64_t ne10, const int64_t ne11, const int64_t ne12, const size_t nb10, const size_t nb11, const size_t nb12,
|
|
+ const size_t nb1, const size_t nb2, const size_t nb3,
|
|
+ cudaStream_t stream) {
|
|
+ const int64_t nb_blocks = ne00 / QK_K;
|
|
+ const dim3 block_dims(64, 1, 1);
|
|
+ const dim3 block_nums(ne10, MIN(nb_blocks, (int64_t)UINT16_MAX), MIN(ne11*ne12, (int64_t)UINT16_MAX));
|
|
+
|
|
+ const size_t s1 = nb1 / sizeof(dst_t);
|
|
+ const size_t s2 = nb2 / sizeof(dst_t);
|
|
+ const size_t s3 = nb3 / sizeof(dst_t);
|
|
+
|
|
+ const size_t s10 = nb10 / sizeof(int32_t);
|
|
+ const size_t s11 = nb11 / sizeof(int32_t);
|
|
+ const size_t s12 = nb12 / sizeof(int32_t);
|
|
+
|
|
+ k_get_rows_q6_K<<<block_nums, block_dims, 0, stream>>>(
|
|
+ src0_d, src1_d, dst_d,
|
|
+ ne00, ne11, ne12,
|
|
+ s1, s2, s3,
|
|
+ nb01, nb02, nb03,
|
|
+ s10, s11, s12);
|
|
+}
|
|
+
|
|
template <typename dst_t>
|
|
static void ggml_cuda_get_rows_switch_src0_type(
|
|
const void * src0_d, const ggml_type src0_type, const int32_t * src1_d, dst_t * dst_d,
|
|
@@ -199,8 +274,11 @@ static void ggml_cuda_get_rows_switch_src0_type(
|
|
get_rows_cuda_q<QK8_0, QR8_0, dequantize_q8_0>(src0_d, src1_d, dst_d,
|
|
ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
break;
|
|
+ case GGML_TYPE_Q6_K:
|
|
+ get_rows_cuda_q6_K(src0_d, src1_d, dst_d,
|
|
+ ne00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb1, nb2, nb3, stream);
|
|
+ break;
|
|
default:
|
|
- // TODO: k-quants
|
|
GGML_ABORT("%s: unsupported src0 type: %s\n", __func__, ggml_type_name(src0_type));
|
|
break;
|
|
}
|
|
diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu
|
|
index 5c9dfd032..b8ed3709b 100644
|
|
--- a/ggml/src/ggml-cuda/ggml-cuda.cu
|
|
+++ b/ggml/src/ggml-cuda/ggml-cuda.cu
|
|
@@ -4693,6 +4693,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g
|
|
case GGML_TYPE_Q5_0:
|
|
case GGML_TYPE_Q5_1:
|
|
case GGML_TYPE_Q8_0:
|
|
+ case GGML_TYPE_Q6_K:
|
|
return true;
|
|
default:
|
|
return false;
|