Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add GPU support for NVIDIA & AMD GPUs in installation and Docker setup (ollama) #229

Open
wants to merge 5 commits into
base: release/2.2.0
Choose a base branch
from

Conversation

psyray
Copy link
Contributor

@psyray psyray commented Nov 10, 2024

Fixes #227

Config for the 2 types of card has been added, but only NVIDIA GPU is effective and tested for the moment.
I don't have any AMD card to do testing.
Maybe later, but for now let's go with NVIDIA

Summary by Sourcery

Add GPU support for NVIDIA and AMD GPUs in the installation and Docker setup, including scripts for GPU detection and configuration, and Dockerfiles for specific GPU types.

New Features:

  • Introduce GPU support for NVIDIA and AMD GPUs in the installation script and Docker setup, allowing users to leverage GPU capabilities for enhanced performance.

Enhancements:

  • Add a new script, gpu_support.sh, to detect GPU type and configure the environment accordingly.
  • Update install.sh to check for GPU support and install necessary dependencies based on the detected GPU type.
  • Modify the Makefile to include GPU configuration options, enabling users to activate GPU support during Docker operations.

Build:

  • Create separate Dockerfiles for NVIDIA and AMD GPU support under the docker/ollama directory.
  • Add a new Docker Compose file, docker-compose.gpu.yml, to handle GPU-specific configurations.

Todo

  • NVIDIA test
  • AMD test

…etup

- Introduced GPU support for both NVIDIA and AMD GPUs in the installation script and Docker setup.
- Added a new script gpu_support.sh to detect GPU type and configure the environment accordingly.
- Updated install.sh to check for GPU support and install necessary dependencies based on the detected GPU type.
- Modified the Makefile to include GPU configuration options, allowing users to enable GPU support during Docker operations.
- Added new Docker Compose file docker-compose.gpu.yml to handle GPU-specific configurations.
- Created separate Dockerfiles for NVIDIA and AMD GPU support under the docker/ollama directory.
- Removed redundant checks for GPU support in the .env file and streamlined the GPU detection process.
- Replaced "rocm" with "amd" for AMD GPU detection and configuration.
- Simplified Docker Compose GPU configuration by removing specific GPU capabilities and adding general GPU settings.
- Updated the Makefile to handle GPU configuration more efficiently, including the use of profiles for Docker Compose.
- Added labels to the Dockerfile for GPU support information.
- Modified the GPU detection script to reflect changes in AMD GPU identification.
-Updated the GPU settings in the Docker Compose file to use NVIDIA-specific configurations, removing AMD ROCm-specific settings.
-Registered a new model, OllamaSettings, in the Django admin interface.
- Enhanced the Gunicorn server configuration in the Docker entrypoint script by adding timeout and keep-alive settings to improve server performance and reliability.
…anager

Removed the 'selected' field from the defaults dictionary in the OllamaManager class to clean up unused code.
@psyray psyray added the enhancement New feature or request label Nov 10, 2024
@psyray psyray requested review from AnonymousWP and 0b3ud November 10, 2024 19:26
@psyray psyray self-assigned this Nov 10, 2024
Copy link
Contributor

sourcery-ai bot commented Nov 10, 2024

Reviewer's Guide by Sourcery

This PR implements GPU support for NVIDIA and AMD GPUs in the installation process and Docker setup. The implementation includes automatic GPU detection, installation of required drivers/toolkits, and Docker configuration for GPU support. The changes primarily focus on NVIDIA GPU support, with AMD support added but untested.

Sequence diagram for GPU detection and setup

sequenceDiagram
    participant User
    participant InstallScript as install.sh
    participant GPUSupportScript as gpu_support.sh
    participant Docker

    User->>InstallScript: Run installation
    InstallScript->>GPUSupportScript: Source gpu_support.sh
    InstallScript->>GPUSupportScript: Detect GPU type
    GPUSupportScript-->>InstallScript: Return GPU type (nvidia/amd/none)
    InstallScript->>InstallScript: Check GPU type
    alt NVIDIA GPU detected
        InstallScript->>Docker: Install NVIDIA Container Toolkit
        InstallScript->>Docker: Configure Docker runtime for NVIDIA
    else AMD GPU detected
        InstallScript->>Docker: Install ROCm
        InstallScript->>Docker: Configure user groups
    else No GPU detected
        InstallScript->>InstallScript: Continue with CPU-only setup
    end
    InstallScript-->>User: Installation complete
Loading

Class diagram for GPU support scripts and Dockerfiles

classDiagram
    class InstallScript {
        +check_gpu_support()
        +install_make()
        +main()
    }
    class GPUSupportScript {
        +detect_gpu_type()
        +debug_log()
    }
    class Makefile {
        +gpu_config()
    }
    class DockerComposeGPU {
        +services
        +profiles
    }
    class DockerfileNVIDIA {
        +NVIDIA_VISIBLE_DEVICES
        +NVIDIA_DRIVER_CAPABILITIES
    }
    class DockerfileAMD {
        +HSA_OVERRIDE_GFX_VERSION
        +ROCR_VISIBLE_DEVICES
    }
    InstallScript --> GPUSupportScript : uses
    InstallScript --> Makefile : modifies
    DockerComposeGPU --> DockerfileNVIDIA : extends
    DockerComposeGPU --> DockerfileAMD : extends
Loading

File-Level Changes

Change Details Files
Added GPU detection and configuration system
  • Created new script for automatic GPU detection (NVIDIA/AMD)
  • Added GPU type validation and environment configuration
  • Implemented interactive and non-interactive GPU setup options
  • Added error handling for GPU detection and setup failures
scripts/gpu_support.sh
install.sh
Enhanced Docker and Makefile system for GPU support
  • Added GPU-specific Docker Compose configuration
  • Implemented GPU detection and runtime configuration in Makefile
  • Added GPU support flags to build and deployment commands
  • Created separate Dockerfiles for NVIDIA and AMD GPU configurations
Makefile
docker/docker-compose.gpu.yml
docker/ollama/nvidia.Dockerfile
docker/ollama/amd.Dockerfile
Added NVIDIA Container Toolkit integration
  • Added NVIDIA repository and key configuration
  • Implemented NVIDIA Container Toolkit installation
  • Added Docker runtime configuration for NVIDIA GPUs
  • Configured environment variables for NVIDIA GPU support
install.sh
docker/ollama/nvidia.Dockerfile
Added AMD ROCm support framework
  • Added ROCm repository and installation configuration
  • Implemented user group configuration for AMD GPU access
  • Added ROCm-specific environment variables
  • Created AMD-specific Docker configuration
install.sh
docker/ollama/amd.Dockerfile

Possibly linked issues

  • Release/2.1.0 #1: The PR addresses the issue by adding NVIDIA GPU support in the ollama Docker setup.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @psyray - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The AMD GPU support is currently untested and should be clearly marked as experimental in the documentation. Consider adding warning logs when users attempt to use AMD GPU support to make it clear it's not production-ready.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

install.sh Show resolved Hide resolved
@psyray psyray linked an issue Nov 10, 2024 that may be closed by this pull request
3 tasks
@psyray psyray changed the base branch from release/2.2.0 to release/2.1.1 November 13, 2024 19:36
@psyray psyray changed the base branch from release/2.1.1 to release/2.2.0 November 17, 2024 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(ollama): add setup to use NVIDIA GPU within ollama container
1 participant