[GH-ISSUE #4808] How to run with a specified gpu? #65071

Closed
opened 2026-05-03 19:41:55 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @zyc1128 on GitHub (Jun 4, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4808

Originally assigned to: @dhiltgen on GitHub.

What is the issue?

I am ruuning a python script traing some model and there is another flask servive binded with ollama.In the script ,I set os.environ["CUDA_VISIBLE_DEVICES"] = "1".I want the flask servive binded with gpu "0",what shoud I do?

OS

Windows

GPU

Nvidia

CPU

Intel

Ollama version

No response

Originally created by @zyc1128 on GitHub (Jun 4, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4808 Originally assigned to: @dhiltgen on GitHub. ### What is the issue? I am ruuning a python script traing some model and there is another flask servive binded with ollama.In the script ,I set os.environ["CUDA_VISIBLE_DEVICES"] = "1".I want the flask servive binded with gpu "0",what shoud I do? ### OS Windows ### GPU Nvidia ### CPU Intel ### Ollama version _No response_
GiteaMirror added the question label 2026-05-03 19:41:55 -05:00
Author
Owner

@MrSuddenJoy commented on GitHub (Jun 4, 2024):

Pass GPU var as a parameter.

<!-- gh-comment-id:2147241190 --> @MrSuddenJoy commented on GitHub (Jun 4, 2024): Pass GPU var as a parameter.
Author
Owner

@octimot commented on GitHub (Jun 5, 2024):

Setting the environment variable directly in the command line should work on Windows:

set CUDA_VISIBLE_DEVICES=1 && [path_to_python] [path_to_ollama]
<!-- gh-comment-id:2148961448 --> @octimot commented on GitHub (Jun 5, 2024): Setting the environment variable directly in the command line should work on Windows: ``` set CUDA_VISIBLE_DEVICES=1 && [path_to_python] [path_to_ollama] ```
Author
Owner

@dhiltgen commented on GitHub (Jun 13, 2024):

GPU selection is described in our docs here

This setting must be applied on the server - see docs here

<!-- gh-comment-id:2166480777 --> @dhiltgen commented on GitHub (Jun 13, 2024): GPU selection is described in our docs [here](https://github.com/ollama/ollama/blob/main/docs/gpu.md#gpu-selection) This setting must be applied on the server - see docs [here](https://github.com/ollama/ollama/blob/main/docs/faq.md#how-do-i-configure-ollama-server)
Author
Owner

@dhiltgen commented on GitHub (Jul 18, 2024):

@UQ-CVLab can you explain your scenario a bit more? How much VRAM do your GPUs have, and what size models are you trying to load. The algorithm should distribute across the GPUs, unless there's asymmetry in the VRAM sizes. I've filed #5773 to track improving the scheduling algorithm for that case which might be what you're experiencing.

<!-- gh-comment-id:2236925275 --> @dhiltgen commented on GitHub (Jul 18, 2024): @UQ-CVLab can you explain your scenario a bit more? How much VRAM do your GPUs have, and what size models are you trying to load. The algorithm should distribute across the GPUs, unless there's asymmetry in the VRAM sizes. I've filed #5773 to track improving the scheduling algorithm for that case which might be what you're experiencing.
Author
Owner

@xiaobaishu0097 commented on GitHub (Jul 19, 2024):

Thank you, @dhiltgen, for your prompt assistance! I have used the wrong account to ask this question and might need to delete the previous message.
Currently, my workstation has four 24GB RTX3090 GPUs, and I am trying to load the llama3:8b. When I start two separate programs with four idle GPUs, Ollama only loads the llama3 once and shares the same llama3 across two processings.

<!-- gh-comment-id:2237839902 --> @xiaobaishu0097 commented on GitHub (Jul 19, 2024): Thank you, @dhiltgen, for your prompt assistance! I have used the wrong account to ask this question and might need to delete the previous message. Currently, my workstation has four 24GB RTX3090 GPUs, and I am trying to load the llama3:8b. When I start two separate programs with four idle GPUs, Ollama only loads the llama3 once and shares the same llama3 across two processings.
Author
Owner

@dhiltgen commented on GitHub (Jul 22, 2024):

The current Concurrency implementation will only load 1 copy of a given model per Ollama instance. If you have multiple GPUs and want to run one copy of the model per GPU, for now, a workaround is to run separate Ollama instances on different ports, and use CUDA_VISIBLE_DEVICES to pin the instances to the specific GPUs.

<!-- gh-comment-id:2243779469 --> @dhiltgen commented on GitHub (Jul 22, 2024): The current Concurrency implementation will only load 1 copy of a given model per Ollama instance. If you have multiple GPUs and want to run one copy of the model per GPU, for now, a workaround is to run separate Ollama instances on different ports, and use CUDA_VISIBLE_DEVICES to pin the instances to the specific GPUs.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#65071