ollama - ✅(Solved) Fix GPU detection silently falls back to CPU when working directory is inaccessible to service user [2 pull requests, 1 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#15079Fetched 2026-04-08 01:36:27
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Participants
Timeline (top)
cross-referenced ×2labeled ×1referenced ×1

When ollama serve is started as a service user (e.g. www-data, wwwrun, nobody) and the current working directory is not accessible to that user, GPU detection silently fails and ollama falls back to library=cpu with no error message or warning.

Error Message

When ollama serve is started as a service user (e.g. www-data, wwwrun, nobody) and the current working directory is not accessible to that user, GPU detection silently fails and ollama falls back to library=cpu with no error message or warning.

Root Cause

The GPU discovery subprocess (the internal ollama runner --ollama-engine process spawned by bootstrapDevices()) inherits the working directory of the parent process.

During CUDA backend initialization, libcuda.so (or a related NVIDIA library) accesses the working directory — most likely to write its JIT kernel cache. If the cwd is a directory the service user cannot access (e.g. /root with mode 700), the CUDA backend fails to initialize. Since the discovery subprocess discards stdout/stderr unless OLLAMA_DEBUG=2 (trace level), this failure is completely invisible to the operator. Ollama then falls back to CPU without any log entry at the default or info log level.

Fix Action

Workaround

Ensure ollama is started from a directory accessible to the service user, e.g. by adding cd /tmp (or any world-accessible directory) before exec ollama serve in the start script.

PR fix notes

PR #15092: Set runner subprocess working directory to temp dir for GPU discovery

Description (problem / solution / changelog)

Fixes #15079

When ollama runs as a service user (e.g. www-data) and the current working directory is inaccessible, GPU discovery silently fails because the runner subprocess inherits the parent's cwd. CUDA initialization accesses the working directory for JIT kernel cache and fails when it can't write there.

Sets cmd.Dir to os.TempDir() so the runner process always starts in an accessible directory.

Changed files

  • llm/server.go (modified, +1/-0)

PR #15163: fix(discover): warn when GPU backend runner fails to start

Description (problem / solution / changelog)

When llm.StartRunner returns an error during bootstrap device discovery, the failure was logged at Debug level and silently swallowed. Users with GPU hardware see ollama fall back to CPU with no visible indication of why.

Upgrade to Warn so that the cause is visible at the default log level.

Also fix a typo: 'to discovery' -> 'to discover'.

Fixes #15079

Changed files

  • discover/runner.go (modified, +1/-1)

Code Example

# Fails silently → library=cpu
sudo -u www-data bash -c 'cd /root; ollama serve'

# Works → library=cuda
sudo -u www-data bash -c 'cd /tmp; ollama serve'

---

os.Chdir(os.TempDir())
RAW_BUFFERClick to expand / collapse

Description

When ollama serve is started as a service user (e.g. www-data, wwwrun, nobody) and the current working directory is not accessible to that user, GPU detection silently fails and ollama falls back to library=cpu with no error message or warning.

Steps to Reproduce

# Fails silently → library=cpu
sudo -u www-data bash -c 'cd /root; ollama serve'

# Works → library=cuda
sudo -u www-data bash -c 'cd /tmp; ollama serve'

The only difference is the working directory. The environment (PATH, OLLAMA_HOST, CUDA env vars, DISPLAY, XAUTHORITY) is identical.

Environment

  • OS: openSUSE Tumbleweed (Linux 6.x)
  • GPU: NVIDIA RTX A3000 12GB (Optimus/PRIME, Dell Precision 7770)
  • ollama built from source (current main)
  • Service user: wwwrun (equivalent of www-data)

Root Cause

The GPU discovery subprocess (the internal ollama runner --ollama-engine process spawned by bootstrapDevices()) inherits the working directory of the parent process.

During CUDA backend initialization, libcuda.so (or a related NVIDIA library) accesses the working directory — most likely to write its JIT kernel cache. If the cwd is a directory the service user cannot access (e.g. /root with mode 700), the CUDA backend fails to initialize. Since the discovery subprocess discards stdout/stderr unless OLLAMA_DEBUG=2 (trace level), this failure is completely invisible to the operator. Ollama then falls back to CPU without any log entry at the default or info log level.

Impact

This is a silent failure — operators get no indication that GPU detection failed. The symptom (running on CPU instead of GPU) has many possible causes, and nothing in the logs points to the working directory as the culprit. Debugging this is extremely time-consuming.

Suggested Fix

Before spawning the discovery subprocess in bootstrapDevices(), change to a safe working directory:

os.Chdir(os.TempDir())

Alternatively (or additionally): log a warning at Info level when a GPU backend fails to load, so the failure is visible without requiring trace-level debugging.

Workaround

Ensure ollama is started from a directory accessible to the service user, e.g. by adding cd /tmp (or any world-accessible directory) before exec ollama serve in the start script.

extent analysis

Fix Plan

To fix the silent failure of GPU detection due to inaccessible working directories, follow these steps:

  • Change the working directory to a safe location before spawning the discovery subprocess in bootstrapDevices():
os.Chdir(os.TempDir())
  • Alternatively, log a warning at Info level when a GPU backend fails to load:
log.Info("GPU backend failed to load, falling back to CPU")
  • Update the start script to ensure ollama is started from a directory accessible to the service user:
cd /tmp; exec ollama serve

Verification

To verify the fix, start ollama as a service user from an inaccessible directory and check the logs for the warning message or the successful use of the GPU backend.

Extra Tips

  • Ensure the service user has access to the temporary directory used in the fix.
  • Consider adding additional logging or monitoring to detect similar issues in the future.
  • Review the permissions and accessibility of directories used by ollama to prevent similar issues.

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 - ✅(Solved) Fix GPU detection silently falls back to CPU when working directory is inaccessible to service user [2 pull requests, 1 participants]