1. 18 Aug, 2025 1 commit
    • Devon Rifkin's avatar
      harmony: convert fn names to be valid ts identifiers · 048bd447
      Devon Rifkin authored
      In <https://github.com/ollama/ollama/issues/11704#issuecomment-3177380197>
      I noticed that hyphens in function names could possibly cause the model
      to become confused. Later in that issue I found other explanations, but
      at a minimum tool names with spaces in them are confusing to the model
      because of the prompt format.
      
      In this change I create a mapper that converts arbitrary tool names into
      valid typescript identifiers. It's a little overly strict in that it
      doesn't allow all unicode characters that might be valid in ts
      identifiers, but it's still very permissive. Since mappings aren't
      reversible, we must temporarily store this mapping in order to unmap it
      if the model comes back with a call. We also handle the case where
      multiple mappings collide into the same mapping and append a counter to
      the end to make them unique
      048bd447
  2. 15 Aug, 2025 1 commit
  3. 14 Aug, 2025 2 commits
    • Jesse Gross's avatar
      llm: New memory management · d5a0d8d9
      Jesse Gross authored
      This changes the memory allocation strategy from upfront estimation to
      tracking actual allocations done by the engine and reacting to that. The
      goal is avoid issues caused by both under-estimation (crashing) and
      over-estimation (low performance due to under-utilized GPUs).
      
      It is currently opt-in and can be enabled for models running on the
      Ollama engine by setting OLLAMA_NEW_ESTIMATES=1. Behavior in other
      cases is unchanged and will continue to use the existing estimates.
      d5a0d8d9
    • Michael Yang's avatar
      update vendored llama.cpp and ggml (#11823) · 1a19df1f
      Michael Yang authored
      * TEMPORARY: Update the llama.cpp upstream to my fork's Granite Four branch
      
      This will be redone once my branch is merged upstream in llama.cpp
      
      * feat: Update all patches
      
      There are a number that are no longer needed at all:
      
      - 0003-embeddings: Embeddings entirely overhauled on master
      - 0008-ensure-KV-cache-is-fully-defragmented: KV caching entirely
          overhauled on master
      - 0019-metal-add-mean-kernel-14267: Merged upstream
      - 0020-CUDA-add-mean-operation-14313: Merged upstream
      
      * feat: Sync llama.cpp and ggml
      
      * fix: Update rsync-filter for all moved/new/removed files
      
      * fix: Add files missing from sync
      
      * fix: Update ggml rsync-filter for new ggml-cpu/arch subdirs
      
      * fix: Add ggml files missing from sync
      
      * fix: Narrow llama.cpp rsync-filter to not include mtmd main tool cpp files
      
      * fix: Remove mtmd main cpp files
      
      * fix: Add missing include in sampling_ext.cpp
      
      * fix: Update llama.go to use mtmd instead of clip/llava
      
      * fix: Add patch for mtmd_input_text
      
      * chore: Ignore *.patched in the patch directory
      
      * fix: Fix support for arch-specific ggml-cpu source files with new arrangement
      
      In https://github.com/ggml-org/llama.cpp/pull/13892, all arch-specific
      implementations were split out into a nested tree structure under
      ggml-cpu/arch. This conflicts with standard CGO layout where all
      arch-specific source files are expected to live in the same directory as
      the parent go module and use suffixes based on GOOS and GOARCH. As such,
      there were really two options for getting this to work:
      
      1. Add a patch on top of the GGML sync to rearrange the files to match the
      GO layout convention
      2. Use CGO directives to conditionally include the nested source files in
      the compilation units
      
      This commit does (2) in order to minimize the set of changes needed on top
      of the upstream file layout. To get this to work, there are two key things
      needed:
      
      1. In cpu.go, #cgo directives are added to explicitly set __${GOARCH}__ in
      the preprocessor directives
      2. In arch-impls.c|cpp, use an #ifdef | #elif defined | #endif chain to
      explicitly include the .c|.cpp files for the given architecture from the
      nested directory
      
      * fix: Use mtmd_helper to correctly load the bitmap for the image
      
      * fix: Apply patch for mtmd_text_input
      
      * fix: Add missing stb to llama.cpp rsync-filter
      
      * fix: Add sync'ed stb vendored header
      
      * fix: Use c++17 and include vendor for go wrapper modules
      
      * fix: Update patch 0015 for upstream implementation of uuid
      
      * feat: Bump to the latest tip of the branch
      
      * fix: Update patches for bump
      
      * feat: Bump back to the cenral repo and point at the latest master
      
      This includes granite 4 and a number of other model architectures!
      
      * fix: Revert changes to ggml export GPU UUID patch
      
      * fix: Add patch for GGML_VERSION and GGML_COMMIT constants
      
      * feat: Sync all patched code
      
      * build: Include cmake/common.cmake in ggml sync
      
      * build: Add top-level include for GNUINstallDirs in CMakeLists.txt
      
      This is used to populate CMAKE_INSTALL_BINDIR
      
      * fix: Add a patch to avoid power throttling API on non-msvc windows builds
      
      * fix: Sync patch changes for ggml-cpu.c
      
      * feat: Bump llama.cpp to 4a4f42
      
      This picks up support for Kimi K2 and PLaMO-2
      
      * feat: Sync llama.cpp
      
      * fix: Handle multi-chunk image encodings from mtmd
      
      * fix: Re-number patches after merge with `main`
      
      * feat: Bump to 41e78c in the makefile
      
      * fix: Fix Solar and argsort/copy patches after bump
      
      * fix: Remove Gemma3n CUDA Graphs patch
      
      It was implemented upstream:
      https://github.com/ggml-org/llama.cpp/pull/14741
      
      * feat: Sync llama.cpp / ggml after latest bump
      
      * build: Remove unnecessary CFLAGS definitions in cpu.go
      
      * fix: Remove unnecessary additions in the rsync-filter
      
      * fix: Remove unused vendored code for chat template parsing
      
      * Revert "fix: Remove Gemma3n CUDA Graphs patch"
      
      This reverts commit d724caced3ce21f08924d4b7801f94ce6638f6ea.
      
      * fix: Update 0020 CUDA Graphs for gemma3n to keep both llama.cpp and ollama fixes
      
      https://github.com/ollama/ollama/pull/11195#issuecomment-3137312394
      
      
      
      * fix: Sync ggml-cuda.cu after keeping both style cuda graph fixes for gemma3n
      
      * unwind mxfp4 patch
      
      Prepare to bump ggml with their impl for mxfp4
      
      * bump
      
      * fix windows build error
      
      * Convert tensors at load time
      
      Repack the mxfp4 tensors as ggmls kernels expect them to be.
      
      * convert mlp bf16 to f32
      
      * buffer the conversion better
      
      * reshape earlier
      
      * openai swiglu
      
      * add ids
      
      * split qkv, gate_up
      
      * fix nested alt tags
      
      * fast attention
      
      * remove debug messages
      
      * fix lint
      
      * remove redundant test
      
      * remap values only if source/target are different
      
      * add back i32->i32 copy
      
      * refactor cpu quants
      
      * clean up vendor
      
      * update patch instructions
      
      * clean up patches
      
      * remove webgpu
      
      * update mem
      
      * also handle gpt-oss
      
      * revert convert changes
      
      ---------
      Signed-off-by: default avatarGabe Goodhart <ghart@us.ibm.com>
      Co-authored-by: default avatarGabe Goodhart <ghart@us.ibm.com>
      Co-authored-by: default avatarDaniel Hiltgen <daniel@ollama.com>
      1a19df1f
  4. 13 Aug, 2025 1 commit
  5. 12 Aug, 2025 1 commit
  6. 11 Aug, 2025 2 commits
    • Devon Rifkin's avatar
      server: fix error when parsing bad harmony tool calls · ee04dbba
      Devon Rifkin authored
      Thanks @moll for reporting!
      
      Fixes: #11781
      ee04dbba
    • Daniel Andersen's avatar
      sched: Add support for grouping GPUs (#10678) · ea7657b5
      Daniel Andersen authored
      This patch modifies Ollama to allow grouping GPUs to memory-fit to the requested model, instead of the former algorithm of using one GPU distributing over all available GPUs.
      
      Benefits:
       - Lower amount of (PCIe-)bus communication between GPUs - especially when they are not very high speed
       - Allowing unallocated GPUs to get into power-saving mode.
       - Significantly reduce VRAM allocation when using more than 2 GPUs in a system
       - Due to the reduced memory allocation, you can run more models simultaneously.
      ea7657b5
  7. 07 Aug, 2025 1 commit
  8. 05 Aug, 2025 2 commits
    • Devon Rifkin's avatar
      tools: support anyOf types · 30f8a68c
      Devon Rifkin authored
      afaik gpt-oss is the first model that meaningfully transforms tool
      function definitions in its template. We found that relatively common
      definitions that include `anyOf` were not working because the template
      was assuming that types were always defined via a `type` field.
      
      anyOf allows for fully recursive types, so I exposed a
      `toTypeScriptType()` function to handle this recursive logic in go and
      keep the templates cleaner. The gpt-oss templates will need to be
      updated to use this.
      
      We should keep building out our function definition support to more
      fully support the parts of json schema that make sense for this use
      case, but in the meantime this will unblock some users (e.g., zed's
      ollama integration w/ gpt-oss). Probably the most urgent is proper array
      support
      30f8a68c
    • Michael Yang's avatar
      gpt-oss (#11672) · fa7776fd
      Michael Yang authored
      
      
      * bf16
      
      * tests
      
      * gpt-oss
      
      * enable gptoss for engine
      
      * rough estimate
      
      * convert to mxfp4
      
      * handle safetensors U8
      
      * clamp glu/linear
      
      * update tokenizer
      
      * MXFP4 support
      
      This implements the Open Compute Microscaling (MX) FP4 format
      as a tensor type with backend implementations focusing
      on mulmat and mulmatid on CPU, CUDA, and Metal.
      
      * Unit tests for MXFP4 support
      
      This exercises various operations and shapes on both CPU and GPU (if detected
      on the system)
      
      * cuda graph
      
      * unit test adjustments
      
      * cuda: optimize memory access
      
      Read 4 bytes at a time (8 elements) when performing mul_mat_vec_mxfp4
      
      * mac: fix crash on old macos versions
      
      cblas_sgemm is only supported on v13.3 and up, however bf16 is
      only supported on v14+ so we were falling back to ggml-blas and
      crashing on bf16 tensors.  Checking for the function being null
      seems to be the simplest way to condittionally avoid registering the
      backend.
      
      * server: Minimum context length for gptoss
      
      This model requires a minimum context length of 8192 to function
      effectively. Users can set higher values through all normal mechanisms
      but lower values will be silently reset.
      
      * ggml: Multiply by numParallel for gptoss sliding window
      
      When computing the graph size estimate, the context size is already
      multiplied by numParallel so estimates reflect that. However, since
      sliding window models use a smaller, fixed context size, they need
      to manually take numParallel into account.
      
      * gpt-oss integration
      
      includes harmony parser and thinking levels, etc.
      
      * fix sync
      
      * fix tests
      
      * fix lint
      
      ---------
      Co-authored-by: default avatarDaniel Hiltgen <daniel@ollama.com>
      Co-authored-by: default avatarJesse Gross <jesse@ollama.com>
      Co-authored-by: default avatarDevon Rifkin <drifkin@drifkin.net>
      fa7776fd
  9. 23 Jul, 2025 1 commit
  10. 22 Jul, 2025 1 commit
  11. 08 Jul, 2025 2 commits
    • Daniel Hiltgen's avatar
      Reduce default parallelism to 1 (#11330) · 20c3266e
      Daniel Hiltgen authored
      The current scheduler algorithm of picking the paralellism based on available
      VRAM complicates the upcoming dynamic layer memory allocation algorithm.  This
      changes the default to 1, with the intent going forward that parallelism is
      explicit and will no longer be dynamically determined.  Removal of the dynamic
      logic will come in a follow up.
      20c3266e
    • Daniel Hiltgen's avatar
      API/CLI context enhancements (#11331) · 34088dbc
      Daniel Hiltgen authored
      * API: expose context size of loaded models
      
      * CLI: add context UX
      
      This adds a column in the ps output to show the models context size.
      34088dbc
  12. 27 Jun, 2025 1 commit
  13. 20 Jun, 2025 1 commit
  14. 18 Jun, 2025 2 commits
  15. 12 Jun, 2025 2 commits
  16. 07 Jun, 2025 1 commit
  17. 06 Jun, 2025 1 commit
  18. 05 Jun, 2025 1 commit
  19. 04 Jun, 2025 1 commit
  20. 29 May, 2025 1 commit
    • Devon Rifkin's avatar
      add thinking support to the api and cli (#10584) · 5f57b0ef
      Devon Rifkin authored
      - Both `/api/generate` and `/api/chat` now accept a `"think"`
        option that allows specifying whether thinking mode should be on or
        not
      - Templates get passed this new option so, e.g., qwen3's template can
        put `/think` or `/no_think` in the system prompt depending on the
        value of the setting
      - Models' thinking support is inferred by inspecting model templates.
        The prefix and suffix the parser uses to identify thinking support is
        also automatically inferred from templates
      - Thinking control & parsing is opt-in via the API to prevent breaking
        existing API consumers. If the `"think"` option is not specified, the
        behavior is unchanged from previous versions of ollama
      - Add parsing for thinking blocks in both streaming/non-streaming mode
        in both `/generate` and `/chat`
      - Update the CLI to make use of these changes. Users can pass `--think`
        or `--think=false` to control thinking, or during an interactive
        session they can use the commands `/se...
      5f57b0ef
  21. 27 May, 2025 1 commit
  22. 24 May, 2025 1 commit
  23. 23 May, 2025 1 commit
  24. 22 May, 2025 2 commits
    • Daniel Hiltgen's avatar
      sched: fix runner leak during reloading unload (#10819) · d950ff12
      Daniel Hiltgen authored
      When the same model is being reloaded rapidly with client connections
      being canceled before the model finishes loading, the queued unload
      event could cause a leak of runners by deleting a different runner from
      the loaded list.
      d950ff12
    • Bruce MacDonald's avatar
      server: improve tensor quantization fallback logic (#10806) · fbe6ae28
      Bruce MacDonald authored
      Fall back to alternative quantization types when a tensor's dimensions aren't divisible by the block size required for the original desired quantization type. If retried quantization types fail, the system ultimately falls back to F16 (half-precision floating point) which has a block size of 1 and can handle any tensor dimension.
      fbe6ae28
  25. 21 May, 2025 1 commit
  26. 19 May, 2025 2 commits
  27. 14 May, 2025 2 commits
  28. 13 May, 2025 1 commit
  29. 12 May, 2025 3 commits