Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Update llama.cpp to b10052 (b2dd28a) (#1021)
Davide Eynard3693f691e9d3
diff --git a/docs/skills/llamafile/building.md b/docs/skills/llamafile/building.mdindex 348361a6..360478bf 100644--- a/docs/skills/llamafile/building.md+++ b/docs/skills/llamafile/building.md@@ -157,11 +157,94 @@ The `zipalign` tool handles bundling. Embedded assets are accessible at runtime## GPU Support-GPU acceleration (CUDA/ROCm) uses dynamic loading:+GPU acceleration (CUDA/ROCm/Vulkan) uses dynamic loading:- Shared libraries (.so/.dll) are not linked at compile time- Libraries are loaded at runtime if available- Can be bundled into executables using zipalign+### Building the GPU dylibs++The host `make` does **not** build the GPU backends. They are separate,+prebuilt shared libraries produced by per-backend scripts in `llamafile/`:++- `llamafile/cuda.sh` → `ggml-cuda.so` (needs `nvcc`; `CUDA_PATH`, default `/usr/local/cuda`)+- `llamafile/rocm.sh` → `ggml-rocm.so` (needs `hipcc`; `ROCM_PATH`, default `/opt/rocm`)+- `llamafile/vulkan.sh` → `ggml-vulkan.so` (needs `glslc` + SPIR-V headers + libvulkan)+- `.bat` / `*_parallel.bat` variants build the Windows DLLs.++`make_dylibs.sh` (if present) just wraps these for a release (writes to a+versioned `gpulibs/<VERSION>/`, passes `--clean`, and `--minimize-size` for+CUDA). **Run the scripts one at a time**, always with `--clean` — a stale+`~/.cache/llamafile-{cuda,rocm,vulkan}-build` is the usual "first build fails"+cause (leftover objects that reference symbols upstream removed, e.g. the b10052+CUDA split-buffer removal). `cuda.sh`/`rocm.sh` share `build-functions.sh`;+`vulkan.sh` is standalone.++### Verifying a GPU build actually succeeded (do not trust "Successfully built")++The parallel compile launches each `nvcc`/`hipcc`/`glslc` in the background.+`compile_gpu_sources_parallel` (cuda/rocm) now reaps each job and fails loudly,+but `vulkan.sh`'s shader loops do **not** yet check per-job status — a single+failed source can still be dropped while the link proceeds and prints+"Successfully built" with a silently incomplete `.so`. So always confirm, don't+assume:++```bash+llamafile/cuda.sh --clean --output /tmp/ggml-cuda.so --minimize-size 2>&1 | tee /tmp/b.log+grep -c 'error:' /tmp/b.log # must be 0+grep 'Linking' /tmp/b.log # object count should match the source count+```++If a source fails to compile, fix the root cause (a new upstream cuBLAS call+missing from TinyBLAS is a recurring one — see `update_llamacpp.md`), never let+the "success" line stand in for a green build.++### Vulkan speed paths depend on the glslc/SDK version++`vulkan.sh` probes the build host's `glslc` for shader extensions+(coopmat, coopmat2, integer-dot, bf16, fp4/fp8) — mirroring upstream's+`ggml-vulkan/CMakeLists.txt` `test_shader_extension_support`. Each probe that+fails drops that acceleration pipeline from the shipped dylib (correct output,+just slower on hardware that supports it). Distro `shaderc` (Ubuntu, SteamOS)+is typically **too old** — it doesn't know `GL_EXT_integer_dot_product`,+`GL_EXT_bfloat16`, `GL_NV_cooperative_matrix2`, and can't target+`--target-env=vulkan1.4`. For a full-featured release Vulkan dylib, build on a+host with a recent **LunarG Vulkan SDK** (1.4.x); after installing, `source`+its `setup-env.sh` so `vulkan.sh` picks up the SDK's `glslc`, then re-run the+build and confirm the probes now print "supported". Keep `vulkan.sh`'s probe+list in sync with the CMakeLists (it must probe all seven feature tests).++### CUDA `--minimize-size` drops IQ-quant kernels (CPU fallback)++The release CUDA dylib is built with `--minimize-size`, which (among the size+options) passes `-DGGML_CUDA_NO_IQ_QUANTS`. That compiles out every IQ-quant+CUDA path — the MMQ/MMVQ matmul kernels and the fp16/fp32 dequant converters+in `convert.cu`, `mmq.cu`, `mmvq.cu`, and the `f32→iq4_nl` copy in `cpy.cu`.+The payoff is a much smaller `.so`; the cost is that it cannot run IQ-quantized+tensors on the GPU.++`ggml_backend_cuda_device_supports_op` is guarded by the same macro: the IQ+cases in the `MUL_MAT`/`MUL_MAT_ID` and `CPY` switches sit inside+`#ifndef GGML_CUDA_NO_IQ_QUANTS`. So a minimized build honestly reports those+ops unsupported and the scheduler runs them on the CPU backend — correct+output, just slower for the IQ layers. **Without that guard the op is+dispatched to a kernel that was never compiled and aborts at+`GGML_ASSERT(convert_func != nullptr)` (`ggml-cuda.cu`)** — this is exactly+what `backend_ops_test` hit on `iq2_xxs` MUL_MAT. If you add or bump IQ+handling, keep the `supports_op` cases and their kernels behind the same macro+or the mismatch reappears. (ROCm shares `ggml-cuda.cu`, but its build does not+define the macro, so IQ stays enabled there.)++For a CUDA dylib that runs IQ quants on the GPU, build without the flag — drop+`--minimize-size` (or use its other pieces like `--minimal-archs`/`--strip`+without `--no-iq-quants`) — at the cost of a larger library. The ROCm, Vulkan,+and Metal builds are not size-minimized, so none of them strips IQ the way the+CUDA build does: ROCm shares this file with the macro undefined, so it keeps the+full IQ mul_mat set; Metal and Vulkan keep whatever IQ ops their own backends+implement (Vulkan's `supports_op` still declines some IQ mul_mat/cpy shapes, but+it declines cleanly and falls back to CPU rather than crashing — which, after+this fix, is exactly how CUDA behaves too).+## Troubleshooting### "make: command not found" or Wrong Makediff --git a/docs/skills/llamafile/testing.md b/docs/skills/llamafile/testing.mdindex 72d3e9ea..75d9b8d6 100644--- a/docs/skills/llamafile/testing.md+++ b/docs/skills/llamafile/testing.md@@ -71,6 +71,36 @@ Corollary: a CPU-only smoke test (`--gpu disable`) does **not** exercise thispath. Always run at least one default/GPU invocation when verifying a build onGPU-capable hardware.+#### Validating a prebuilt GPU dylib — verify by observation, never infer++A clean *compile* does not prove the dylib loads or runs on the GPU. Confirm it+with observed runtime behavior, and never conclude "it won't use the GPU" from+indirect signals (an `ldconfig` grep, an ICD filename) — enumerate/observe the+real thing.++1. **Deploy** the dylib where llamafile loads it: `~/.llamafile/v/<VERSION>/`+ (keyed by `version.h`; the same dir as the stale-cache note above), e.g.+ `cp ggml-vulkan.so ~/.llamafile/v/0.10.5/`.+2. **Force the backend** so you test the dylib you mean to (not a fallback):+ `--gpu cuda` / `--gpu vulkan` / `--gpu amd`. Run with `-ngl 99 --verbose`.+3. **Read the device line** — this is the proof the backend loaded and bound the+ GPU. For Vulkan: `ggml_vulkan: Found 1 Vulkan devices:` /+ `0 = NVIDIA L40S (...) | fp16: 1 | bf16: 0 | int dot: 0 | matrix cores: KHR_coopmat`+ / `register_device: registered device Vulkan0` / `load_tensors: layer N+ assigned to device Vulkan0`. That capability line also tells you which speed+ paths are live (`bf16: 0` / `int dot: 0` / `KHR_coopmat` vs coopmat2 = the+ build's glslc lacked them — see building.md).+4. **Cross-check VRAM**: `nvidia-smi --query-compute-apps=process_name,used_memory+ --format=csv,noheader` should show the llamafile/`.ape` process holding memory.+5. **Confirm output**: one chat/completion returns sane text.+6. To check whether a device is even visible to a backend, run the real probe —+ `vulkaninfo --summary` (Vulkan), `nvidia-smi` (CUDA) — not a library-file grep.++Gotcha: the llamafile process's `comm` is `.ape-*`, not `llamafile`, so+`pkill -x llamafile` misses it — kill by PID (from `nvidia-smi+--query-compute-apps=pid`), and never `pkill -f <model-or-cmd-substring>` from a+shell whose own command line contains that substring (it matches itself).+#### Where can I find GGUF model weights files?Look for available gguf files in `~/ggufs/`. If you don't find any or thediff --git a/docs/support.md b/docs/support.mdindex 4912507e..eb849703 100644--- a/docs/support.md+++ b/docs/support.md@@ -50,6 +50,18 @@ below llamafile runs on the CPU.The 0.10.* series has not been tested on every GPU and platform yet, sotreat the AMD and Windows paths in particular as best-effort.+### IQ-quantized models on NVIDIA GPUs++The CUDA library bundled in our releases is size-optimized and leaves out+the IQ-quant kernels (the `IQ1_*`, `IQ2_*`, `IQ3_*`, `IQ4_*` quantizations).+When you offload an IQ-quantized model to an NVIDIA GPU, llamafile keeps just+those layers on the CPU automatically — the output is correct, those specific+layers simply don't get GPU acceleration. Every other quantization (`Q*_*`,+`MXFP4`, `NVFP4`, `F16`, `BF16`, …) runs fully on the GPU. The Apple Metal and+AMD (ROCm) builds are not size-optimized and include full IQ-quant GPU support.+For full IQ acceleration on NVIDIA, build or supply a full (non-minimized) CUDA+library — see [Building the GPU libraries](building_dlls.md).+GPU on MacOS ARM64 is supported by compiling a small module using theXcode Command Line Tools, which need to be installed. This is a one timecost that happens the first time you run your llamafile. The DSO builtdiff --git a/llama.cpp b/llama.cppindex d6d89958..b2dd28a3 160000--- a/llama.cpp+++ b/llama.cpp@@ -1 +1 @@-Subproject commit d6d899580dcf0e50a3d14453d3d082f6ed050450+Subproject commit b2dd28a3b601417b8ea345c4db72df3048e1114fdiff --git a/llama.cpp.patches/README.md b/llama.cpp.patches/README.mdindex d439b9d7..b3faff29 100644--- a/llama.cpp.patches/README.md+++ b/llama.cpp.patches/README.md@@ -44,7 +44,7 @@ The `GGML_CALL` macro (defined as `__attribute__((__ms_abi__))` when `GGML_MULTI|-------|-------------|| `ggml_include_ggml-backend.h.patch` | Defines the `GGML_CALL` macro; adds it to the five `get_proc_address` return typedefs (`ggml_backend_split_buffer_type_t`, `ggml_backend_set_n_threads_t`, `ggml_backend_dev_get_extra_bufts_t`, `ggml_backend_set_abort_callback_t`, `ggml_backend_get_features_t`) || `ggml_include_ggml-cpu.h.patch` | Adds `GGML_CALL` to declarations of `ggml_backend_cpu_set_n_threads` and `ggml_backend_cpu_set_abort_callback` (returned via `get_proc_address`) |-| `ggml_include_ggml-cuda.h.patch` | Adds `GGML_CALL` to declarations of `ggml_backend_cuda_split_buffer_type`, `ggml_backend_cuda_register_host_buffer`, and `ggml_backend_cuda_unregister_host_buffer` |+| `ggml_include_ggml-cuda.h.patch` | Adds `GGML_CALL` to the declaration of `ggml_backend_cuda_register_host_buffer` (upstream removed the row-split multi-GPU buffer in b10052, so the former `ggml_backend_cuda_split_buffer_type` annotation is gone) || `ggml_src_ggml-backend-impl.h.patch` | Adds `GGML_CALL` to all 49+ function pointers across the five interface structs (`ggml_backend_buffer_type_i`, `ggml_backend_buffer_i`, `ggml_backend_i`, `ggml_backend_device_i`, `ggml_backend_reg_i`); also adds `free_struct` callback (see Cross-Module Memory below) || `ggml_src_ggml-backend.cpp.patch` | Adds `GGML_CALL` to CPU buffer, buffer type, and multi-buffer callback implementations; also adds `free_struct` support (see Cross-Module Memory below) || `ggml_src_ggml-cpu_ggml-cpu.cpp.patch` | Adds `GGML_CALL` to all CPU backend, device, and registry callback implementations, plus `get_proc_address`-returned functions (`set_n_threads`, `set_abort_callback`, `get_extra_buffers_type`, `get_features`) |@@ -63,7 +63,7 @@ When GPU backends (CUDA, Vulkan, Metal) are loaded as dynamic libraries, memory|-------|-------------|| `ggml_src_ggml-backend-impl.h.patch` | Adds `free_struct` callback to `ggml_backend_buffer_i` interface for cross-module buffer cleanup || `ggml_src_ggml-backend.cpp.patch` | Implements `free_struct` callback support in `ggml_backend_buffer_free()` — calls DSO's `free_struct` instead of `delete` when set |-| `ggml_src_ggml-cuda_ggml-cuda.cu.patch` | Adds `free_struct` implementation for CUDA buffers (regular, split, and host); sets it on fallback CPU buffers allocated within the DSO |+| `ggml_src_ggml-cuda_ggml-cuda.cu.patch` | Adds `free_struct` implementation for CUDA buffers (regular and host; upstream removed the split buffer in b10052); sets it on fallback CPU buffers allocated within the DSO || `ggml_src_ggml-metal_ggml-metal.cpp.patch` | Adds `free_struct` implementation for Metal shared and private buffers || `ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch` | Adds `free_struct` implementation for Vulkan buffers and host buffer fallback path |@@ -205,6 +205,7 @@ can change on a llama.cpp bump — when it does, the asset list in| `ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch` | Fixes unsigned integer underflow in `ggml_backend_vk_get_device_memory` where Vulkan's `heapUsage` can exceed `heapBudget` (clamps to zero instead of wrapping) || `src_models_t5.cpp.patch` | Forward-declares the `graph<false>`/`graph<true>` explicit specializations before `build_arch_graph` so clang's `-std=gnu++23` doesn't reject them as specializations after implicit instantiation || `src_models_eagle3.cpp.patch` | Moves `build_arch_graph` to the end of the file, after the `graph<true>`/`graph<false>` constructor specializations, so clang's `-std=gnu++23` doesn't reject them as explicit specializations appearing after the `make_unique<graph<...>>` implicit instantiation point |+| `src_models_dflash.cpp.patch` | Same fix as `eagle3` for the DFlash model (new in b10052): moves `build_arch_graph` to the end of the file, after the `graph<true>`/`graph<false>` specializations, so clang's `-std=gnu++23` doesn't reject them as explicit specializations after the `make_unique<graph<...>>` implicit instantiation point |## Creating New Patchesdiff --git a/llama.cpp.patches/fetch-ui-assets.sh b/llama.cpp.patches/fetch-ui-assets.shindex 86d1e320..6180f173 100755--- a/llama.cpp.patches/fetch-ui-assets.sh+++ b/llama.cpp.patches/fetch-ui-assets.sh@@ -101,7 +101,6 @@ ui_missing_assets() {return 1}_have 'index.html' || echo 'index.html'- _have 'loading.html' || echo 'loading.html'_have 'manifest.webmanifest' || echo 'manifest.webmanifest'_have 'sw.js' || echo 'sw.js'_have 'build.json' || echo 'build.json'diff --git a/llama.cpp.patches/llamafile-files/BUILD.mk b/llama.cpp.patches/llamafile-files/BUILD.mkindex 04c7f787..f392bceb 100644--- a/llama.cpp.patches/llamafile-files/BUILD.mk+++ b/llama.cpp.patches/llamafile-files/BUILD.mk@@ -76,7 +76,9 @@ LLAMA_SRCS_CPP := \llama.cpp/src/models/deepseek2.cpp \llama.cpp/src/models/deepseek2ocr.cpp \llama.cpp/src/models/deepseek32.cpp \+ llama.cpp/src/models/deepseek4.cpp \llama.cpp/src/models/delta-net-base.cpp \+ llama.cpp/src/models/dflash.cpp \llama.cpp/src/models/dots1.cpp \llama.cpp/src/models/dream.cpp \llama.cpp/src/models/eagle3.cpp \@@ -109,6 +111,7 @@ LLAMA_SRCS_CPP := \llama.cpp/src/models/hunyuan-dense.cpp \llama.cpp/src/models/hunyuan-moe.cpp \llama.cpp/src/models/hunyuan-vl.cpp \+ llama.cpp/src/models/hy-v3.cpp \llama.cpp/src/models/internlm2.cpp \llama.cpp/src/models/jais.cpp \llama.cpp/src/models/jais2.cpp \@@ -198,6 +201,7 @@ LLAMA_SRCS_CPP := \llama.cpp/src/llama-impl.cpp \llama.cpp/src/llama-io.cpp \llama.cpp/src/llama-kv-cache-dsa.cpp \+ llama.cpp/src/llama-kv-cache-dsv4.cpp \llama.cpp/src/llama-kv-cache-iswa.cpp \llama.cpp/src/llama-kv-cache.cpp \llama.cpp/src/llama-memory-hybrid.cpp \@@ -240,7 +244,6 @@ COMMON_SRCS_CPP := \llama.cpp/common/jinja/runtime.cpp \llama.cpp/common/jinja/string.cpp \llama.cpp/common/jinja/value.cpp \- llama.cpp/common/json-partial.cpp \llama.cpp/common/json-schema-to-grammar.cpp \llama.cpp/common/license.cpp \llama.cpp/common/llguidance.cpp \@@ -251,7 +254,6 @@ COMMON_SRCS_CPP := \llama.cpp/common/peg-parser.cpp \llama.cpp/common/preset.cpp \llama.cpp/common/reasoning-budget.cpp \- llama.cpp/common/regex-partial.cpp \llama.cpp/common/sampling.cpp \llama.cpp/common/speculative.cpp \llama.cpp/common/unicode.cpp@@ -420,6 +422,7 @@ TOOL_SERVER_SRCS := \llama.cpp/tools/server/server-models.cpp \llama.cpp/tools/server/server-queue.cpp \llama.cpp/tools/server/server-schema.cpp \+ llama.cpp/tools/server/server-stream.cpp \llama.cpp/tools/server/server-task.cpp \llama.cpp/tools/server/server-tools.cppdiff --git a/llama.cpp.patches/patches/common_arg.cpp.patch b/llama.cpp.patches/patches/common_arg.cpp.patchindex 153f0ac0..7b3bab50 100644--- a/llama.cpp.patches/patches/common_arg.cpp.patch+++ b/llama.cpp.patches/patches/common_arg.cpp.patch@@ -1,7 +1,7 @@diff --git a/common/arg.cpp b/common/arg.cpp--- a/llama.cpp/common/arg.cpp+++ b/llama.cpp/common/arg.cpp-@@ -38,6 +38,8 @@+@@ -39,6 +39,8 @@#ifndef __EMSCRIPTEN__#ifdef __linux__#include <linux/limits.h>diff --git a/llama.cpp.patches/patches/common_common.cpp.patch b/llama.cpp.patches/patches/common_common.cpp.patchindex 91d50635..c4772ae6 100644--- a/llama.cpp.patches/patches/common_common.cpp.patch+++ b/llama.cpp.patches/patches/common_common.cpp.patch@@ -12,11 +12,11 @@ diff --git a/common/common.cpp b/common/common.cpp#if defined(_WIN32)#define WIN32_LEAN_AND_MEAN#ifndef NOMINMAX-@@ -72,7 +76,38 @@ common_time_meas::~common_time_meas() {+@@ -76,7 +80,38 @@ common_time_meas::~common_time_meas() {//int32_t common_cpu_get_num_physical_cores() {--#ifdef __linux__+-#if defined(_AIX)+#if defined(COSMOCC)+ // cosmocc cross-compiles for both Linux and macOS at once, so neither+ // __linux__ nor __APPLE__ is defined here; detect the host OS at runtime.@@ -48,11 +48,11 @@ diff --git a/common/common.cpp b/common/common.cpp+ return num_physical_cores;+ }+ }-+#elif defined(__linux__)- // enumerate the set of thread siblings, num entries is num cores- std::unordered_set<std::string> siblings;- for (uint32_t cpu=0; cpu < UINT32_MAX; ++cpu) {-@@ -1012,6 +1047,16 @@ std::string fs_get_cache_directory() {++#elif defined(_AIX)+ int32_t logical_cpus = _system_configuration.ncpus;+ int32_t smt_threads = _system_configuration.smt_threads;+ if (smt_threads > 0) {+@@ -1033,6 +1068,16 @@ std::string fs_get_cache_directory() {cache_directory = std::getenv("HOME") + std::string("/Library/Caches/");#elif defined(_WIN32)cache_directory = std::getenv("LOCALAPPDATA");@@ -69,10 +69,10 @@ diff --git a/common/common.cpp b/common/common.cpp#elif defined(__EMSCRIPTEN__)GGML_ABORT("not implemented on this platform");#else-@@ -1201,10 +1246,31 @@ common_init_result::common_init_result(common_params & params, bool model_only)+@@ -1222,10 +1267,31 @@ common_init_result::common_init_result(common_params & params, bool model_only)if (params.fit_params) {- LOG_INF("%s: fitting params to device memory ...\n", __func__);- LOG_INF("%s: (for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on)\n", __func__);+ COM_TRC("%s", "fitting params to device memory ...\n");+ COM_TRC("%s", "(for bugs during this step try to reproduce them with -fit off, or provide --verbose logs if the bug only occurs with -fit on)\n");++ // if a multimodal projection model is specified and will be loaded on GPU,+ // add its estimated size to the fit margins so the fit leaves enough room for itdiff --git a/llama.cpp.patches/patches/common_http.h.patch b/llama.cpp.patches/patches/common_http.h.patchindex 5aa4236a..1f7a8c69 100644--- a/llama.cpp.patches/patches/common_http.h.patch+++ b/llama.cpp.patches/patches/common_http.h.patch@@ -1,7 +1,7 @@diff --git a/common/http.h b/common/http.h--- a/llama.cpp/common/http.h+++ b/llama.cpp/common/http.h-@@ -72,7 +72,7 @@ static std::pair<httplib::Client, common_http_url> common_http_client(const std:+@@ -104,7 +104,7 @@ static std::pair<httplib::Client, common_http_url> common_http_client(const std:throw std::runtime_error("error: invalid URL format");}diff --git a/llama.cpp.patches/patches/ggml_include_ggml-cpu.h.patch b/llama.cpp.patches/patches/ggml_include_ggml-cpu.h.patchindex a25100bd..22fa9147 100644--- a/llama.cpp.patches/patches/ggml_include_ggml-cpu.h.patch+++ b/llama.cpp.patches/patches/ggml_include_ggml-cpu.h.patch@@ -1,7 +1,7 @@diff --git a/ggml/include/ggml-cpu.h b/ggml/include/ggml-cpu.h--- a/llama.cpp/ggml/include/ggml-cpu.h+++ b/llama.cpp/ggml/include/ggml-cpu.h-@@ -131,9 +131,9 @@ extern "C" {+@@ -132,9 +132,9 @@ extern "C" {GGML_BACKEND_API ggml_backend_t ggml_backend_cpu_init(void);GGML_BACKEND_API bool ggml_backend_is_cpu (ggml_backend_t backend);diff --git a/llama.cpp.patches/patches/ggml_include_ggml-cuda.h.patch b/llama.cpp.patches/patches/ggml_include_ggml-cuda.h.patchindex a2b00a01..6f671c09 100644--- a/llama.cpp.patches/patches/ggml_include_ggml-cuda.h.patch+++ b/llama.cpp.patches/patches/ggml_include_ggml-cuda.h.patch@@ -1,16 +1,7 @@diff --git a/ggml/include/ggml-cuda.h b/ggml/include/ggml-cuda.h--- a/llama.cpp/ggml/include/ggml-cuda.h+++ b/llama.cpp/ggml/include/ggml-cuda.h-@@ -31,7 +31,7 @@ GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_cuda_buffer_type(int de- GGML_BACKEND_API bool ggml_backend_cuda_allreduce_tensor(ggml_backend_t * backends, struct ggml_tensor ** tensors, size_t n_backends);-- // split tensor buffer that splits matrices by rows across multiple devices--GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_cuda_split_buffer_type(int main_device, const float * tensor_split);-+GGML_BACKEND_API ggml_backend_buffer_type_t GGML_CALL ggml_backend_cuda_split_buffer_type(int main_device, const float * tensor_split);-- // pinned host buffer for use with the CPU backend for faster copies between CPU and GPU- GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_cuda_host_buffer_type(void);-@@ -40,8 +40,8 @@ GGML_BACKEND_API int ggml_backend_cuda_get_device_count(void);+@@ -37,8 +37,8 @@ GGML_BACKEND_API int ggml_backend_cuda_get_device_count(void);GGML_BACKEND_API void ggml_backend_cuda_get_device_description(int device, char * description, size_t description_size);GGML_BACKEND_API void ggml_backend_cuda_get_device_memory(int device, size_t * free, size_t * total);diff --git a/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patchindex ef308ea0..a0461af6 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-backend-meta.cpp.patch@@ -150,7 +150,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cppGGML_UNUSED(buffer);return (void *) 0x1000000000000000; // FIXME}-@@ -1236,14 +1236,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_m+@@ -1241,14 +1241,14 @@ static enum ggml_status ggml_backend_meta_buffer_init_tensor_impl(ggml_backend_mreturn GGML_STATUS_SUCCESS;}@@ -165,18 +165,18 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cpp-static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor, const void * data, size_t offset, size_t size) {+static void GGML_CALL ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor, const void * data, size_t offset, size_t size) {const size_t n_bufs = ggml_backend_meta_buffer_n_bufs(buffer);- GGML_ASSERT(ggml_is_contiguous(tensor));--@@ -1358,7 +1358,7 @@ static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, gg+ const ggml_backend_meta_split_state split_state = ggml_backend_meta_get_split_state(tensor, /*assume_sync =*/ false);+ GGML_ASSERT(ggml_is_contiguous(tensor) || split_state.axis == GGML_BACKEND_SPLIT_AXIS_MIRRORED);+@@ -1362,7 +1362,7 @@ static void ggml_backend_meta_buffer_set_tensor(ggml_backend_buffer_t buffer, gg}}-static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, const ggml_tensor * tensor, void * data, size_t offset, size_t size) {+static void GGML_CALL ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, const ggml_tensor * tensor, void * data, size_t offset, size_t size) {const size_t n_bufs = ggml_backend_meta_buffer_n_bufs(buffer);- GGML_ASSERT(ggml_is_contiguous(tensor));--@@ -1459,14 +1459,14 @@ static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, co+ const ggml_backend_meta_split_state split_state = ggml_backend_meta_get_split_state(tensor, /*assume_sync =*/ false);+ GGML_ASSERT(ggml_is_contiguous(tensor) || split_state.axis == GGML_BACKEND_SPLIT_AXIS_MIRRORED);+@@ -1462,14 +1462,14 @@ static void ggml_backend_meta_buffer_get_tensor(ggml_backend_buffer_t buffer, co}}@@ -193,7 +193,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cppGGML_ASSERT(ggml_backend_buffer_is_meta(buffer));ggml_backend_meta_buffer_context * buf_ctx = (ggml_backend_meta_buffer_context *) buffer->context;for (size_t i = 0; i < buf_ctx->bufs.size(); i++) {-@@ -1492,7 +1492,7 @@ bool ggml_backend_buffer_is_meta(ggml_backend_buffer_t buf) {+@@ -1495,7 +1495,7 @@ bool ggml_backend_buffer_is_meta(ggml_backend_buffer_t buf) {return buf != nullptr && buf->iface.free_buffer == ggml_backend_meta_buffer_iface.free_buffer;}@@ -202,7 +202,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cppconst size_t n_simple_bufts = ggml_backend_meta_buft_n_bufts(buft);const ggml_init_params params = {-@@ -1659,20 +1659,20 @@ struct ggml_backend_meta_context {+@@ -1662,20 +1662,20 @@ struct ggml_backend_meta_context {}};@@ -226,7 +226,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cppconst size_t n_backends = ggml_backend_meta_n_backends(backend);GGML_ASSERT(offset == 0);GGML_ASSERT(ggml_is_contiguous(tensor));-@@ -1717,7 +1717,7 @@ static void ggml_backend_meta_set_tensor_async(ggml_backend_t backend, ggml_tens+@@ -1720,7 +1720,7 @@ static void ggml_backend_meta_set_tensor_async(ggml_backend_t backend, ggml_tens}}@@ -235,7 +235,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cppconst size_t n_backends = ggml_backend_meta_n_backends(backend);GGML_ASSERT(offset == 0);GGML_ASSERT(ggml_is_contiguous(tensor));-@@ -1762,14 +1762,14 @@ static void ggml_backend_meta_get_tensor_async(ggml_backend_t backend, const ggm+@@ -1765,14 +1765,14 @@ static void ggml_backend_meta_get_tensor_async(ggml_backend_t backend, const ggm}}@@ -252,7 +252,7 @@ diff --git a/ggml/src/ggml-backend-meta.cpp b/ggml/src/ggml-backend-meta.cppGGML_ASSERT(cgraph->grads == nullptr);const size_t n_backends = ggml_backend_meta_n_backends(backend);ggml_backend_meta_context * backend_ctx = (ggml_backend_meta_context *) backend->context;-@@ -2239,7 +2239,7 @@ bool ggml_backend_is_meta(ggml_backend_t backend) {+@@ -2242,7 +2242,7 @@ bool ggml_backend_is_meta(ggml_backend_t backend) {return backend != nullptr && backend->iface.get_name == ggml_backend_meta_i.get_name;}diff --git a/llama.cpp.patches/patches/ggml_src_ggml-backend-reg.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-backend-reg.cpp.patchindex ab59ee37..6286b24e 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-backend-reg.cpp.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-backend-reg.cpp.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-backend-reg.cpp b/ggml/src/ggml-backend-reg.cpp--- a/llama.cpp/ggml/src/ggml-backend-reg.cpp+++ b/llama.cpp/ggml/src/ggml-backend-reg.cpp-@@ -497,7 +497,7 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,+@@ -504,7 +504,7 @@ static ggml_backend_reg_t ggml_backend_load_best(const char * name, bool silent,if (ec) {GGML_LOG_DEBUG("%s: posix_stat(%s) failure, error-message: %s\n", __func__, path_str(search_path).c_str(), ec.message().c_str());} else {diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patchindex 4a720231..0906b0c3 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.c.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.c--- a/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c+++ b/llama.cpp/ggml/src/ggml-cpu/ggml-cpu.c-@@ -1530,6 +1530,26 @@ static void ggml_compute_forward_mul_mat_id(+@@ -1539,6 +1539,26 @@ static void ggml_compute_forward_mul_mat_id(const struct ggml_tensor * src1 = dst->src[1];const struct ggml_tensor * ids = dst->src[2];@@ -28,7 +28,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.cGGML_TENSOR_BINARY_OP_LOCALSconst int ith = params->ith;-@@ -1649,6 +1669,24 @@ static void ggml_compute_forward_mul_mat_id(+@@ -1658,6 +1678,24 @@ static void ggml_compute_forward_mul_mat_id(const int64_t nr0 = ne01;const int64_t nr1 = cne1;@@ -53,7 +53,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.c b/ggml/src/ggml-cpu/ggml-cpu.cint chunk_size = 16;if (nr0 == 1 || nr1 == 1) {chunk_size = 64;-@@ -2842,6 +2880,19 @@ struct ggml_cplan ggml_graph_plan(+@@ -2856,6 +2894,19 @@ struct ggml_cplan ggml_graph_plan(cur += n_as*ids->ne[0]*ids->ne[1]*sizeof(struct mmid_row_mapping) + sizeof(int64_t);// atomic_current_chunkcur += CACHE_LINE_SIZE*n_as + CACHE_LINE_SIZE;diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.cpp.patchindex 4e4cf7d1..c413711e 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.cpp.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ggml-cpu.cpp.patch@@ -151,7 +151,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.cpp b/ggml/src/ggml-cpu/ggml-cpu.cppconst struct ggml_tensor * src0 = op->src[0];const struct ggml_tensor * src1 = op->src[1];-@@ -473,7 +473,7 @@ static bool ggml_backend_cpu_device_supports_op(ggml_backend_dev_t dev, const st+@@ -474,7 +474,7 @@ static bool ggml_backend_cpu_device_supports_op(ggml_backend_dev_t dev, const st}}@@ -160,7 +160,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.cpp b/ggml/src/ggml-cpu/ggml-cpu.cppreturn ggml_backend_buft_is_host(buft) || ggml_backend_cpu_is_extra_buffer_type(buft);GGML_UNUSED(dev);}-@@ -498,19 +498,19 @@ static const struct ggml_backend_device_i ggml_backend_cpu_device_i = {+@@ -499,19 +499,19 @@ static const struct ggml_backend_device_i ggml_backend_cpu_device_i = {// CPU backend - backend (reg)@@ -183,7 +183,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.cpp b/ggml/src/ggml-cpu/ggml-cpu.cppGGML_ASSERT(index == 0);static ggml_backend_cpu_device_context ctx;-@@ -525,7 +525,7 @@ static ggml_backend_dev_t ggml_backend_cpu_reg_get_device(ggml_backend_reg_t reg+@@ -526,7 +526,7 @@ static ggml_backend_dev_t ggml_backend_cpu_reg_get_device(ggml_backend_reg_t reg// This is intended to replace the the ggml_cpu_has_* functions when loading the CPU backend dynamically,// and additionally to allow other backends to expose their own list of features that applications can query using the same API@@ -192,7 +192,7 @@ diff --git a/ggml/src/ggml-cpu/ggml-cpu.cpp b/ggml/src/ggml-cpu/ggml-cpu.cppstatic std::vector<ggml_backend_feature> features = []() {ggml_cpu_init();-@@ -639,7 +639,7 @@ static ggml_backend_feature * ggml_backend_cpu_get_features(ggml_backend_reg_t r+@@ -643,7 +643,7 @@ static ggml_backend_feature * ggml_backend_cpu_get_features(ggml_backend_reg_t rGGML_UNUSED(reg);}diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patchindex a8b1a737..4bb02060 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cpu_ops.cpp.patch@@ -20,7 +20,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp// ggml_compute_forward_dupstatic void ggml_compute_forward_dup_same_cont(-@@ -8399,6 +8411,15 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(+@@ -8547,6 +8559,15 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(GGML_ASSERT(( q_to_vec_dot) && "fattn: unsupported K-type");GGML_ASSERT((v->type == GGML_TYPE_F32 || v_to_float ) && "fattn: unsupported V-type");@@ -36,7 +36,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cppint ith = params->ith;for (int ir = ir0; ir < ir1; ++ir) {-@@ -8418,10 +8439,22 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(+@@ -8566,10 +8587,22 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(ggml_fp16_t * VKQ16 = (ggml_fp16_t *) (VKQ32 + 1*DV); // (temporary) FP16 VKQ accumulatorggml_fp16_t * Q_q = (ggml_fp16_t *) (VKQ32 + 2*DV); // (temporary) buffer for Q converted to quantized/FP16@@ -62,7 +62,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp}const ggml_fp16_t * mp = mask ? (ggml_fp16_t *)((char *) mask->data + iq1*mask->nb[1] + (iq2%mask->ne[2])*mask->nb[2] + (iq3%mask->ne[3])*mask->nb[3]) : NULL;-@@ -8450,7 +8483,13 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(+@@ -8598,7 +8631,13 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(float s; // KQ valueconst char * k_data = (const char *) k->data + ( ic*nbk1 + ik2*nbk2 + ik3*nbk3);@@ -76,7 +76,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpps = s*scale; // scale KQ value-@@ -8467,21 +8506,36 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(+@@ -8615,21 +8654,36 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(const char * v_data = ((const char *) v->data + (ic*nbv1 + iv2*nbv2 + iv3*nbv3));@@ -116,7 +116,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp} else {if (s > M) {// s is new maximum, ms < 1.0f, vs == expf(s - s) == 1.0f-@@ -8489,26 +8543,20 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(+@@ -8637,26 +8691,20 @@ static void ggml_compute_forward_flash_attn_ext_f16_one_chunk(ms = expf(Mold - M);// V = V*expf(Mold - M)@@ -146,7 +146,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cppfor (int64_t d = 0; d < DV; ++d) {VKQ32[d] = GGML_CPU_FP16_TO_FP32(VKQ16[d]);}-@@ -8729,8 +8777,24 @@ static void ggml_compute_forward_flash_attn_ext_tiled(+@@ -8877,8 +8925,24 @@ static void ggml_compute_forward_flash_attn_ext_tiled(const char * k_data = (const char *)k->data + (ic + tk)*nbk1 + ik2*nbk2 + ik3*nbk3;if (kv_type == GGML_TYPE_F16) {const ggml_fp16_t * k_f16 = (const ggml_fp16_t *)k_data;@@ -173,7 +173,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp}} else {const float * k_f32_src = (const float *)k_data;-@@ -8740,7 +8804,18 @@ static void ggml_compute_forward_flash_attn_ext_tiled(+@@ -8888,7 +8952,18 @@ static void ggml_compute_forward_flash_attn_ext_tiled(}}memset(KQ, 0, Q_TILE_SZ * KV_TILE_SZ * sizeof(float));@@ -192,7 +192,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cppggml_vec_scale_f32(Q_TILE_SZ * KV_TILE_SZ, KQ, scale);// Set padded KQ entries to -inf so softmax gives them zero weight-@@ -8793,7 +8868,15 @@ static void ggml_compute_forward_flash_attn_ext_tiled(+@@ -8941,7 +9016,15 @@ static void ggml_compute_forward_flash_attn_ext_tiled(for (int tk = 0; tk < kv_tile; tk++) {const char * v_data = (const char *)v->data + (ic + tk)*nbv1 + iv2*nbv2 + iv3*nbv3;if (kv_type == GGML_TYPE_F16) {@@ -208,7 +208,7 @@ diff --git a/ggml/src/ggml-cpu/ops.cpp b/ggml/src/ggml-cpu/ops.cpp} else {memcpy(V32 + tk * DV, v_data, DV * sizeof(float));}-@@ -8803,7 +8886,16 @@ static void ggml_compute_forward_flash_attn_ext_tiled(+@@ -8951,7 +9034,16 @@ static void ggml_compute_forward_flash_attn_ext_tiled(memset(KQ + tq * KV_TILE_SZ, 0, KV_TILE_SZ * sizeof(float));}}diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_convert.cu.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_convert.cu.patchindex 6ef4957c..c76fb7fb 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_convert.cu.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_convert.cu.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-cuda/convert.cu b/ggml/src/ggml-cuda/convert.cu--- a/llama.cpp/ggml/src/ggml-cuda/convert.cu+++ b/llama.cpp/ggml/src/ggml-cuda/convert.cu-@@ -736,6 +736,7 @@ to_fp16_cuda_t ggml_get_to_fp16_cuda(ggml_type type) {+@@ -730,6 +730,7 @@ to_bf16_cuda_t ggml_get_to_bf16_cuda(ggml_type type) {return dequantize_row_q5_K_cuda;case GGML_TYPE_Q6_K:return dequantize_row_q6_K_cuda;@@ -9,7 +9,7 @@ diff --git a/ggml/src/ggml-cuda/convert.cu b/ggml/src/ggml-cuda/convert.cucase GGML_TYPE_IQ2_XXS:return dequantize_row_iq2_xxs_cuda;case GGML_TYPE_IQ2_XS:-@@ -754,6 +755,7 @@ to_fp16_cuda_t ggml_get_to_fp16_cuda(ggml_type type) {+@@ -748,6 +749,7 @@ to_bf16_cuda_t ggml_get_to_bf16_cuda(ggml_type type) {return dequantize_row_iq4_xs_cuda;case GGML_TYPE_IQ3_S:return dequantize_row_iq3_s_cuda;@@ -17,7 +17,7 @@ diff --git a/ggml/src/ggml-cuda/convert.cu b/ggml/src/ggml-cuda/convert.cucase GGML_TYPE_MXFP4:return dequantize_row_mxfp4_cuda;case GGML_TYPE_NVFP4:-@@ -791,6 +793,7 @@ to_fp32_cuda_t ggml_get_to_fp32_cuda(ggml_type type) {+@@ -788,6 +790,7 @@ to_fp16_cuda_t ggml_get_to_fp16_cuda(ggml_type type) {return dequantize_row_q5_K_cuda;case GGML_TYPE_Q6_K:return dequantize_row_q6_K_cuda;@@ -25,7 +25,7 @@ diff --git a/ggml/src/ggml-cuda/convert.cu b/ggml/src/ggml-cuda/convert.cucase GGML_TYPE_IQ2_XXS:return dequantize_row_iq2_xxs_cuda;case GGML_TYPE_IQ2_XS:-@@ -809,6 +812,7 @@ to_fp32_cuda_t ggml_get_to_fp32_cuda(ggml_type type) {+@@ -806,6 +809,7 @@ to_fp16_cuda_t ggml_get_to_fp16_cuda(ggml_type type) {return dequantize_row_iq4_xs_cuda;case GGML_TYPE_IQ3_S:return dequantize_row_iq3_s_cuda;diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_cpy.cu.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_cpy.cu.patchindex 13e4a5b9..34840be0 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_cpy.cu.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_cpy.cu.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-cuda/cpy.cu b/ggml/src/ggml-cuda/cpy.cu--- a/llama.cpp/ggml/src/ggml-cuda/cpy.cu+++ b/llama.cpp/ggml/src/ggml-cuda/cpy.cu-@@ -368,6 +368,7 @@ static void ggml_cpy_q5_1_f32_cuda(+@@ -374,6 +374,7 @@ static void ggml_cpy_q5_1_f32_cuda(ne10, ne11, ne12, nb10, nb11, nb12, nb13);}@@ -9,15 +9,15 @@ diff --git a/ggml/src/ggml-cuda/cpy.cu b/ggml/src/ggml-cuda/cpy.custatic void ggml_cpy_f32_iq4_nl_cuda(const char * cx, char * cdst, const int64_t ne,const int64_t ne00, const int64_t ne01, const int64_t ne02, const int64_t nb00, const int64_t nb01, const int64_t nb02,-@@ -379,6 +380,7 @@ static void ggml_cpy_f32_iq4_nl_cuda(+@@ -385,6 +386,7 @@ static void ggml_cpy_f32_iq4_nl_cuda(cpy_f32_q<cpy_blck_f32_iq4_nl, QK4_NL><<<num_blocks, 1, 0, stream>>>(cx, cdst, ne, ne00, ne01, ne02, nb00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb13);}+#endif // GGML_CUDA_NO_IQ_QUANTS- void ggml_cuda_cpy(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, ggml_tensor * src1) {- const int64_t ne = ggml_nelements(src0);-@@ -473,9 +475,11 @@ void ggml_cuda_cpy(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, gg+ // check if a same-type copy reduces to a 2D strided copy (height rows of width+ // contiguous bytes), so it can use cudaMemcpy2DAsync instead of the scalar kernel+@@ -524,9 +526,11 @@ void ggml_cuda_cpy(ggml_backend_cuda_context & ctx, const ggml_tensor * src0, gg} else if (src0->type == GGML_TYPE_Q5_0 && src1->type == GGML_TYPE_F32) {ggml_cpy_q5_0_f32_cuda(src0_ddc, src1_ddc, ne, ne00, ne01, ne02, nb00, nb01, nb02, nb03, ne10, ne11, ne12, nb10, nb11, nb12, nb13, main_stream);diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patchindex ba96fc63..aa5da09e 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_ggml-cuda.cu.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu--- a/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu+++ b/llama.cpp/ggml/src/ggml-cuda/ggml-cuda.cu-@@ -638,7 +638,7 @@ struct ggml_backend_cuda_buffer_context {+@@ -735,7 +735,7 @@ struct ggml_backend_cuda_buffer_context {}};@@ -10,7 +10,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;delete ctx;}-@@ -647,12 +647,12 @@ static bool ggml_backend_buffer_is_cuda(ggml_backend_buffer_t buffer) {+@@ -744,12 +744,12 @@ static bool ggml_backend_buffer_is_cuda(ggml_backend_buffer_t buffer) {return buffer->iface.free_buffer == ggml_backend_cuda_buffer_free_buffer;}@@ -25,7 +25,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;if (tensor->view_src != NULL) {-@@ -673,7 +673,7 @@ static enum ggml_status ggml_backend_cuda_buffer_init_tensor(ggml_backend_buffer+@@ -770,7 +770,7 @@ static enum ggml_status ggml_backend_cuda_buffer_init_tensor(ggml_backend_bufferreturn GGML_STATUS_SUCCESS;}@@ -34,7 +34,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;ggml_cuda_set_device(ctx->device);-@@ -681,7 +681,7 @@ static void ggml_backend_cuda_buffer_memset_tensor(ggml_backend_buffer_t buffer,+@@ -778,7 +778,7 @@ static void ggml_backend_cuda_buffer_memset_tensor(ggml_backend_buffer_t buffer,CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));}@@ -43,7 +43,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;ggml_cuda_set_device(ctx->device);-@@ -689,7 +689,7 @@ static void ggml_backend_cuda_buffer_set_tensor(ggml_backend_buffer_t buffer, gg+@@ -786,7 +786,7 @@ static void ggml_backend_cuda_buffer_set_tensor(ggml_backend_buffer_t buffer, ggCUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));}@@ -52,7 +52,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;ggml_cuda_set_device(ctx->device);-@@ -697,7 +697,7 @@ static void ggml_backend_cuda_buffer_get_tensor(ggml_backend_buffer_t buffer, co+@@ -794,7 +794,7 @@ static void ggml_backend_cuda_buffer_get_tensor(ggml_backend_buffer_t buffer, coCUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));}@@ -61,7 +61,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cusize_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *) buffer->context;-@@ -707,7 +707,7 @@ static void ggml_backend_cuda_buffer_set_tensor_2d(ggml_backend_buffer_t buffer,+@@ -804,7 +804,7 @@ static void ggml_backend_cuda_buffer_set_tensor_2d(ggml_backend_buffer_t buffer,CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));}@@ -70,7 +70,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cusize_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {ggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;-@@ -717,7 +717,7 @@ static void ggml_backend_cuda_buffer_get_tensor_2d(ggml_backend_buffer_t buffer,+@@ -814,7 +814,7 @@ static void ggml_backend_cuda_buffer_get_tensor_2d(ggml_backend_buffer_t buffer,CUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));}@@ -79,7 +79,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuif (ggml_backend_buffer_is_cuda(src->buffer)) {ggml_backend_cuda_buffer_context * src_ctx = (ggml_backend_cuda_buffer_context *)src->buffer->context;ggml_backend_cuda_buffer_context * dst_ctx = (ggml_backend_cuda_buffer_context *)dst->buffer->context;-@@ -738,7 +738,7 @@ static bool ggml_backend_cuda_buffer_cpy_tensor(ggml_backend_buffer_t buffer, co+@@ -839,7 +839,7 @@ static bool ggml_backend_cuda_buffer_cpy_tensor(ggml_backend_buffer_t buffer, coGGML_UNUSED(buffer);}@@ -88,7 +88,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_context * ctx = (ggml_backend_cuda_buffer_context *)buffer->context;ggml_cuda_set_device(ctx->device);-@@ -746,6 +746,14 @@ static void ggml_backend_cuda_buffer_clear(ggml_backend_buffer_t buffer, uint8_t+@@ -847,6 +847,14 @@ static void ggml_backend_cuda_buffer_clear(ggml_backend_buffer_t buffer, uint8_tCUDA_CHECK(cudaStreamSynchronize(cudaStreamPerThread));}@@ -103,7 +103,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.custatic const ggml_backend_buffer_i ggml_backend_cuda_buffer_interface = {/* .free_buffer = */ ggml_backend_cuda_buffer_free_buffer,/* .get_base = */ ggml_backend_cuda_buffer_get_base,-@@ -758,6 +766,7 @@ static const ggml_backend_buffer_i ggml_backend_cuda_buffer_interface = {+@@ -859,6 +867,7 @@ static const ggml_backend_buffer_i ggml_backend_cuda_buffer_interface = {/* .cpy_tensor = */ ggml_backend_cuda_buffer_cpy_tensor,/* .clear = */ ggml_backend_cuda_buffer_clear,/* .reset = */ NULL,@@ -111,7 +111,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu};// cuda buffer type-@@ -766,7 +775,7 @@ struct ggml_backend_cuda_buffer_type_context {+@@ -867,7 +876,7 @@ struct ggml_backend_cuda_buffer_type_context {std::string name;};@@ -120,7 +120,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_type_context * ctx = (ggml_backend_cuda_buffer_type_context *)buft->context;return ctx->name.c_str();-@@ -776,7 +785,7 @@ static bool ggml_backend_buft_is_cuda(ggml_backend_buffer_type_t buft) {+@@ -877,7 +886,7 @@ static bool ggml_backend_buft_is_cuda(ggml_backend_buffer_type_t buft) {return buft->iface.get_name == ggml_backend_cuda_buffer_type_get_name;}@@ -129,7 +129,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *)buft->context;ggml_cuda_set_device(buft_ctx->device);-@@ -795,13 +804,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffer(ggml_bac+@@ -896,13 +905,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_buffer_type_alloc_buffer(ggml_bacreturn ggml_backend_buffer_init(buft, ggml_backend_cuda_buffer_interface, ctx, size);}@@ -145,114 +145,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_buffer_type_context * buft_ctx = (ggml_backend_cuda_buffer_type_context *) buft->context;size_t size = tensor->op == GGML_OP_FLASH_ATTN_EXT-@@ -917,19 +926,19 @@ struct ggml_backend_cuda_split_buffer_context {- };----static void ggml_backend_cuda_split_buffer_free_buffer(ggml_backend_buffer_t buffer) {-+static void GGML_CALL ggml_backend_cuda_split_buffer_free_buffer(ggml_backend_buffer_t buffer) {- ggml_backend_cuda_split_buffer_context * ctx = (ggml_backend_cuda_split_buffer_context *)buffer->context;- delete ctx;- }---static void * ggml_backend_cuda_split_buffer_get_base(ggml_backend_buffer_t buffer) {-+static void * GGML_CALL ggml_backend_cuda_split_buffer_get_base(ggml_backend_buffer_t buffer) {- // the pointers are stored in the tensor extras, this is just a dummy address and never dereferenced- return (void *)0x1000;-- GGML_UNUSED(buffer);- }---static enum ggml_status ggml_backend_cuda_split_buffer_init_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor) {-+static enum ggml_status GGML_CALL ggml_backend_cuda_split_buffer_init_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor) {- GGML_ASSERT(tensor->view_src == nullptr); // views of split tensors are not supported- GGML_ASSERT(ggml_is_contiguous(tensor) && "split buffers only supported for contiguous tensors");--@@ -979,7 +988,7 @@ static enum ggml_status ggml_backend_cuda_split_buffer_init_tensor(ggml_backend_- return GGML_STATUS_SUCCESS;- }---static void ggml_backend_cuda_split_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor, const void * data, size_t offset, size_t size) {-+static void GGML_CALL ggml_backend_cuda_split_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml_tensor * tensor, const void * data, size_t offset, size_t size) {- // split tensors must always be set in their entirety at once- GGML_ASSERT(offset == 0);- GGML_ASSERT(size == ggml_nbytes(tensor));-@@ -1018,7 +1027,7 @@ static void ggml_backend_cuda_split_buffer_set_tensor(ggml_backend_buffer_t buff- }- }---static void ggml_backend_cuda_split_buffer_get_tensor(ggml_backend_buffer_t buffer, const ggml_tensor * tensor, void * data, size_t offset, size_t size) {-+static void GGML_CALL ggml_backend_cuda_split_buffer_get_tensor(ggml_backend_buffer_t buffer, const ggml_tensor * tensor, void * data, size_t offset, size_t size) {- // split tensors must always be set in their entirety at once- GGML_ASSERT(offset == 0);- GGML_ASSERT(size == ggml_nbytes(tensor));-@@ -1057,7 +1066,7 @@ static void ggml_backend_cuda_split_buffer_get_tensor(ggml_backend_buffer_t buff- }- }---static void ggml_backend_cuda_split_buffer_clear(ggml_backend_buffer_t buffer, uint8_t value) {-+static void GGML_CALL ggml_backend_cuda_split_buffer_clear(ggml_backend_buffer_t buffer, uint8_t value) {- GGML_UNUSED(buffer);- GGML_UNUSED(value);- }-@@ -1074,11 +1083,12 @@ static const ggml_backend_buffer_i ggml_backend_cuda_split_buffer_interface = {- /* .cpy_tensor = */ NULL,- /* .clear = */ ggml_backend_cuda_split_buffer_clear,- /* .reset = */ NULL,-+ /* .free_struct = */ ggml_backend_cuda_buffer_free_struct,- };-- // cuda split buffer type---static const char * ggml_backend_cuda_split_buffer_type_get_name(ggml_backend_buffer_type_t buft) {-+static const char * GGML_CALL ggml_backend_cuda_split_buffer_type_get_name(ggml_backend_buffer_type_t buft) {- ggml_backend_cuda_split_buffer_type_context * ctx = (ggml_backend_cuda_split_buffer_type_context *)buft->context;-- return ctx->name.c_str();-@@ -1088,7 +1098,7 @@ static bool ggml_backend_buft_is_cuda_split(ggml_backend_buffer_type_t buft) {- return buft->iface.get_name == ggml_backend_cuda_split_buffer_type_get_name;- }---static ggml_backend_buffer_t ggml_backend_cuda_split_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {-+static ggml_backend_buffer_t GGML_CALL ggml_backend_cuda_split_buffer_type_alloc_buffer(ggml_backend_buffer_type_t buft, size_t size) {- // since we don't know the exact split after rounding, we cannot allocate the device buffers at this point- // instead, we allocate them for each tensor separately in init_tensor- // however, the size still represents the maximum cumulative size of all the device buffers after the tensors are allocated,-@@ -1098,13 +1108,13 @@ static ggml_backend_buffer_t ggml_backend_cuda_split_buffer_type_alloc_buffer(gg- return ggml_backend_buffer_init(buft, ggml_backend_cuda_split_buffer_interface, ctx, size);- }---static size_t ggml_backend_cuda_split_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {-+static size_t GGML_CALL ggml_backend_cuda_split_buffer_type_get_alignment(ggml_backend_buffer_type_t buft) {- return 128;-- GGML_UNUSED(buft);- }---static size_t ggml_backend_cuda_split_buffer_type_get_alloc_size(ggml_backend_buffer_type_t buft, const ggml_tensor * tensor) {-+static size_t GGML_CALL ggml_backend_cuda_split_buffer_type_get_alloc_size(ggml_backend_buffer_type_t buft, const ggml_tensor * tensor) {- ggml_backend_cuda_split_buffer_type_context * ctx = (ggml_backend_cuda_split_buffer_type_context *)buft->context;- GGML_ASSERT(ggml_is_contiguous(tensor) && "split buffers only supported for contiguous tensors");--@@ -1132,7 +1142,7 @@ static size_t ggml_backend_cuda_split_buffer_type_get_alloc_size(ggml_backend_bu- return total_size;- }---static bool ggml_backend_cuda_split_buffer_type_is_host(ggml_backend_buffer_type_t buft) {-+static bool GGML_CALL ggml_backend_cuda_split_buffer_type_is_host(ggml_backend_buffer_type_t buft) {- return false;-- GGML_UNUSED(buft);-@@ -1436,7 +1446,7 @@ static bool ggml_backend_cuda_comm_allreduce_tensor(void * comm_ctx_v, struct gg- return comm_ctx->try_allreduce(comm_ctx, tensors);- }---ggml_backend_buffer_type_t ggml_backend_cuda_split_buffer_type(int main_device, const float * tensor_split) {-+ggml_backend_buffer_type_t GGML_CALL ggml_backend_cuda_split_buffer_type(int main_device, const float * tensor_split) {- static std::mutex mutex;- std::lock_guard<std::mutex> lock(mutex);--@@ -1480,7 +1490,7 @@ ggml_backend_buffer_type_t ggml_backend_cuda_split_buffer_type(int main_device,+@@ -1255,7 +1264,7 @@ static bool ggml_backend_cuda_comm_allreduce_tensor(void * comm_ctx_v, struct gg// host buffer type@@ -261,7 +154,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cureturn GGML_CUDA_NAME "_Host";GGML_UNUSED(buft);-@@ -1490,7 +1500,7 @@ static bool ggml_backend_buft_is_cuda_host(ggml_backend_buffer_type_t buft) {+@@ -1265,7 +1274,7 @@ static bool ggml_backend_buft_is_cuda_host(ggml_backend_buffer_type_t buft) {return buft->iface.get_name == ggml_backend_cuda_host_buffer_type_name;}@@ -270,7 +163,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuCUDA_CHECK(cudaFreeHost(buffer->context));}-@@ -1512,17 +1522,25 @@ static void * ggml_cuda_host_malloc(size_t size) {+@@ -1287,17 +1296,25 @@ static void * ggml_cuda_host_malloc(size_t size) {return ptr;}@@ -298,21 +191,22 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cureturn buffer;}-@@ -1650,8 +1668,13 @@ static void ggml_cuda_op_mul_mat_cublas(-- const int cc = ggml_cuda_info().devices[id].cc;+@@ -1643,6 +1660,14 @@ static void ggml_cuda_mul_mat_cublas(ggml_backend_cuda_context & ctx, const ggml+ }+ }+#ifdef GGML_USE_TINYBLAS-+ // TinyBLAS does not support BF16 - it would incorrectly interpret BF16 bits as FP16-+ const bool supports_bf16 = false;-+#else- const bool supports_bf16 = GGML_CUDA_CC_IS_NVIDIA(cc) || GGML_CUDA_CC_IS_AMD(cc) ||- (GGML_CUDA_CC_IS_MTHREADS(cc) && cc >= GGML_CUDA_CC_QY2);++ // TinyBLAS does not support BF16 compute - it would incorrectly interpret++ // BF16 bits as FP16. Fall back to F32 compute (always safe) for correctness.++ if (compute_type == GGML_TYPE_BF16) {++ compute_type = GGML_TYPE_F32;++ }+#endif-- const bool use_fp16 =- src0->type != GGML_TYPE_NVFP4 &&-@@ -3135,20 +3158,20 @@ static bool ggml_cuda_compute_forward(ggml_backend_cuda_context & ctx, struct gg+++ switch (compute_type) {+ case GGML_TYPE_F32:+ ggml_cuda_mul_mat_cublas_impl<GGML_TYPE_F32>(ctx, src0, src1, dst);+@@ -2357,20 +2382,20 @@ static bool ggml_cuda_compute_forward(ggml_backend_cuda_context & ctx, struct gg// backend@@ -336,7 +230,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;-@@ -3157,7 +3180,7 @@ static void ggml_backend_cuda_set_tensor_async(ggml_backend_t backend, ggml_tens+@@ -2379,7 +2404,7 @@ static void ggml_backend_cuda_set_tensor_async(ggml_backend_t backend, ggml_tensCUDA_CHECK(cudaMemcpyAsync((char *) tensor->data + offset, data, size, cudaMemcpyHostToDevice, cuda_ctx->stream()));}@@ -345,7 +239,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;-@@ -3166,7 +3189,7 @@ static void ggml_backend_cuda_get_tensor_async(ggml_backend_t backend, const ggm+@@ -2388,7 +2413,7 @@ static void ggml_backend_cuda_get_tensor_async(ggml_backend_t backend, const ggmCUDA_CHECK(cudaMemcpyAsync(data, (const char *) tensor->data + offset, size, cudaMemcpyDeviceToHost, cuda_ctx->stream()));}@@ -354,7 +248,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cusize_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;-@@ -3177,7 +3200,7 @@ static void ggml_backend_cuda_set_tensor_2d_async(ggml_backend_t backend, struct+@@ -2399,7 +2424,7 @@ static void ggml_backend_cuda_set_tensor_2d_async(ggml_backend_t backend, struct(char *) tensor->data + offset, stride_tensor, data, stride_data, size, n_copies, cudaMemcpyHostToDevice, cuda_ctx->stream()));}@@ -363,7 +257,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cusize_t offset, size_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {ggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;ggml_backend_buffer_t buf = tensor->view_src ? tensor->view_src->buffer : tensor->buffer;-@@ -3188,7 +3211,7 @@ static void ggml_backend_cuda_get_tensor_2d_async(ggml_backend_t backend, const+@@ -2410,7 +2435,7 @@ static void ggml_backend_cuda_get_tensor_2d_async(ggml_backend_t backend, constdata, stride_data, (const char *) tensor->data + offset, stride_tensor, size, n_copies, cudaMemcpyDeviceToHost, cuda_ctx->stream()));}@@ -372,7 +266,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_buffer_t buf_src = src->view_src ? src->view_src->buffer : src->buffer;ggml_backend_buffer_t buf_dst = dst->view_src ? dst->view_src->buffer : dst->buffer;-@@ -3243,7 +3266,7 @@ static bool ggml_backend_cuda_cpy_tensor_async(ggml_backend_t backend_src, ggml_+@@ -2469,7 +2494,7 @@ static bool ggml_backend_cuda_cpy_tensor_async(ggml_backend_t backend_src, ggml_return true;}@@ -381,7 +275,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context;CUDA_CHECK(cudaStreamSynchronize(cuda_ctx->stream()));-@@ -4465,7 +4488,7 @@ static bool ggml_cuda_graph_set_enabled(ggml_backend_cuda_context * cuda_ctx, co+@@ -4073,7 +4098,7 @@ static bool ggml_cuda_graph_set_enabled(ggml_backend_cuda_context * cuda_ctx, co}#endif // USE_CUDA_GRAPH@@ -390,7 +284,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;ggml_cuda_set_device(cuda_ctx->device);-@@ -4524,13 +4547,13 @@ static enum ggml_status ggml_backend_cuda_graph_compute(ggml_backend_t backend,+@@ -4132,13 +4157,13 @@ static enum ggml_status ggml_backend_cuda_graph_compute(ggml_backend_t backend,return GGML_STATUS_SUCCESS;}@@ -406,7 +300,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *)backend->context;if (ggml_backend_is_cuda(backend)) {-@@ -4549,7 +4572,7 @@ static void ggml_backend_cuda_event_wait(ggml_backend_t backend, ggml_backend_ev+@@ -4157,7 +4182,7 @@ static void ggml_backend_cuda_event_wait(ggml_backend_t backend, ggml_backend_ev}}@@ -415,8 +309,8 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_context * cuda_ctx = (ggml_backend_cuda_context *) backend->context;#ifdef USE_CUDA_GRAPH-@@ -4837,7 +4860,7 @@ void ggml_backend_cuda_get_device_memory(int device, size_t * free, size_t * tot- CUDA_CHECK(cudaMemGetInfo(free, total));+@@ -4467,7 +4492,7 @@ void ggml_backend_cuda_get_device_memory(int device, size_t * free, size_t * tot+ *total /= share_count;}-bool ggml_backend_cuda_register_host_buffer(void * buffer, size_t size) {@@ -424,7 +318,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuif (getenv("GGML_CUDA_REGISTER_HOST") == nullptr) {return false;}-@@ -4860,7 +4883,7 @@ bool ggml_backend_cuda_register_host_buffer(void * buffer, size_t size) {+@@ -4490,7 +4515,7 @@ bool ggml_backend_cuda_register_host_buffer(void * buffer, size_t size) {#endif // CUDART_VERSION >= 11010 || defined(GGML_USE_MUSA)}@@ -433,7 +327,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuif (getenv("GGML_CUDA_REGISTER_HOST") == nullptr) {return;}-@@ -4883,12 +4906,12 @@ struct ggml_backend_cuda_device_context {+@@ -4513,12 +4538,12 @@ struct ggml_backend_cuda_device_context {int op_offload_min_batch_size;};@@ -448,7 +342,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;return ctx->description.c_str();}-@@ -4969,7 +4992,7 @@ static bool ggml_backend_cuda_get_available_uma_memory(long * available_memory_k+@@ -4599,7 +4624,7 @@ static bool ggml_backend_cuda_get_available_uma_memory(long * available_memory_k}#endif // defined(__linux__)@@ -456,9 +350,9 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu+static void GGML_CALL ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t * free, size_t * total) {ggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;ggml_cuda_set_device(ctx->device);- CUDA_CHECK(cudaMemGetInfo(free, total));-@@ -4999,7 +5022,7 @@ static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t *-+ cudaError_t err = cudaMemGetInfo(free, total);+@@ -4640,7 +4665,7 @@ static void ggml_backend_cuda_device_get_memory(ggml_backend_dev_t dev, size_t *+ *total /= share_count;}-static enum ggml_backend_dev_type ggml_backend_cuda_device_get_type(ggml_backend_dev_t dev) {@@ -466,7 +360,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *) dev->context;cudaDeviceProp prop;-@@ -5010,7 +5033,7 @@ static enum ggml_backend_dev_type ggml_backend_cuda_device_get_type(ggml_backend+@@ -4651,7 +4676,7 @@ static enum ggml_backend_dev_type ggml_backend_cuda_device_get_type(ggml_backend: GGML_BACKEND_DEVICE_TYPE_GPU;}@@ -475,7 +369,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuggml_backend_cuda_device_context * ctx = (ggml_backend_cuda_device_context *)dev->context;props->name = ggml_backend_cuda_device_get_name(dev);-@@ -5034,24 +5057,24 @@ static void ggml_backend_cuda_device_get_props(ggml_backend_dev_t dev, ggml_back+@@ -4675,24 +4700,24 @@ static void ggml_backend_cuda_device_get_props(ggml_backend_dev_t dev, ggml_back};}@@ -503,8 +397,45 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu+static bool GGML_CALL ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const ggml_tensor * op) {ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) dev->context;- // split buffers can only be used with GGML_OP_MUL_MAT-@@ -5455,7 +5478,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g+ // check if all the sources are allocated on this device+@@ -4791,6 +4816,13 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g+ case GGML_TYPE_Q5_K:+ case GGML_TYPE_Q6_K:+ case GGML_TYPE_Q8_K:++ // IQ quant mul_mat kernels (mmq/mmvq) and the dequant++ // converters are compiled out under GGML_CUDA_NO_IQ_QUANTS++ // (llamafile's --minimize-size CUDA build). Report them++ // unsupported so the scheduler falls back to the CPU++ // backend instead of dispatching to a missing kernel and++ // hitting GGML_ASSERT(convert_func != nullptr).++#ifndef GGML_CUDA_NO_IQ_QUANTS+ case GGML_TYPE_IQ1_M:+ case GGML_TYPE_IQ1_S:+ case GGML_TYPE_IQ2_S:+@@ -4800,6 +4832,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g+ case GGML_TYPE_IQ3_XXS:+ case GGML_TYPE_IQ4_NL:+ case GGML_TYPE_IQ4_XS:++#endif // GGML_CUDA_NO_IQ_QUANTS+ case GGML_TYPE_BF16:+ return true;+ default:+@@ -4890,9 +4923,14 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g+ if (src0_type == GGML_TYPE_Q5_1 && src1_type == GGML_TYPE_F32) {+ return true;+ }++ // ggml_cpy_f32_iq4_nl_cuda is compiled out under++ // GGML_CUDA_NO_IQ_QUANTS; don't advertise the copy or the++ // dispatch below GGML_ABORTs on an unhandled type combination.++#ifndef GGML_CUDA_NO_IQ_QUANTS+ if (src0_type == GGML_TYPE_F32 && src1_type == GGML_TYPE_IQ4_NL) {+ return true;+ }++#endif // GGML_CUDA_NO_IQ_QUANTS+ if (src0_type == GGML_TYPE_F32 && src1_type == GGML_TYPE_I32) {+ return true;+ }+@@ -5108,7 +5146,7 @@ static bool ggml_backend_cuda_device_supports_op(ggml_backend_dev_t dev, const g}}@@ -512,8 +443,8 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu+static bool GGML_CALL ggml_backend_cuda_device_supports_buft(ggml_backend_dev_t dev, ggml_backend_buffer_type_t buft) {ggml_backend_cuda_device_context * dev_ctx = (ggml_backend_cuda_device_context *) dev->context;const bool integrated = ggml_cuda_info().devices[dev_ctx->device].integrated;- return (((ggml_backend_buft_is_cuda(buft) || ggml_backend_buft_is_cuda_split(buft)) && buft->device == dev) || (integrated && ggml_backend_buft_is_cuda_host(buft)));-@@ -5476,13 +5499,13 @@ static int64_t get_op_batch_size(const ggml_tensor * op) {+ return (ggml_backend_buft_is_cuda(buft) && buft->device == dev) || (integrated && ggml_backend_buft_is_cuda_host(buft));+@@ -5129,13 +5167,13 @@ static int64_t get_op_batch_size(const ggml_tensor * op) {}}@@ -529,7 +460,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cu#ifdef GGML_CUDA_NO_PEER_COPYreturn nullptr;#else-@@ -5500,14 +5523,14 @@ static ggml_backend_event_t ggml_backend_cuda_device_event_new(ggml_backend_dev_+@@ -5153,14 +5191,14 @@ static ggml_backend_event_t ggml_backend_cuda_device_event_new(ggml_backend_dev_#endif}@@ -546,7 +477,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.cuGGML_UNUSED(dev);CUDA_CHECK(cudaEventSynchronize((cudaEvent_t)event->context));}-@@ -5536,23 +5559,23 @@ struct ggml_backend_cuda_reg_context {+@@ -5189,23 +5227,23 @@ struct ggml_backend_cuda_reg_context {std::vector<ggml_backend_dev_t> devices;};@@ -574,7 +505,7 @@ diff --git a/ggml/src/ggml-cuda/ggml-cuda.cu b/ggml/src/ggml-cuda/ggml-cuda.custatic std::vector<ggml_backend_feature> features = []() {std::vector<ggml_backend_feature> features;#define _STRINGIFY(...) #__VA_ARGS__-@@ -5613,7 +5636,7 @@ static ggml_backend_feature * ggml_backend_cuda_get_features(ggml_backend_reg_t+@@ -5262,7 +5300,7 @@ static ggml_backend_feature * ggml_backend_cuda_get_features(ggml_backend_reg_tGGML_UNUSED(reg);}diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cu.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cu.patchindex 159312ad..1e15f36e 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cu.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cu.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-cuda/mmq.cu b/ggml/src/ggml-cuda/mmq.cu--- a/llama.cpp/ggml/src/ggml-cuda/mmq.cu+++ b/llama.cpp/ggml/src/ggml-cuda/mmq.cu-@@ -44,6 +44,7 @@ static void ggml_cuda_mul_mat_q_switch_type(ggml_backend_cuda_context & ctx, con+@@ -46,6 +46,7 @@ static void ggml_cuda_mul_mat_q_switch_type(ggml_backend_cuda_context & ctx, concase GGML_TYPE_Q6_K:mul_mat_q_case<GGML_TYPE_Q6_K>(ctx, args, stream);break;@@ -9,7 +9,7 @@ diff --git a/ggml/src/ggml-cuda/mmq.cu b/ggml/src/ggml-cuda/mmq.cucase GGML_TYPE_IQ2_XXS:mul_mat_q_case<GGML_TYPE_IQ2_XXS>(ctx, args, stream);break;-@@ -68,6 +69,7 @@ static void ggml_cuda_mul_mat_q_switch_type(ggml_backend_cuda_context & ctx, con+@@ -70,6 +71,7 @@ static void ggml_cuda_mul_mat_q_switch_type(ggml_backend_cuda_context & ctx, concase GGML_TYPE_IQ4_NL:mul_mat_q_case<GGML_TYPE_IQ4_NL>(ctx, args, stream);break;@@ -17,7 +17,7 @@ diff --git a/ggml/src/ggml-cuda/mmq.cu b/ggml/src/ggml-cuda/mmq.cudefault:GGML_ABORT("fatal error");break;-@@ -285,6 +287,7 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t+@@ -258,6 +260,7 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_tcase GGML_TYPE_Q4_K:case GGML_TYPE_Q5_K:case GGML_TYPE_Q6_K:@@ -25,7 +25,7 @@ diff --git a/ggml/src/ggml-cuda/mmq.cu b/ggml/src/ggml-cuda/mmq.cucase GGML_TYPE_IQ2_XXS:case GGML_TYPE_IQ2_XS:case GGML_TYPE_IQ2_S:-@@ -293,6 +296,7 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t+@@ -266,6 +269,7 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_tcase GGML_TYPE_IQ1_S:case GGML_TYPE_IQ4_XS:case GGML_TYPE_IQ4_NL:@@ -33,7 +33,7 @@ diff --git a/ggml/src/ggml-cuda/mmq.cu b/ggml/src/ggml-cuda/mmq.cummq_supported = true;break;default:-@@ -355,9 +359,11 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_t+@@ -328,9 +332,11 @@ bool ggml_cuda_should_use_mmq(enum ggml_type type, int cc, int64_t ne11, int64_treturn ne11 <= 128;case GGML_TYPE_Q6_K:return ne11 <= (GGML_CUDA_CC_IS_RDNA3_0(cc) ? 128 : 256);diff --git a/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cuh.patch b/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cuh.patchindex 37a3c63b..19f8357e 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cuh.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-cuda_mmq.cuh.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-cuda/mmq.cuh b/ggml/src/ggml-cuda/mmq.cuh--- a/llama.cpp/ggml/src/ggml-cuda/mmq.cuh+++ b/llama.cpp/ggml/src/ggml-cuda/mmq.cuh-@@ -4152,6 +4152,7 @@ extern DECL_MMQ_CASE(GGML_TYPE_Q3_K);+@@ -1478,6 +1478,7 @@ extern DECL_MMQ_CASE(GGML_TYPE_Q3_K);extern DECL_MMQ_CASE(GGML_TYPE_Q4_K);extern DECL_MMQ_CASE(GGML_TYPE_Q5_K);extern DECL_MMQ_CASE(GGML_TYPE_Q6_K);@@ -9,7 +9,7 @@ diff --git a/ggml/src/ggml-cuda/mmq.cuh b/ggml/src/ggml-cuda/mmq.cuhextern DECL_MMQ_CASE(GGML_TYPE_IQ2_XXS);extern DECL_MMQ_CASE(GGML_TYPE_IQ2_XS);extern DECL_MMQ_CASE(GGML_TYPE_IQ2_S);-@@ -4160,6 +4161,7 @@ extern DECL_MMQ_CASE(GGML_TYPE_IQ3_S);+@@ -1486,6 +1487,7 @@ extern DECL_MMQ_CASE(GGML_TYPE_IQ3_S);extern DECL_MMQ_CASE(GGML_TYPE_IQ1_S);extern DECL_MMQ_CASE(GGML_TYPE_IQ4_NL);extern DECL_MMQ_CASE(GGML_TYPE_IQ4_XS);diff --git a/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch b/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patchindex a15c2cd9..f2eb828e 100644--- a/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch+++ b/llama.cpp.patches/patches/ggml_src_ggml-vulkan_ggml-vulkan.cpp.patch@@ -1,7 +1,7 @@diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vulkan.cpp--- a/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp+++ b/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp-@@ -280,11 +280,11 @@ struct vk_queue {+@@ -308,11 +308,11 @@ struct vk_queue {}};@@ -18,7 +18,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vustatic ggml_backend_buffer_type_i ggml_backend_vk_buffer_type_interface = {/* .get_name = */ ggml_backend_vk_buffer_type_name,/* .alloc_buffer = */ ggml_backend_vk_buffer_type_alloc_buffer,-@@ -2224,7 +2224,7 @@ static void ggml_vk_check_results_1(ggml_backend_vk_context * ctx, ggml_cgraph *+@@ -2336,7 +2336,7 @@ static void ggml_vk_check_results_1(ggml_backend_vk_context * ctx, ggml_cgraph *typedef void (*ggml_vk_func_t)(ggml_backend_vk_context * ctx, vk_context& subctx, const ggml_tensor * src0, const ggml_tensor * src1, ggml_tensor * dst);@@ -27,7 +27,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vustatic VkDeviceSize ggml_vk_get_max_buffer_range(const ggml_backend_vk_context * ctx, const vk_buffer &buf, const VkDeviceSize offset) {const VkDeviceSize range = std::min(VkDeviceSize{buf->size - offset},-@@ -14765,20 +14765,28 @@ static bool ggml_backend_buffer_is_vk(ggml_backend_buffer_t buffer) {+@@ -15359,20 +15359,28 @@ static bool ggml_backend_buffer_is_vk(ggml_backend_buffer_t buffer) {return buffer->buft->iface.get_name == ggml_backend_vk_buffer_type_name;}@@ -59,7 +59,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_buffer_init_tensor(" << buffer << " (" << buffer->context << "), " << tensor << ")");if (tensor->view_src != nullptr) {GGML_ASSERT(tensor->view_src->buffer->buft == buffer->buft);-@@ -14786,7 +14794,7 @@ static enum ggml_status ggml_backend_vk_buffer_init_tensor(ggml_backend_buffer_t+@@ -15380,7 +15388,7 @@ static enum ggml_status ggml_backend_vk_buffer_init_tensor(ggml_backend_buffer_treturn GGML_STATUS_SUCCESS;}@@ -68,7 +68,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_buffer_memset_tensor(" << buffer << ", " << tensor << ", " << value << ", " << offset << ", " << size << ")");ggml_backend_vk_buffer_context * buf_ctx = (ggml_backend_vk_buffer_context *)buffer->context;vk_buffer buf = buf_ctx->dev_buffer;-@@ -14799,7 +14807,7 @@ static void ggml_backend_vk_buffer_memset_tensor(ggml_backend_buffer_t buffer, g+@@ -15393,7 +15401,7 @@ static void ggml_backend_vk_buffer_memset_tensor(ggml_backend_buffer_t buffer, gggml_vk_buffer_memset(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, val32, size);}@@ -77,7 +77,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_buffer_set_tensor(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ")");ggml_backend_vk_buffer_context * buf_ctx = (ggml_backend_vk_buffer_context *)buffer->context;vk_buffer buf = buf_ctx->dev_buffer;-@@ -14811,7 +14819,7 @@ static void ggml_backend_vk_buffer_set_tensor(ggml_backend_buffer_t buffer, ggml+@@ -15405,7 +15413,7 @@ static void ggml_backend_vk_buffer_set_tensor(ggml_backend_buffer_t buffer, ggmlggml_vk_buffer_write(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, size);}@@ -86,7 +86,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vusize_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {VK_LOG_DEBUG("ggml_backend_vk_buffer_set_tensor_2d(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ", " <<n_copies << ", " << stride_tensor << ", " << stride_data << ")");-@@ -14825,7 +14833,7 @@ static void ggml_backend_vk_buffer_set_tensor_2d(ggml_backend_buffer_t buffer, g+@@ -15419,7 +15427,7 @@ static void ggml_backend_vk_buffer_set_tensor_2d(ggml_backend_buffer_t buffer, gggml_vk_buffer_write_2d(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, stride_data, stride_tensor, size, n_copies);}@@ -95,7 +95,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_buffer_get_tensor(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ")");ggml_backend_vk_buffer_context * buf_ctx = (ggml_backend_vk_buffer_context *)buffer->context;-@@ -14838,7 +14846,7 @@ static void ggml_backend_vk_buffer_get_tensor(ggml_backend_buffer_t buffer, cons+@@ -15432,7 +15440,7 @@ static void ggml_backend_vk_buffer_get_tensor(ggml_backend_buffer_t buffer, consggml_vk_buffer_read(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, size);}@@ -104,7 +104,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vusize_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {VK_LOG_DEBUG("ggml_backend_vk_buffer_get_tensor_2d(" << buffer << ", " << tensor << ", " << data << ", " << offset << ", " << size << ", " <<n_copies << ", " << stride_tensor << ", " << stride_data << ")");-@@ -14853,7 +14861,7 @@ static void ggml_backend_vk_buffer_get_tensor_2d(ggml_backend_buffer_t buffer, c+@@ -15447,7 +15455,7 @@ static void ggml_backend_vk_buffer_get_tensor_2d(ggml_backend_buffer_t buffer, cggml_vk_buffer_read_2d(buf, vk_tensor_offset(tensor) + tensor->view_offs + offset, data, stride_tensor, stride_data, size, n_copies);}@@ -113,7 +113,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuif (ggml_nbytes(src) == 0) {return true;}-@@ -14874,7 +14882,7 @@ static bool ggml_backend_vk_buffer_cpy_tensor(ggml_backend_buffer_t buffer, cons+@@ -15468,7 +15476,7 @@ static bool ggml_backend_vk_buffer_cpy_tensor(ggml_backend_buffer_t buffer, consUNUSED(buffer);}@@ -122,7 +122,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuggml_backend_vk_buffer_context * ctx = (ggml_backend_vk_buffer_context *)buffer->context;ggml_vk_buffer_memset(ctx->dev_buffer, 0, value, buffer->size);-@@ -14892,16 +14900,17 @@ static ggml_backend_buffer_i ggml_backend_vk_buffer_interface = {+@@ -15486,16 +15494,17 @@ static ggml_backend_buffer_i ggml_backend_vk_buffer_interface = {/* .cpy_tensor = */ ggml_backend_vk_buffer_cpy_tensor,/* .clear = */ ggml_backend_vk_buffer_clear,/* .reset = */ NULL,@@ -142,7 +142,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_MEMORY("ggml_backend_vk_buffer_type_alloc_buffer(" << size << ")");ggml_backend_vk_buffer_type_context * ctx = (ggml_backend_vk_buffer_type_context *) buft->context;-@@ -14917,17 +14926,17 @@ static ggml_backend_buffer_t ggml_backend_vk_buffer_type_alloc_buffer(ggml_backe+@@ -15511,17 +15520,17 @@ static ggml_backend_buffer_t ggml_backend_vk_buffer_type_alloc_buffer(ggml_backereturn ggml_backend_buffer_init(buft, ggml_backend_vk_buffer_interface, bufctx, size);}@@ -163,7 +163,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vureturn ggml_nbytes(tensor);UNUSED(buft);-@@ -14945,18 +14954,18 @@ ggml_backend_buffer_type_t ggml_backend_vk_buffer_type(size_t dev_num) {+@@ -15539,18 +15548,18 @@ ggml_backend_buffer_type_t ggml_backend_vk_buffer_type(size_t dev_num) {// host buffer type@@ -185,7 +185,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_MEMORY("ggml_backend_vk_host_buffer_type_alloc_buffer(" << size << ")");size += 32; // Behave like the CPU buffer type-@@ -14972,19 +14981,20 @@ static ggml_backend_buffer_t ggml_backend_vk_host_buffer_type_alloc_buffer(ggml_+@@ -15566,19 +15575,20 @@ static ggml_backend_buffer_t ggml_backend_vk_host_buffer_type_alloc_buffer(ggml_ggml_backend_buffer_t buffer = ggml_backend_cpu_buffer_from_ptr(ptr, size);buffer->buft = buft;buffer->iface.free_buffer = ggml_backend_vk_host_buffer_free_buffer;@@ -208,7 +208,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vureturn vk_instance.devices[0]->suballocation_block_size;UNUSED(buft);-@@ -15016,13 +15026,13 @@ ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() {+@@ -15610,13 +15620,13 @@ ggml_backend_buffer_type_t ggml_backend_vk_host_buffer_type() {// backend@@ -224,7 +224,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;VK_LOG_DEBUG("ggml_backend_vk_free(" << ctx->name << ")");-@@ -15038,7 +15048,7 @@ static ggml_backend_buffer_type_t ggml_backend_vk_get_default_buffer_type(ggml_b+@@ -15632,7 +15642,7 @@ static ggml_backend_buffer_type_t ggml_backend_vk_get_default_buffer_type(ggml_breturn &ctx->device->buffer_type;}@@ -233,7 +233,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vusize_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {VK_LOG_DEBUG("ggml_backend_vk_set_tensor_2d_async(" << size << ", " << n_copies << ")");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;-@@ -15102,12 +15112,12 @@ static void ggml_backend_vk_set_tensor_2d_async(ggml_backend_t backend, ggml_ten+@@ -15690,12 +15700,12 @@ static void ggml_backend_vk_set_tensor_2d_async(ggml_backend_t backend, ggml_ten}}@@ -248,7 +248,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vusize_t size, size_t n_copies, size_t stride_tensor, size_t stride_data) {VK_LOG_DEBUG("ggml_backend_vk_get_tensor_2d_async(" << size << ", " << n_copies << ")");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;-@@ -15158,12 +15168,12 @@ static void ggml_backend_vk_get_tensor_2d_async(ggml_backend_t backend, const gg+@@ -15746,12 +15756,12 @@ static void ggml_backend_vk_get_tensor_2d_async(ggml_backend_t backend, const gg}}@@ -263,7 +263,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_cpy_tensor_async(" << src << " -> " << dst << ", size=" << ggml_nbytes(src) << ")");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend_dst->context;-@@ -15288,7 +15298,7 @@ static void ggml_vk_synchronize(ggml_backend_vk_context * ctx) {+@@ -15870,7 +15880,7 @@ static void ggml_vk_synchronize(ggml_backend_vk_context * ctx) {}}@@ -272,7 +272,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_synchronize()");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;-@@ -15824,7 +15834,7 @@ static int32_t find_first_set(uint32_t x) {+@@ -16406,7 +16416,7 @@ static int32_t find_first_set(uint32_t x) {return ret;}@@ -281,7 +281,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_graph_compute(" << cgraph->n_nodes << " nodes)");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;-@@ -16228,7 +16238,7 @@ static ggml_status ggml_backend_vk_graph_compute(ggml_backend_t backend, ggml_cg+@@ -16820,7 +16830,7 @@ static ggml_status ggml_backend_vk_graph_compute(ggml_backend_t backend, ggml_cg}// Sort the graph for improved parallelism.@@ -290,7 +290,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu{VK_LOG_DEBUG("ggml_vk_graph_optimize(" << graph->n_nodes << " nodes)");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;-@@ -16485,7 +16495,7 @@ static void ggml_vk_graph_optimize(ggml_backend_t backend, struct ggml_cgraph *+@@ -17077,7 +17087,7 @@ static void ggml_vk_graph_optimize(ggml_backend_t backend, struct ggml_cgraph *}}@@ -299,7 +299,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_event_record(backend=" << backend << ", event=" << event << ")");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;vk_event *vkev = (vk_event *)event->context;-@@ -16523,7 +16533,7 @@ static void ggml_backend_vk_event_record(ggml_backend_t backend, ggml_backend_ev+@@ -17115,7 +17125,7 @@ static void ggml_backend_vk_event_record(ggml_backend_t backend, ggml_backend_evctx->compute_ctx.reset();}@@ -308,7 +308,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_event_wait(backend=" << backend << ", event=" << event << ")");ggml_backend_vk_context * ctx = (ggml_backend_vk_context *)backend->context;vk_event *vkev = (vk_event *)event->context;-@@ -16620,7 +16630,10 @@ void ggml_backend_vk_get_device_memory(int device, size_t * free, size_t * total+@@ -17217,7 +17227,10 @@ void ggml_backend_vk_get_device_memory(int device, size_t * free, size_t * total*total += heap.size;if (membudget_supported && i < budgetprops.heapUsage.size()) {@@ -320,7 +320,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vu} else {*free += heap.size;}-@@ -16688,38 +16701,38 @@ struct ggml_backend_vk_device_context {+@@ -17285,38 +17298,38 @@ struct ggml_backend_vk_device_context {int op_offload_min_batch_size;};@@ -366,7 +366,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;props->name = ggml_backend_vk_device_get_name(dev);-@@ -16735,13 +16748,13 @@ static void ggml_backend_vk_device_get_props(ggml_backend_dev_t dev, struct ggml+@@ -17332,13 +17345,13 @@ static void ggml_backend_vk_device_get_props(ggml_backend_dev_t dev, struct ggml};}@@ -382,7 +382,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;const vk_device& device = ggml_vk_get_device(ctx->device);-@@ -17292,7 +17305,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggm+@@ -17906,7 +17919,7 @@ static bool ggml_backend_vk_device_supports_op(ggml_backend_dev_t dev, const ggmUNUSED(dev);}@@ -391,7 +391,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuif (buft->iface.get_name != ggml_backend_vk_buffer_type_name) {return false;}-@@ -17318,13 +17331,13 @@ static int64_t ggml_vk_get_op_batch_size(const ggml_tensor * op) {+@@ -17932,13 +17945,13 @@ static int64_t ggml_vk_get_op_batch_size(const ggml_tensor * op) {}}@@ -407,7 +407,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;auto device = ggml_vk_get_device(ctx->device);-@@ -17347,7 +17360,7 @@ static ggml_backend_event_t ggml_backend_vk_device_event_new(ggml_backend_dev_t+@@ -17961,7 +17974,7 @@ static ggml_backend_event_t ggml_backend_vk_device_event_new(ggml_backend_dev_t};}@@ -416,7 +416,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;auto device = ggml_vk_get_device(ctx->device);-@@ -17367,7 +17380,7 @@ static void ggml_backend_vk_device_event_free(ggml_backend_dev_t dev, ggml_backe+@@ -17981,7 +17994,7 @@ static void ggml_backend_vk_device_event_free(ggml_backend_dev_t dev, ggml_backedelete event;}@@ -425,7 +425,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_device_event_synchronize(backend=" << dev << ", event=" << event << ")");ggml_backend_vk_device_context * ctx = (ggml_backend_vk_device_context *)dev->context;auto device = ggml_vk_get_device(ctx->device);-@@ -17424,7 +17437,7 @@ static vk_buffer ggml_vk_buffer_from_host_ptr(vk_device & device, void * ptr, si+@@ -18038,7 +18051,7 @@ static vk_buffer ggml_vk_buffer_from_host_ptr(vk_device & device, void * ptr, sireturn buf;}@@ -434,7 +434,7 @@ diff --git a/ggml/src/ggml-vulkan/ggml-vulkan.cpp b/ggml/src/ggml-vulkan/ggml-vuVK_LOG_DEBUG("ggml_backend_vk_device_buffer_from_host_ptr(backend=" << dev << ", ptr=" << ptr << ", size=" << size << ")");GGML_UNUSED(max_tensor_size);-@@ -17462,17 +17475,17 @@ static const struct ggml_backend_device_i ggml_backend_vk_device_i = {+@@ -18076,17 +18089,17 @@ static const struct ggml_backend_device_i ggml_backend_vk_device_i = {/* .event_synchronize = */ ggml_backend_vk_device_event_synchronize,};diff --git a/llama.cpp.patches/patches/ggml_src_gguf.cpp.patch b/llama.cpp.patches/patches/ggml_src_gguf.cpp.patchindex a9a46b47..9c528b2b 100644--- a/llama.cpp.patches/patches/ggml_src_gguf.cpp.patch+++ b/llama.cpp.patches/patches/ggml_src_gguf.cpp.patch@@ -12,7 +12,7 @@ diff --git a/ggml/src/gguf.cpp b/ggml/src/gguf.cpp#include <cinttypes>#include <cstddef>#include <cstdint>-@@ -976,7 +980,54 @@ struct gguf_context * gguf_init_from_buffer(const void * data, size_t size, stru+@@ -980,7 +984,54 @@ struct gguf_context * gguf_init_from_buffer(const void * data, size_t size, strureturn gguf_init_from_reader(gr, params);}@@ -67,7 +67,7 @@ diff --git a/ggml/src/gguf.cpp b/ggml/src/gguf.cppFILE * file = ggml_fopen(fname, "rb");if (!file) {-@@ -987,6 +1038,7 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_p+@@ -991,6 +1042,7 @@ struct gguf_context * gguf_init_from_file(const char * fname, struct gguf_init_pstruct gguf_context * result = gguf_init_from_file_ptr(file, params);fclose(file);return result;diff --git a/llama.cpp.patches/patches/src_llama-context.cpp.patch b/llama.cpp.patches/patches/src_llama-context.cpp.patchindex 26661001..ed636b1e 100644--- a/llama.cpp.patches/patches/src_llama-context.cpp.patch+++ b/llama.cpp.patches/patches/src_llama-context.cpp.patch@@ -1,10 +1,10 @@diff --git a/src/llama-context.cpp b/src/llama-context.cpp--- a/llama.cpp/src/llama-context.cpp+++ b/llama.cpp/src/llama-context.cpp-@@ -476,6 +476,16 @@ void llama_context::sched_reserve() {- LLAMA_LOG_DEBUG("%s: worst-case: n_tokens = %d, n_seqs = %d, n_outputs = %d\n", __func__, n_tokens, n_seqs, n_outputs);+@@ -520,6 +520,16 @@ void llama_context::resolve_fused_ops(const llama_memory_context_i * mctx, uint3+ }+ };- // resolve automatic Flash Attention use+ if (cparams.auto_fa && model.devices.empty()) {+ // llamafile: the CPU Flash Attention path (f16 mad/dot) is significantly+ // slower than the non-FA path on x86 (see mozilla-ai/llamafile#975).@@ -16,5 +16,5 @@ diff --git a/src/llama-context.cpp b/src/llama-context.cpp+ }+if (cparams.auto_fa) {- auto * gf = graph_reserve(1, n_seqs, n_outputs, mctx.get(), true);- if (!gf) {+ resolve(llm_fused_op_flash_attn_probe, cparams.flash_attn);+ cparams.auto_fa = false;diff --git a/llama.cpp.patches/patches/src_models_dflash.cpp.patch b/llama.cpp.patches/patches/src_models_dflash.cpp.patchnew file mode 100644index 00000000..e98d1fd8--- /dev/null+++ b/llama.cpp.patches/patches/src_models_dflash.cpp.patch@@ -0,0 +1,41 @@+diff --git a/src/models/dflash.cpp b/src/models/dflash.cpp+--- a/llama.cpp/src/models/dflash.cpp++++ b/llama.cpp/src/models/dflash.cpp+@@ -60,18 +60,6 @@ void llama_model_dflash::load_arch_tensors(llama_model_loader &) {+ }+ }++-std::unique_ptr<llm_graph_context> llama_model_dflash::build_arch_graph(const llm_graph_params & params) const {+- switch (params.gtype) {+- case LLM_GRAPH_TYPE_ENCODER:+- return std::make_unique<graph<true>>(*this, params);+- case LLM_GRAPH_TYPE_DEFAULT:+- case LLM_GRAPH_TYPE_DECODER:+- return std::make_unique<graph<false>>(*this, params);+- default:+- GGML_ABORT("invalid graph type");+- };+-}+-+ template <>+ ggml_tensor * llama_model_dflash::graph<true>::build_inp_embd_enc() const {+ auto inp_target = std::make_unique<llm_graph_input_embd>(hparams.n_embd_inp_enc());+@@ -274,3 +262,18 @@ llama_model_dflash::graph<false>::graph(const llama_model & model, const llm_gra++ ggml_build_forward_expand(gf, cur);+ }++++// Defined after the graph<true>/graph<false> constructor specializations above:++// cosmocc's clang rejects an explicit specialization that appears after the++// point where make_unique<graph<...>> would implicitly instantiate it.++std::unique_ptr<llm_graph_context> llama_model_dflash::build_arch_graph(const llm_graph_params & params) const {++ switch (params.gtype) {++ case LLM_GRAPH_TYPE_ENCODER:++ return std::make_unique<graph<true>>(*this, params);++ case LLM_GRAPH_TYPE_DEFAULT:++ case LLM_GRAPH_TYPE_DECODER:++ return std::make_unique<graph<false>>(*this, params);++ default:++ GGML_ABORT("invalid graph type");++ };++}diff --git a/llama.cpp.patches/patches/tools_server_server-http.cpp.patch b/llama.cpp.patches/patches/tools_server_server-http.cpp.patchindex 3db61c8c..67583e77 100644--- a/llama.cpp.patches/patches/tools_server_server-http.cpp.patch+++ b/llama.cpp.patches/patches/tools_server_server-http.cpp.patch@@ -1,12 +1,12 @@diff --git a/tools/server/server-http.cpp b/tools/server/server-http.cpp--- a/llama.cpp/tools/server/server-http.cpp+++ b/llama.cpp/tools/server/server-http.cpp-@@ -93,7 +93,7 @@ bool server_http_context::init(const common_params & params) {+@@ -104,7 +104,7 @@ bool server_http_context::init(const common_params & params) {auto & srv = pimpl->srv;-#ifdef CPPHTTPLIB_OPENSSL_SUPPORT+#ifdef CPPHTTPLIB_SSL_ENABLEDif (!params.ssl_file_key.empty() && !params.ssl_file_cert.empty()) {- SRV_INF("running with SSL: key = %s, cert = %s\n", params.ssl_file_key.c_str(), params.ssl_file_cert.c_str());+ SRV_TRC("running with SSL: key = %s, cert = %s\n", params.ssl_file_key.c_str(), params.ssl_file_cert.c_str());srv = std::make_unique<httplib::SSLServer>(diff --git a/llama.cpp.patches/patches/tools_server_server-models.cpp.patch b/llama.cpp.patches/patches/tools_server_server-models.cpp.patchindex 8943db45..80bfdd5a 100644--- a/llama.cpp.patches/patches/tools_server_server-models.cpp.patch+++ b/llama.cpp.patches/patches/tools_server_server-models.cpp.patch@@ -1,15 +1,15 @@diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp--- a/llama.cpp/tools/server/server-models.cpp+++ b/llama.cpp/tools/server/server-models.cpp-@@ -33,6 +33,7 @@- #include <netinet/in.h>- #include <arpa/inet.h>- #include <unistd.h>+@@ -30,6 +30,7 @@+ #include <cstring>++ #ifndef _WIN32+#include <csignal>extern char **environ;#endif-@@ -496,13 +497,19 @@ void server_models::load_models() {+@@ -508,13 +509,19 @@ void server_models::load_models() {}// wait for all targeted models to reach UNLOADED; cv.wait handles unlock/relock@@ -31,7 +31,7 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp// collect all threads to join in one pass while the lock is held:// - monitoring threads from just-unloaded models (to_unload)-@@ -807,9 +814,12 @@ void server_models::unload_lru() {+@@ -765,9 +772,12 @@ void server_models::unload_lru() {// wait for unload to complete{std::unique_lock<std::mutex> lk(mutex);@@ -47,19 +47,21 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp}}}-@@ -823,7 +833,10 @@ void server_models::load(const std::string & name) {+@@ -787,7 +797,12 @@ void server_models::load(const std::string & name, const load_options & opts) {std::unique_lock<std::mutex> lk(mutex);// edge case: block until any in-progress reload has finished so we always load// against the freshest preset and a consistent mapping state- cv.wait(lk, [this]() { return !is_reloading; });-+ // Use wait_for() instead of wait() to work around the XNU futex timeout bug.++ // Use wait_for() instead of wait() to work around a Cosmopolitan libc bug++ // where untimed futex waits on XNU (macOS) expire after ~72 minutes,++ // causing condition_variable::wait() to throw ETIMEDOUT.+ while (is_reloading) {+ cv.wait_for(lk, std::chrono::seconds(30));+ }- auto meta = mapping[name].meta;+ auto meta = opts.custom_meta.has_value() ? *opts.custom_meta : mapping[name].meta;if (meta.status != SERVER_MODEL_STATUS_UNLOADED) {-@@ -915,15 +928,34 @@ void server_models::load(const std::string & name) {+@@ -889,15 +904,34 @@ void server_models::load(const std::string & name, const load_options & opts) {});std::thread stopping_thread([&]() {@@ -95,9 +97,9 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp+ this->cv_stop.wait_for(lk, std::chrono::seconds(30));+ }}- // child crashed or finished on its own — skip graceful shutdown sequence+ // child crashed or finished on its own, skip graceful shutdown sequenceif (child_proc->stopped.load(std::memory_order_acquire)) {-@@ -1237,14 +1269,16 @@ void server_models::wait(const std::string & name, std::function<bool(const serv+@@ -1164,16 +1198,22 @@ void server_models::wait(const std::string & name, std::function<bool(const serv}void server_models::wait(std::unique_lock<std::mutex> & lk, const std::string & name, std::function<bool(const server_model_meta &)> predicate) {@@ -107,20 +109,27 @@ diff --git a/tools/server/server-models.cpp b/tools/server/server-models.cpp+ // causing condition_variable::wait() to throw ETIMEDOUT.+ while (true) {auto it = mapping.find(name);-- if (it != mapping.end()) {+ if (it != mapping.end()) {- return predicate(it->second.meta);--+ if (it != mapping.end() && predicate(it->second.meta)) {++ if (predicate(it->second.meta)) {++ break;++ }++ } else {++ // model was removed from mapping by another code path (e.g. load_models()).++ // nothing left to wait for - tell the caller to proceed.+ break;}-- return false;+- // model was removed from mapping by another code path (e.g. load_models()).+- // nothing left to wait for - tell the caller to proceed.+- return true;- });+ cv.wait_for(lk, std::chrono::seconds(30));+ }}bool server_models::ensure_model_ready(const std::string & name) {-@@ -1894,10 +1928,10 @@ server_http_proxy::server_http_proxy(+@@ -2103,10 +2143,10 @@ server_http_proxy::server_http_proxy(auto pipe = std::make_shared<pipe_t<msg_t>>();if (scheme == "https") {diff --git a/llama.cpp.patches/patches/tools_server_server.cpp.patch b/llama.cpp.patches/patches/tools_server_server.cpp.patchindex f1e2918f..300915fc 100644--- a/llama.cpp.patches/patches/tools_server_server.cpp.patch+++ b/llama.cpp.patches/patches/tools_server_server.cpp.patch@@ -1,7 +1,7 @@diff --git a/tools/server/server.cpp b/tools/server/server.cpp--- a/llama.cpp/tools/server/server.cpp+++ b/llama.cpp/tools/server/server.cpp-@@ -14,6 +14,7 @@+@@ -15,6 +15,7 @@#include <atomic>#include <clocale>#include <exception>@@ -9,7 +9,7 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp#include <signal.h>#include <thread> // for std::thread::hardware_concurrency-@@ -21,6 +22,13 @@+@@ -22,6 +23,13 @@#include <windows.h>#endif@@ -23,14 +23,16 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cppstatic std::function<void(int)> shutdown_handler;static std::atomic_flag is_terminating = ATOMIC_FLAG_INIT;-@@ -71,15 +79,26 @@ static server_http_context::handler_t ex_wrapper(server_http_context::handler_t- };- }+@@ -40,7 +48,19 @@ static inline void signal_handler(int signal) {+ int llama_server(int argc, char ** argv);--// satisfies -Wmissing-declarations--int llama_server(int argc, char ** argv);----int llama_server(int argc, char ** argv) {+ // to be used via CLI (argc / argv are used by router mode only)+-int llama_server(common_params & params, int argc, char ** argv);++// on_ready / on_shutdown_available are llamafile combined-mode (TUI) callbacks.++int llama_server(common_params & params, int argc, char ** argv,++ std::function<void(const std::string &)> on_ready = nullptr,++ std::function<void(std::function<void()>)> on_shutdown_available = nullptr);+++// Core server logic - can be called from llamafile main.cpp or standalone main()+// Optional callbacks for combined mode:+// on_ready: called when server is fully loaded and accepting requests@@ -38,6 +40,18 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp+int server_main(int argc, char ** argv,+ std::function<void(const std::string &)> on_ready,+ std::function<void(std::function<void()>)> on_shutdown_available);+++ void llama_server_terminate();+ void llama_server_terminate() {+ if (shutdown_handler) {+@@ -86,11 +106,23 @@ static server_http_context::handler_t ex_wrapper(server_http_context::handler_t+ }++ int llama_server(int argc, char ** argv) {++ // thin wrapper for the `llama` multiplexer command; combined-mode callbacks++ // are only used by llamafile's own TUI, which calls server_main() directly.++ return server_main(argc, argv, nullptr, nullptr);++}++int server_main(int argc, char ** argv,+ std::function<void(const std::string &)> on_ready,@@ -53,8 +67,23 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp+common_init();- if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_SERVER)) {-@@ -297,6 +316,86 @@ int llama_server(int argc, char ** argv) {+ // start the stream session manager GC right after common init, before any HTTP route can+@@ -104,10 +136,12 @@ int llama_server(int argc, char ** argv) {+ llama_backend_init();+ llama_numa_init(params.numa);++- return llama_server(params, argc, argv);++ return llama_server(params, argc, argv, on_ready, on_shutdown_available);+ }++-int llama_server(common_params & params, int argc, char ** argv) {++int llama_server(common_params & params, int argc, char ** argv,++ std::function<void(const std::string &)> on_ready,++ std::function<void(std::function<void()>)> on_shutdown_available) {+ bool is_run_by_cli = (argv == nullptr);++ common_models_handler models_handler;+@@ -415,6 +449,92 @@ int llama_server(common_params & params, int argc, char ** argv) {llama_backend_free();};@@ -80,8 +109,12 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp+ // media, etc.) that can't be known when the ruleset locks.+ //+ // cosmo installs the SECCOMP/Landlock filters on the calling thread-+ // only (no TSYNC), so quiesce the llama.cpp log worker across the-+ // call: pause() joins it, resume() respawns it under the filter.++ // only (no TSYNC), so quiesce every pre-existing background thread++ // across the call: the llama.cpp log worker (pause() joins it,++ // resume() respawns it under the filter) and the stream-session GC++ // started at the top of server_main() (stop joins it, start++ // respawns it; no sessions exist yet, so stopping is a no-op++ // beyond the join).+ //+ // When --confine-reads is on, unveil() confines reads to these+ // directories, so collect every on-disk path the loader opens@@ -121,8 +154,10 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp+ };+ char promises[64];+ common_log_pause(common_log_main());++ server_stream_session_manager_stop();+ int sandbox = llamafile_sandbox_server(&spec, promises, sizeof(promises));-+ int sandbox_errno = errno; // capture before resume() spawns a thread++ int sandbox_errno = errno; // capture before the respawns spawn threads++ server_stream_session_manager_start();+ common_log_resume(common_log_main());+ if (sandbox == LLAMAFILE_SANDBOX_FAILED) {+ SRV_ERR("sandbox: pledge failed: %s; retry with --unsecure to disable sandboxing\n",@@ -141,7 +176,7 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp// start the HTTP server before loading the model to be able to serve /health requestsif (!ctx_http.start()) {clean_up();-@@ -332,6 +431,13 @@ int llama_server(int argc, char ** argv) {+@@ -447,6 +567,13 @@ int llama_server(common_params & params, int argc, char ** argv) {// this will unblock start_loop()ctx_server.terminate();};@@ -154,11 +189,11 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp+ }}- // TODO: refactor in common/console-@@ -368,6 +474,11 @@ int llama_server(int argc, char ** argv) {+ // register signal handler if not running by CLI+@@ -481,6 +608,11 @@ int llama_server(common_params & params, int argc, char ** argv) {+ // when the HTTP server stops, clean up and exit+ clean_up();} else {- SRV_INF("server is listening on %s\n", ctx_http.listening_address.c_str());-+ // Notify caller that server is ready (for combined mode TUI startup)+ if (on_ready) {+ on_ready(ctx_http.listening_address);@@ -167,7 +202,7 @@ diff --git a/tools/server/server.cpp b/tools/server/server.cpp// optionally, notify router server that this instance is readystd::thread monitor_thread;if (child.is_child()) {-@@ -392,5 +503,56 @@ int llama_server(int argc, char ** argv) {+@@ -505,5 +637,56 @@ int llama_server(common_params & params, int argc, char ** argv) {}}diff --git a/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch b/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patchindex 88a2de27..d280b3d5 100644--- a/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch+++ b/llama.cpp.patches/patches/vendor_cpp-httplib_httplib.cpp.patch@@ -1,7 +1,7 @@diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cpp--- a/llama.cpp/vendor/cpp-httplib/httplib.cpp+++ b/llama.cpp/vendor/cpp-httplib/httplib.cpp-@@ -6333,6 +6333,22 @@ void ThreadPool::cleanup_finished_threads() {+@@ -6416,6 +6416,22 @@ void ThreadPool::cleanup_finished_threads() {}void ThreadPool::worker(bool is_dynamic) {@@ -24,7 +24,7 @@ diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cppfor (;;) {std::function<void()> fn;{-@@ -6350,7 +6366,13 @@ void ThreadPool::worker(bool is_dynamic) {+@@ -6433,7 +6449,13 @@ void ThreadPool::worker(bool is_dynamic) {break;}} else {@@ -39,7 +39,7 @@ diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cpp}idle_thread_count_--;-@@ -12625,6 +12647,13 @@ bool enumerate_macos_keychain_certs(Callback cb) {+@@ -12733,6 +12755,13 @@ bool enumerate_macos_keychain_certs(Callback cb) {#if !defined(_WIN32) && !(defined(__APPLE__) && \defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN))@@ -53,7 +53,7 @@ diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cpp// Common CA certificate file paths on Linux/Unixconst char **system_ca_paths() {static const char *paths[] = {-@@ -12642,6 +12671,10 @@ const char **system_ca_dirs() {+@@ -12750,6 +12779,10 @@ const char **system_ca_dirs() {static const char *dirs[] = {"/etc/ssl/certs", // Debian/Ubuntu"/etc/pki/tls/certs", // RHEL/CentOS"/usr/share/ca-certificates", // Otherdiff --git a/llamafile/BUILD.mk b/llamafile/BUILD.mkindex 470afcf0..d7a995f2 100644--- a/llamafile/BUILD.mk+++ b/llamafile/BUILD.mk@@ -250,6 +250,7 @@ LLAMAFILE_SERVER_SUPPORT_OBJS := \o/$(MODE)/llama.cpp/tools/server/server-models.cpp.o \o/$(MODE)/llama.cpp/tools/server/server-queue.cpp.o \o/$(MODE)/llama.cpp/tools/server/server-schema.cpp.o \+ o/$(MODE)/llama.cpp/tools/server/server-stream.cpp.o \o/$(MODE)/llama.cpp/tools/server/server-task.cpp.o \o/$(MODE)/llama.cpp/tools/server/server-tools.cpp.o \$(UI_GEN_OBJ)diff --git a/llamafile/build-functions.sh b/llamafile/build-functions.shindex 590d3038..9676e5c5 100644--- a/llamafile/build-functions.sh+++ b/llamafile/build-functions.sh@@ -177,6 +177,8 @@ compile_gpu_sources_parallel() {local count=0local total=$NUM_SOURCES+ local pids=()+ local fail=0for src in $CUDA_SOURCES; docount=$((count + 1))@@ -198,6 +200,7 @@ compile_gpu_sources_parallel() {echo "[$count/$total] Compiling: $base.cu"$compiler -c $arch_flags $common_flags -o "$obj" "$src" &+ pids+=("$!")# Limit parallel jobs by waiting when we hit the limitlocal running=$(jobs -r | wc -l)@@ -209,7 +212,19 @@ compile_gpu_sources_parallel() {echo ""echo "Waiting for remaining compilations to finish..."- wait+ # Reap each job individually and check its status. A bare `wait` returns 0+ # even when a background nvcc/hipcc failed, which would silently drop the+ # object and let the link produce an incomplete library (bit us on+ # out-prod.cu / cublasSgemmBatched). Fail loudly instead.+ for pid in "${pids[@]}"; do+ if ! wait "$pid"; then+ fail=1+ fi+ done+ if [ "$fail" -ne 0 ]; then+ echo "Error: one or more GPU source compilations failed (see errors above)" >&2+ return 1+ fi}# Compile core GGML C/C++ sourcesdiff --git a/llamafile/chatbot_cli.cpp b/llamafile/chatbot_cli.cppindex 9f4b72ec..bb556229 100644--- a/llamafile/chatbot_cli.cpp+++ b/llamafile/chatbot_cli.cpp@@ -315,6 +315,7 @@ int cli_main(int argc, char **argv) {// Use mtmd pipeline for multimodal prompt evaluationmtmd_input_text text;text.text = formatted_prompt.c_str();+ text.text_len = formatted_prompt.size();text.add_special = true;text.parse_special = true;diff --git a/llamafile/chatbot_eval.cpp b/llamafile/chatbot_eval.cppindex 7c6e5956..30af677d 100644--- a/llamafile/chatbot_eval.cpp+++ b/llamafile/chatbot_eval.cpp@@ -181,6 +181,7 @@ bool eval_string(std::string_view s, bool add_special, bool parse_special) {// Use mtmd_tokenize to process text with imagesmtmd_input_text text;text.text = extraction.modified_text.c_str();+ text.text_len = extraction.modified_text.size();text.add_special = add_special;text.parse_special = parse_special;diff --git a/llamafile/release.sh b/llamafile/release.shindex 1373b9fb..9805d187 100644--- a/llamafile/release.sh+++ b/llamafile/release.sh@@ -55,7 +55,8 @@ ZIP_FILE="${DEST_DIR}/llamafile-${LLAMAFILE_VERSION}.zip"echo "Zipping ${ZIP_DIR} into ${ZIP_FILE}"# now zip the release directory-zip -r "${ZIP_FILE}" "${ZIP_DIR}"+cd "${RELEASE_DIR}"+zip -r "${ZIP_FILE}" "llamafile-${LLAMAFILE_VERSION}"if [ -f "${ZIP_FILE}" ]; thenecho "${ZIP_FILE} ready."diff --git a/llamafile/rocm.bat b/llamafile/rocm.batindex e4914d09..448f3764 100644--- a/llamafile/rocm.bat+++ b/llamafile/rocm.bat@@ -95,6 +95,7 @@ if not exist "%HIPCC%" (:: -------- AMD GPU architecture targets --------:: gfx906: Vega 20 (Radeon VII, MI50)+:: gfx942: CDNA3 (AMD Instinct MI300X/MI300A):: gfx1030: RDNA2 (RX 6900 XT, RX 6800 series):: gfx1031: RDNA2 (RX 6700 series):: gfx1032: RDNA2 (RX 6600 series)@@ -102,15 +103,22 @@ if not exist "%HIPCC%" (:: gfx1101: RDNA3 (RX 7800 series):: gfx1102: RDNA3 (RX 7600 series):: gfx1103: RDNA3 (RX 7000 mobile)-set "ARCH_FLAGS="-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx906"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1030"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1031"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1032"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1100"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1101"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1102"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1103"+:: ARCH_FLAGS can be overridden via the OFFLOAD_ARCH env var, e.g.+:: set "OFFLOAD_ARCH=--offload-arch=gfx942" ^& llamafile\rocm.bat (single-arch fast build)+if defined OFFLOAD_ARCH (+ set "ARCH_FLAGS=%OFFLOAD_ARCH%"+) else (+ set "ARCH_FLAGS="+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx906"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx942"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1030"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1031"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1032"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1100"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1101"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1102"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1103"+):: -------- copy TinyBLAS files --------copy /y "%LLAMAFILE_DIR%\tinyblas.h" "%BUILD_DIR%\" >nul@@ -124,7 +132,10 @@ set "COMMON_FLAGS=%COMMON_FLAGS% -Wno-ignored-attributes -Wno-nested-anon-types"set "COMMON_FLAGS=%COMMON_FLAGS% -I%BUILD_DIR% -I%GGML_INC_DIR% -I%GGML_SRC_DIR% -I%GGML_CUDA_DIR%"set "COMMON_FLAGS=%COMMON_FLAGS% -I"%HIP_PATH%\include""set "COMMON_FLAGS=%COMMON_FLAGS% -DNDEBUG -DGGML_BUILD=1 -DGGML_SHARED=1 -DGGML_BACKEND_SHARED=1 -DGGML_BACKEND_BUILD=1 -DGGML_MULTIPLATFORM"-set "COMMON_FLAGS=%COMMON_FLAGS% -DGGML_USE_HIP=1 -DGGML_USE_TINYBLAS=1 -DGGML_HIP_NO_VMM -D__HIP_PLATFORM_AMD__"+set "COMMON_FLAGS=%COMMON_FLAGS% -DGGML_USE_HIP=1 -DGGML_USE_TINYBLAS=1 -DGGML_HIP_NO_VMM=1 -D__HIP_PLATFORM_AMD__"+:: --offload-compress shrinks the fat binary (mirrors rocm.sh / #995); requires a+:: recent ROCm HIP SDK -- drop this flag if your clang++ rejects it+set "COMMON_FLAGS=%COMMON_FLAGS% --offload-compress":: -------- extract GGML version --------set "GGML_VERSION=unknown"@@ -191,21 +202,35 @@ for %%f in ("%GGML_CUDA_DIR%\*.cu") do (set "OBJ_FILES=!OBJ_FILES! "!OBJ!"")-:: Template-instances sources-for %%f in ("%GGML_CUDA_DIR%\template-instances\*.cu") do (- set /a COUNT+=1- set "BASE=%%~nf"- set "OBJ=%BUILD_DIR%\ti-!BASE!.obj"- set "SRC=%%f"- if not exist "!OBJ!" (- echo [!COUNT!] Compiling: ti-!BASE!.cu- "%HIPCC%" -c %ARCH_FLAGS% %COMMON_FLAGS% -o "!OBJ!" "!SRC!"- if errorlevel 1 (echo Error compiling ti-!BASE!.cu & exit /b 1)- set /a COMPILED+=1- ) else (- echo [!COUNT!] Skipping: ti-!BASE!.cu (up to date^)+:: Template-instances sources (mirror rocm.sh collect_gpu_sources: include all+:: fattn-mma / fattn-tile / mmf / mmq instances, but only the 4 default fattn-vec+:: quant combos -- f16-f16, q4_0-q4_0, q8_0-q8_0, bf16-bf16 -- to match upstream+:: CMake defaults and keep the DLL size down)+for %%f in (+ "%GGML_CUDA_DIR%\template-instances\fattn-mma-*.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-tile-*.cu"+ "%GGML_CUDA_DIR%\template-instances\mmf-*.cu"+ "%GGML_CUDA_DIR%\template-instances\mmq-*.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-f16-f16.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-q4_0-q4_0.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-q8_0-q8_0.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-bf16-bf16.cu"+) do (+ if exist "%%f" (+ set /a COUNT+=1+ set "BASE=%%~nf"+ set "OBJ=%BUILD_DIR%\ti-!BASE!.obj"+ set "SRC=%%f"+ if not exist "!OBJ!" (+ echo [!COUNT!] Compiling: ti-!BASE!.cu+ "%HIPCC%" -c %ARCH_FLAGS% %COMMON_FLAGS% -o "!OBJ!" "!SRC!"+ if errorlevel 1 (echo Error compiling ti-!BASE!.cu & exit /b 1)+ set /a COMPILED+=1+ ) else (+ echo [!COUNT!] Skipping: ti-!BASE!.cu (up to date^)+ )+ set "OBJ_FILES=!OBJ_FILES! "!OBJ!"")- set "OBJ_FILES=!OBJ_FILES! "!OBJ!"")echo.diff --git a/llamafile/rocm_parallel.bat b/llamafile/rocm_parallel.batindex 36ce7684..a18052ef 100644--- a/llamafile/rocm_parallel.bat+++ b/llamafile/rocm_parallel.bat@@ -117,6 +117,7 @@ if not exist "%PARALLEL%" (:: -------- AMD GPU architecture targets --------:: gfx906: Vega 20 (Radeon VII, MI50)+:: gfx942: CDNA3 (AMD Instinct MI300X/MI300A):: gfx1030: RDNA2 (RX 6900 XT, RX 6800 series):: gfx1031: RDNA2 (RX 6700 series):: gfx1032: RDNA2 (RX 6600 series)@@ -124,15 +125,22 @@ if not exist "%PARALLEL%" (:: gfx1101: RDNA3 (RX 7800 series):: gfx1102: RDNA3 (RX 7600 series):: gfx1103: RDNA3 (RX 7000 mobile)-set "ARCH_FLAGS="-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx906"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1030"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1031"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1032"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1100"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1101"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1102"-set "ARCH_FLAGS=%ARCH_FLAGS% --offload-arch=gfx1103"+:: ARCH_FLAGS can be overridden via the OFFLOAD_ARCH env var, e.g.+:: set "OFFLOAD_ARCH=--offload-arch=gfx942" ^& llamafile\rocm_parallel.bat (single-arch fast build)+if defined OFFLOAD_ARCH (+ set "ARCH_FLAGS=%OFFLOAD_ARCH%"+) else (+ set "ARCH_FLAGS="+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx906"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx942"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1030"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1031"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1032"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1100"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1101"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1102"+ set "ARCH_FLAGS=!ARCH_FLAGS! --offload-arch=gfx1103"+):: -------- copy TinyBLAS files --------copy /y "%LLAMAFILE_DIR%\tinyblas.h" "%BUILD_DIR%\" >nul@@ -146,7 +154,10 @@ set "COMMON_FLAGS=%COMMON_FLAGS% -Wno-ignored-attributes -Wno-nested-anon-types"set "COMMON_FLAGS=%COMMON_FLAGS% -I%BUILD_DIR% -I%GGML_INC_DIR% -I%GGML_SRC_DIR% -I%GGML_CUDA_DIR%"set "COMMON_FLAGS=%COMMON_FLAGS% -I"%HIP_PATH%\include""set "COMMON_FLAGS=%COMMON_FLAGS% -DNDEBUG -DGGML_BUILD=1 -DGGML_SHARED=1 -DGGML_BACKEND_SHARED=1 -DGGML_BACKEND_BUILD=1 -DGGML_MULTIPLATFORM"-set "COMMON_FLAGS=%COMMON_FLAGS% -DGGML_USE_HIP=1 -DGGML_USE_TINYBLAS=1 -DGGML_HIP_NO_VMM -D__HIP_PLATFORM_AMD__"+set "COMMON_FLAGS=%COMMON_FLAGS% -DGGML_USE_HIP=1 -DGGML_USE_TINYBLAS=1 -DGGML_HIP_NO_VMM=1 -D__HIP_PLATFORM_AMD__"+:: --offload-compress shrinks the fat binary (mirrors rocm.sh / #995); requires a+:: recent ROCm HIP SDK -- drop this flag if your clang++ rejects it+set "COMMON_FLAGS=%COMMON_FLAGS% --offload-compress":: -------- extract GGML version --------set "GGML_VERSION=unknown"@@ -205,15 +216,29 @@ for %%f in ("%GGML_CUDA_DIR%\*.cu") do (set "OBJ_FILES=!OBJ_FILES! "!OBJ!"")-:: Template-instances sources-for %%f in ("%GGML_CUDA_DIR%\template-instances\*.cu") do (- set "BASE=%%~nf"- set "OBJ=%BUILD_DIR%\ti-!BASE!.obj"- if not exist "!OBJ!" (- echo ti-!BASE!.cu:::"%HIPCC%" -c %ARCH_FLAGS% %COMMON_FLAGS% -o "!OBJ!" "%%f">> "%CMD_FILE%"- set /a CMD_COUNT+=1+:: Template-instances sources (mirror rocm.sh collect_gpu_sources: include all+:: fattn-mma / fattn-tile / mmf / mmq instances, but only the 4 default fattn-vec+:: quant combos -- f16-f16, q4_0-q4_0, q8_0-q8_0, bf16-bf16 -- to match upstream+:: CMake defaults and keep the DLL size down)+for %%f in (+ "%GGML_CUDA_DIR%\template-instances\fattn-mma-*.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-tile-*.cu"+ "%GGML_CUDA_DIR%\template-instances\mmf-*.cu"+ "%GGML_CUDA_DIR%\template-instances\mmq-*.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-f16-f16.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-q4_0-q4_0.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-q8_0-q8_0.cu"+ "%GGML_CUDA_DIR%\template-instances\fattn-vec-instance-bf16-bf16.cu"+) do (+ if exist "%%f" (+ set "BASE=%%~nf"+ set "OBJ=%BUILD_DIR%\ti-!BASE!.obj"+ if not exist "!OBJ!" (+ echo ti-!BASE!.cu:::"%HIPCC%" -c %ARCH_FLAGS% %COMMON_FLAGS% -o "!OBJ!" "%%f">> "%CMD_FILE%"+ set /a CMD_COUNT+=1+ )+ set "OBJ_FILES=!OBJ_FILES! "!OBJ!"")- set "OBJ_FILES=!OBJ_FILES! "!OBJ!""):: -------- compile .cu sources in parallel --------diff --git a/llamafile/tinyblas-compat.h b/llamafile/tinyblas-compat.hindex 32b5085e..b1d4b747 100644--- a/llamafile/tinyblas-compat.h+++ b/llamafile/tinyblas-compat.h@@ -58,6 +58,7 @@#define cublasSetStream tinyblasSetStream#define cublasGetStream tinyblasGetStream#define cublasSgemm tinyblasSgemm+#define cublasSgemmBatched tinyblasSgemmBatched#define cublasSgemmStridedBatched tinyblasSgemmStridedBatched#define cublasGemmEx tinyblasGemmEx#define cublasGemmBatchedEx tinyblasGemmBatchedExdiff --git a/llamafile/tinyblas.cu b/llamafile/tinyblas.cuindex 758f68ad..77efd71c 100644--- a/llamafile/tinyblas.cu+++ b/llamafile/tinyblas.cu@@ -492,6 +492,23 @@ tinyblasStatus_t tinyblasSgemmStridedBatched(tinyblasHandle_t handle, tinyblasOpreturn TINYBLAS_STATUS_SUCCESS;}+// Pointer-array batched SGEMM. Unlike the strided variant, cublasSgemmBatched+// takes device-resident arrays of per-matrix pointers, so it cannot loop on the+// host; delegate to the typed batched-Ex path, which reads the pointer arrays+// on-device. F32 in/out with F32 compute. New caller: the out_prod broadcast+// path in ggml-cuda/out-prod.cu (upstream #24426).+tinyblasStatus_t tinyblasSgemmBatched(tinyblasHandle_t handle, tinyblasOperation_t transa,+ tinyblasOperation_t transb, int m, int n, int k,+ const float *alpha, const float *const Aarray[], int lda,+ const float *const Barray[], int ldb, const float *beta,+ float *const Carray[], int ldc, int batchCount) {+ return tinyblasGemmBatchedEx(handle, transa, transb, m, n, k, alpha,+ (const void *const *)Aarray, TINYBLAS_R_32F, lda,+ (const void *const *)Barray, TINYBLAS_R_32F, ldb, beta,+ (void *const *)Carray, TINYBLAS_R_32F, ldc, batchCount,+ TINYBLAS_COMPUTE_32F, TINYBLAS_GEMM_DEFAULT);+}+template <int CONFIG, int BM, int BN, int BK, int VE, int WM, int WN, int WNI, int TM, int TN,int TT, typename WORD, typename SRC, typename DST>static __global__ void __launch_bounds__(TT) tinyblasGE_entry(tinyblasOperation_t aT, //diff --git a/llamafile/tinyblas.h b/llamafile/tinyblas.hindex 54e189c6..99b6341f 100644--- a/llamafile/tinyblas.h+++ b/llamafile/tinyblas.h@@ -66,6 +66,11 @@ tinyblasStatus_t tinyblasSgemmStridedBatched(tinyblasHandle_t, tinyblasOperationlong long, const float *, float *, int, long long,int);+tinyblasStatus_t tinyblasSgemmBatched(tinyblasHandle_t, tinyblasOperation_t, tinyblasOperation_t,+ int, int, int, const float *, const float *const[], int,+ const float *const[], int, const float *, float *const[], int,+ int);+tinyblasStatus_t tinyblasStrsmBatched(tinyblasHandle_t, tinyblasSideMode_t, tinyblasFillMode_t,tinyblasOperation_t, tinyblasDiagType_t, int, int,const float *, const float *const[], int,diff --git a/llamafile/version.h b/llamafile/version.hindex ad4ea88e..be75b44e 100644--- a/llamafile/version.h+++ b/llamafile/version.h@@ -20,7 +20,7 @@#define LLAMAFILE_MAJOR 0#define LLAMAFILE_MINOR 10-#define LLAMAFILE_PATCH 4+#define LLAMAFILE_PATCH 5#define LLAMAFILE_VERSION \(100000000 * LLAMAFILE_MAJOR + 1000000 * LLAMAFILE_MINOR + LLAMAFILE_PATCH)diff --git a/llamafile/vulkan.sh b/llamafile/vulkan.shindex c0dd7e50..aead08cb 100755--- a/llamafile/vulkan.sh+++ b/llamafile/vulkan.sh@@ -169,6 +169,8 @@ probe_glslc_extension coopmat2.comp GGML_VULKAN_COOPMAT2_GLSLC_SUPprobe_glslc_extension coopmat2_decode_vector.comp GGML_VULKAN_COOPMAT2_DECODE_VECTOR_GLSLC_SUPPORTprobe_glslc_extension integer_dot.comp GGML_VULKAN_INTEGER_DOT_GLSLC_SUPPORTprobe_glslc_extension bfloat16.comp GGML_VULKAN_BFLOAT16_GLSLC_SUPPORT+probe_glslc_extension float_e2m1.comp GGML_VULKAN_FLOAT_E2M1_GLSLC_SUPPORT+probe_glslc_extension float_e4m3.comp GGML_VULKAN_FLOAT_E4M3_GLSLC_SUPPORTecho ""# The defines bake into vulkan-shaders-gen, the generated header, and everydiff --git a/tests/integration/tests/test_server.py b/tests/integration/tests/test_server.pyindex ec07406e..02c2534f 100644--- a/tests/integration/tests/test_server.py+++ b/tests/integration/tests/test_server.py@@ -79,50 +79,57 @@ class TestServerParameters:@pytest.mark.determinismdef test_server_with_temperature_zero(self, llamafile, server_port, timeouts):- """Test that temperature=0 produces consistent output."""- proc = llamafile.start_server(port=server_port)-- try:- ready = LlamafileRunner.wait_for_server(- server_port, timeout=timeouts.server_ready, proc=proc- )- assert ready-- messages = [- {- "role": "user",- "content": "Hello",- }- ]-- # Use streaming with time limit to handle slow/thinking models- content1 = LlamafileRunner.chat_completion_streaming(- port=server_port,- messages=messages,- temperature=0.0,- collect_timeout=20.0,- )- content2 = LlamafileRunner.chat_completion_streaming(- port=server_port,- messages=messages,- temperature=0.0,- collect_timeout=20.0,- )-- # Compare the shorter response - it should match the prefix of the longer- # (they may differ in length if one timed out earlier)- min_len = min(len(content1), len(content2))- assert min_len > 0, "No content received from either response"-- assert content1[:min_len] == content2[:min_len], (- f"Expected consistent output with temperature=0.\n"- f"Response 1: {content1[:200]!r}...\n"- f"Response 2: {content2[:200]!r}..."- )-- finally:- proc.terminate()- proc.wait()+ """Test that temperature=0 produces consistent output.++ Determinism is checked cold-vs-cold: each completion runs against its+ own freshly-started server, so no state carries between them. This is+ deliberate. Two requests to the *same* running server are not a fair+ determinism check: the first does a full prompt prefill while the+ second reuses the cached prefix KV (cache_prompt defaults to true), and+ the different batch composition perturbs the logits by ~1 ULP -- enough+ to flip a knife's-edge argmax at temperature 0. That is inherent+ floating-point non-associativity in llama.cpp's cached-prefix path, not+ a llamafile bug, so we isolate the kernel's own determinism by giving+ each request an identical cold start.+ """+ messages = [+ {+ "role": "user",+ "content": "Hello",+ }+ ]++ def cold_completion() -> str:+ """Run one completion against a fresh server, then tear it down."""+ proc = llamafile.start_server(port=server_port)+ try:+ assert LlamafileRunner.wait_for_server(+ server_port, timeout=timeouts.server_ready, proc=proc+ ), "Server did not become ready"+ # Use streaming with time limit to handle slow/thinking models+ return LlamafileRunner.chat_completion_streaming(+ port=server_port,+ messages=messages,+ temperature=0.0,+ collect_timeout=20.0,+ )+ finally:+ proc.terminate()+ proc.wait()++ content1 = cold_completion()+ content2 = cold_completion()++ # Compare the shorter response - it should match the prefix of the longer+ # (they may differ in length if one timed out earlier)+ min_len = min(len(content1), len(content2))+ assert min_len > 0, "No content received from either response"++ assert content1[:min_len] == content2[:min_len], (+ f"Expected consistent output with temperature=0.\n"+ f"Response 1: {content1[:200]!r}...\n"+ f"Response 2: {content2[:200]!r}..."+ )def test_server_with_max_tokens(self, llamafile, server_port, timeouts):"""Test that max_tokens parameter limits output."""