Skip to content

Commit

Permalink
Enable num_gpu layers to be edited and used by ollama
Browse files Browse the repository at this point in the history
  • Loading branch information
tib12 committed Jul 4, 2024
1 parent 824966a commit fff91f7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/apps/ollama/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 759,9 @@ async def generate_chat_completion(

if model_info.params.get("num_ctx", None):
payload["options"]["num_ctx"] = model_info.params.get("num_ctx", None)

if model_info.params.get("num_gpu", None):
payload["options"]["num_gpu"] = model_info.params.get("num_gpu", None)

if model_info.params.get("num_batch", None):
payload["options"]["num_batch"] = model_info.params.get(
Expand Down
46 changes: 46 additions & 0 deletions src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 21,7 @@
top_p: null,
tfs_z: null,
num_ctx: null,
num_gpu: null,
num_batch: null,
num_keep: null,
max_tokens: null,
Expand Down Expand Up @@ -566,6 567,51 @@
</div>
{/if}
</div>

<div class=" py-0.5 w-full justify-between">
<div class="flex w-full justify-between">
<div class=" self-center text-xs font-medium">{$i18n.t('GPU Layers')}</div>

<button
class="p-1 px-3 text-xs flex rounded transition"
type="button"
on:click={() => {
params.num_gpu = (params?.num_gpu ?? null) === null ? 100 : null;
}}
>
{#if (params?.num_gpu ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
{/if}
</button>
</div>

{#if (params?.num_gpu ?? null) !== null}
<div class="flex mt-0.5 space-x-2">
<div class=" flex-1">
<input
id="steps-range"
type="range"
min="-1"
max="999"
step="1"
bind:value={params.num_gpu}
class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
/>
</div>
<div class="">
<input
bind:value={params.num_gpu}
type="number"
class=" bg-transparent text-center w-14"
min="-1"
step="1"
/>
</div>
</div>
{/if}
</div>

<div class=" py-0.5 w-full justify-between">
<div class="flex w-full justify-between">
Expand Down
2 changes: 2 additions & 0 deletions src/lib/components/chat/Settings/General.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 57,7 @@
stop: null,
tfs_z: null,
num_ctx: null,
num_gpu: null,
num_batch: null,
num_keep: null,
max_tokens: null
Expand Down Expand Up @@ -312,6 313,7 @@
top_p: params.top_p !== null ? params.top_p : undefined,
tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
num_gpu: params.num_gpu !== null ? params.num_gpu : undefined,
num_batch: params.num_batch !== null ? params.num_batch : undefined,
num_keep: params.num_keep !== null ? params.num_keep : undefined,
max_tokens: params.max_tokens !== null ? params.max_tokens : undefined,
Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 94,7 @@ type Settings = {
top_k?: string;
top_p?: string;
num_ctx?: string;
num_gpu?: string;
num_batch?: string;
num_keep?: string;
options?: ModelOptions;
Expand Down

0 comments on commit fff91f7

Please sign in to comment.