Automatically use ROCm when appropriate - #328
ericcurtin wants to merge 1 commit into
Conversation
Summary of ChangesHello @ericcurtin, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces an automatic detection mechanism for supported AMD GPUs on Linux. Upon detecting a compatible AMD GPU, the system will automatically configure the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- The environment-based GPU autodetection in init() can be surprising; consider moving that logic into an explicit configuration method or flag instead of a package init side-effect.
- The GPU check in main.go duplicates the detection later in the backend; consider removing this duplicate scan to avoid redundant file system accesses.
- Scanning /sys/class/kfd on every download invocation may impact performance; consider caching the detected GPU presence per process.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The environment-based GPU autodetection in init() can be surprising; consider moving that logic into an explicit configuration method or flag instead of a package init side-effect.
- The GPU check in main.go duplicates the detection later in the backend; consider removing this duplicate scan to avoid redundant file system accesses.
- Scanning /sys/class/kfd on every download invocation may impact performance; consider caching the detected GPU presence per process.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request adds automatic detection of AMD GPUs to use the ROCm variant on Linux. The changes are well-intentioned, but there are several critical issues that will prevent the code from building due to function and method redeclarations across different build tags. I've provided comments and suggestions to resolve these build-breaking issues. Additionally, the core GPU detection logic contains a critical bug that could lead to a panic, and there are several opportunities for improving code quality, readability, and performance, for which I've also left suggestions.
3d3badd to
b7e9f39
Compare
On Linux at least Signed-off-by: Eric Curtin <eric.curtin@docker.com>
doringeman
left a comment
There was a problem hiding this comment.
This means docker model install-runner --gpu none won't have effect anymore, right? Because we'll automatically update to the ROCm variant if it's supported.
| ShouldUseGPUVariantLock.Lock() | ||
| defer ShouldUseGPUVariantLock.Unlock() | ||
| ShouldUseGPUVariant = true | ||
| } |
There was a problem hiding this comment.
I'd rather have ShouldUseGPUVariant = runtime.GOOS == "linux" in download.go instead of an init.
For more context, this variable is used by Docker Desktop to determine whether it should display the GPU backed engine checkbox in the UI.
| func (g *GPUInfo) HasSupportedAMDGPU() (bool, error) { | ||
| // AMD GPU detection is only supported on Linux | ||
| return false, nil | ||
| } No newline at end of file |
| @@ -0,0 +1,3 @@ | |||
| //go:build linux | |||
|
|
|||
| package gpuinfo No newline at end of file | |||
There was a problem hiding this comment.
| package gpuinfo | |
| package gpuinfo | |
| } | ||
|
|
||
| return false, nil // No supported AMD GPU found | ||
| } No newline at end of file |
| ) error { | ||
| l.status = fmt.Sprintf("running llama.cpp version: %s", | ||
| getLlamaCppVersion(log, filepath.Join(vendoredServerStoragePath, "com.docker.llama-server"))) | ||
| return errLlamaCppUpdateDisabled |
There was a problem hiding this comment.
I think it'd be better to stick to a consistent logic for picking whether we use acceleration or not. Currently on LInux we expect people to run the model-runner container (appropriate to their usecase and system), so the accelerate/not-accelerate question should be decided in the CLI rather than here.
|
Would you like me to add logic to auto-detect |
Sure, see what we did for Nvidia. But only if it's not crazy or unreliable. Ideally we should be able to probe /proc, /sys or /dev to figure this out (I know that is not always possible though) |
|
@ericcurtin Please see: #342 I will rebase main once your PR is merged. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical duplicate declarations break builds, and the ROCm artifact path mismatch prevents successful installation.
Review effort: Lite
Findings: 3
Open (3)
What changed in this PR
Adds Linux AMD GPU detection and automatic ROCm llama.cpp selection.
Changes:
- Detects supported AMD GPUs via KFD topology.
- Selects CPU or ROCm variants on Linux.
- Adds platform-specific fallbacks and status logging.
| File | Summary |
|---|---|
pkg/inference/backends/llamacpp/download_linux.go |
Selects and downloads CPU or ROCm variants. |
pkg/gpuinfo/memory_windows.go |
Adds Windows fallback behavior. |
pkg/gpuinfo/memory_linux_nocgo.go |
Adds Linux no-cgo memory fallback. |
pkg/gpuinfo/memory_darwin_nocgo.go |
Adds Darwin no-cgo fallback. |
pkg/gpuinfo/memory_darwin_cgo.go |
Adds Darwin cgo fallback. |
pkg/gpuinfo/gpuinfo.go |
Exposes AMD GPU detection. |
pkg/gpuinfo/gpuinfo_not_linux.go |
Adds non-Linux fallback behavior. |
pkg/gpuinfo/gpuinfo_linux.go |
Adds Linux GPU targeting. |
pkg/gpuinfo/amd_gpu_linux.go |
Implements Linux AMD GPU detection. |
main.go |
Logs detected AMD GPU support. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| func (g *GPUInfo) HasSupportedAMDGPU() (bool, error) { | ||
| // AMD GPU detection is only supported on Linux | ||
| return false, nil | ||
| } No newline at end of file |
| // hasSupportedAMDGPU returns true if the system has supported AMD GPUs | ||
| func hasSupportedAMDGPU() (bool, error) { | ||
| return false, errors.New("unimplemented without cgo") | ||
| } |
| // Use ROCm if supported AMD GPU is detected | ||
| if hasAMD { | ||
| log.Info("Supported AMD GPU detected, using ROCm variant") | ||
| desiredVariant = "rocm" | ||
| } |
| // Use ROCm if supported AMD GPU is detected | ||
| if hasAMD { | ||
| log.Info("Supported AMD GPU detected, using ROCm variant") | ||
| desiredVariant = "rocm" |
| // Auto-detect GPU type and set appropriate variant | ||
| // Check if we have supported AMD GPUs and set ROCm variant accordingly | ||
| if hasAMD, err := gpuInfo.HasSupportedAMDGPU(); err == nil && hasAMD { | ||
| log.Info("Supported AMD GPU detected, ROCm will be used automatically") | ||
| // This will be handled by the llama.cpp backend during server download | ||
| } else if err != nil { | ||
| log.Debugf("AMD GPU detection failed: %v", err) | ||
| } |
|
Closing, conflicts and the direction has moved on. Thanks for the reviews! |


On Linux at least