ollama - 💡(How to fix) Fix GPU selection support [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
ollama/ollama#14733Fetched 2026-04-08 00:32:20
View on GitHub
Comments
2
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
commented ×2closed ×1labeled ×1
RAW_BUFFERClick to expand / collapse

We have multiple GPUs, but we want Olama to only call one at runtime. Can we support this in Olama's settings? At present, this can also be achieved through setting environment variables, but it will affect other applications that also require GPU, so I hope to manually set it in ollama,thanks!

extent analysis

Fix Plan

1. Modify Olama's Settings

We can add a new setting to Olama to allow users to specify which GPU to use.

2. Update Olama's Code

Here's an example of how you can modify Olama's code to support this new setting:

import os
import torch

class Olama:
    def __init__(self, settings):
        self.settings = settings
        self.device = torch.device(self.get_device())

    def get_device(self):
        # Check if the user has specified a GPU in the settings
        if 'gpu' in self.settings and self.settings['gpu'] is not None:
            # Try to use the specified GPU
            try:
                return torch.device(f"cuda:{self.settings['gpu']}")
            except Exception as e:
                print(f"Error: Unable to use GPU {self.settings['gpu']}. Falling back to CPU.")
                return torch.device('cpu')
        else:
            # If no GPU is specified, try to use the first available GPU
            try:
                return torch.device('cuda:0')
            except Exception as e:
                # If no GPU is available, fall back to CPU
                return torch.device('cpu')

# Example usage:
settings = {
    'gpu': 0  # Specify the GPU to use (0-indexed)
}
olama = Olama(settings)

3. Update Olama's Settings File

You'll also need to update Olama's settings file to include the new gpu setting. This will depend on how Olama stores its settings, but here's an example of how you might do it:

{
    "gpu": 0,  # Specify the GPU to use (0-indexed)
    "other_settings": {
        "key": "value"
    }
}

4. Remove Environment Variable Support

If you want

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

ollama - 💡(How to fix) Fix GPU selection support [2 comments, 2 participants]