Ollama is an open-source machine learning model that works similarly to OpenAI’s ChatGPT. It makes it easy to get up and running with large language models locally, making it accessible for users who prefer not to rely on cloud-based solutions. We are going to configure a NixOS environment for running Ollama with GPU support using Docker..
To leverage GPU acceleration for running Ollama in Docker containers on NixOS, you need to configure the system properly. Here’s a step by step breakdown of the configuration settings in configuration.nix:
# OpenGL Settings
hardware.opengl = {
enable = true; # Activates OpenGL support, essential for graphical applications and GPU computations.
driSupport = true; # Enables Direct Rendering Infrastructure (DRI) to allow direct access to the GPU.
driSupport32Bit = true; # Provides support for 32-bit applications, which is important if you run legacy or specific software that requires it.
};
# NVIDIA GPU Configuration
hardware.nvidia = {
modesetting.enable = true; # Allows the use of the modesetting driver, which can improve performance.
open = false; # Indicates that proprietary NVIDIA drivers should be used instead of the open-source alternatives.
nvidiaSettings = true; # Enables the NVIDIA settings utility for managing GPU settings.
package = config.boot.kernelPackages.nvidiaPackages.stable;
# Specifies the version of the NVIDIA driver package to use.
};
# Library Path and Video Drivers:
hardware.opengl.setLdLibraryPath = true; # Ensures that the library path is set correctly for OpenGL drivers.
services.xserver.videoDrivers = [ "nvidia" ];
# Specifies that the NVIDIA driver should be used for the X server, enabling graphical applications to utilize the GPU.
# To run the Ollama mode:
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run llama3
docker ps # Check if container is running
docker logs ollama # View container logs
docker stop ollama # Stop the container
docker rm ollama # Remove the container
docker pull ollama/ollama # Pull a new image
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama #