From d469933fd53e3440bb7a412667bdd828b42fca00 Mon Sep 17 00:00:00 2001 From: Fmstrat Date: Tue, 25 Feb 2025 16:19:58 +0000 Subject: [PATCH] add support for Ollama num_gpu --- core/config/types.ts | 1 + core/control-plane/schema.ts | 1 + core/index.d.ts | 1 + core/llm/llms/Ollama.ts | 3 ++- docs/docs/json-reference.md | 1 + docs/docs/reference.md | 1 + .../docusaurus-plugin-content-docs/current/reference.md | 1 + extensions/vscode/config_schema.json | 5 +++++ packages/config-types/src/index.ts | 1 + 9 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/config/types.ts b/core/config/types.ts index 2a68c4c35..8ca427e58 100644 --- a/core/config/types.ts +++ b/core/config/types.ts @@ -843,6 +843,7 @@ declare global { numThreads?: number; useMmap?: boolean; keepAlive?: number; + numGpu?: number; raw?: boolean; stream?: boolean; prediction?: Prediction; diff --git a/core/control-plane/schema.ts b/core/control-plane/schema.ts index 9fcdd2219..32de122b9 100644 --- a/core/control-plane/schema.ts +++ b/core/control-plane/schema.ts @@ -58,6 +58,7 @@ const modelDescriptionSchema = z.object({ numThreads: z.number().optional(), useMmap: z.boolean().optional(), keepAlive: z.number().optional(), + numGpu: z.number().optional(), raw: z.boolean().optional(), stream: z.boolean().optional(), }) diff --git a/core/index.d.ts b/core/index.d.ts index 7d882cb27..86310d97d 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -903,6 +903,7 @@ export interface BaseCompletionOptions { numThreads?: number; useMmap?: boolean; keepAlive?: number; + numGpu?: number; raw?: boolean; stream?: boolean; prediction?: Prediction; diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index b9734acb9..fe1902b89 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -33,12 +33,12 @@ interface OllamaModelFileParams { top_k?: number; top_p?: number; min_p?: number; + num_gpu?: number; // deprecated or not directly supported here: num_thread?: number; use_mmap?: boolean; num_gqa?: number; - num_gpu?: number; num_keep?: number; typical_p?: number; presence_penalty?: number; @@ -264,6 +264,7 @@ class Ollama extends BaseLLM { num_thread: options.numThreads, use_mmap: options.useMmap, min_p: options.minP, + num_gpu: options.numGpu, }; } diff --git a/docs/docs/json-reference.md b/docs/docs/json-reference.md index 470d59921..ac5573b76 100644 --- a/docs/docs/json-reference.md +++ b/docs/docs/json-reference.md @@ -155,6 +155,7 @@ Parameters that control the behavior of text generation and completion settings. - `maxTokens`: The maximum number of tokens to generate in a completion (default: `2048`). - `numThreads`: The number of threads used during the generation process. Available only for Ollama as `num_thread`. - `keepAlive`: For Ollama, this parameter sets the number of seconds to keep the model loaded after the last request, unloading it from memory if inactive (default: `1800` seconds, or 30 minutes). +- `numGpu`: For Ollama, this parameter overrides the number of gpu layers that will be used to load the model into VRAM. - `useMmap`: For Ollama, this parameter allows the model to be mapped into memory. If disabled can enhance response time on low end devices but will slow down the stream. Example diff --git a/docs/docs/reference.md b/docs/docs/reference.md index 03707c4e4..7891ebc4a 100644 --- a/docs/docs/reference.md +++ b/docs/docs/reference.md @@ -157,6 +157,7 @@ Parameters that control the behavior of text generation and completion settings. - `maxTokens`: The maximum number of tokens to generate in a completion (default: `2048`). - `numThreads`: The number of threads used during the generation process. Available only for Ollama as `num_thread`. - `keepAlive`: For Ollama, this parameter sets the number of seconds to keep the model loaded after the last request, unloading it from memory if inactive (default: `1800` seconds, or 30 minutes). +- `numGpu`: For Ollama, this parameter overrides the number of gpu layers that will be used to load the model into VRAM. - `useMmap`: For Ollama, this parameter allows the model to be mapped into memory. If disabled can enhance response time on low end devices but will slow down the stream. Example diff --git a/docs/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference.md b/docs/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference.md index 98addf212..1252bd2fd 100644 --- a/docs/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference.md +++ b/docs/i18n/zh-CN/docusaurus-plugin-content-docs/current/reference.md @@ -155,6 +155,7 @@ Parameters that control the behavior of text generation and completion settings. - `maxTokens`: The maximum number of tokens to generate in a completion (default: `2048`). - `numThreads`: The number of threads used during the generation process. Available only for Ollama as `num_thread`. - `keepAlive`: For Ollama, this parameter sets the number of seconds to keep the model loaded after the last request, unloading it from memory if inactive (default: `1800` seconds, or 30 minutes). +- `numGpu`: For Ollama, this parameter overrides the number of gpu layers that will be used to load the model into VRAM. - `useMmap`: For Ollama, this parameter allows the model to be mapped into memory. If disabled can enhance response time on low end devices but will slow down the stream. Example diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 259d3e7c8..50fabaaaa 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -71,6 +71,11 @@ "title": "Ollama keep_alive", "description": "The number of seconds after no requests are made to unload the model from memory. Defaults to 60*30 = 30min", "type": "integer" + }, + "numGpu": { + "title": "Ollama num_gpu", + "description": "Override the number of gpu layers used when loading the model", + "type": "integer" } } }, diff --git a/packages/config-types/src/index.ts b/packages/config-types/src/index.ts index 8a0806d7b..41cdce373 100644 --- a/packages/config-types/src/index.ts +++ b/packages/config-types/src/index.ts @@ -13,6 +13,7 @@ export const completionOptionsSchema = z.object({ numThreads: z.number().optional(), useMmap: z.boolean().optional(), keepAlive: z.number().optional(), + numGpu: z.number().optional(), raw: z.boolean().optional(), stream: z.boolean().optional(), });