Why Ollama is Crucial for Docker GenAI Stack?
Published: 2024-02-19 07:09:10

[Docker GenAI](https://github.com/docker/genai-stack) stacks offer a powerful and versatile approach to developing and deploying AI-powered applications. However, for Mac users, getting these stacks up and running requires an essential component: Ollama server. In this blog, we'll delve into why Ollama plays such a crucial role in enabling Docker GenAI on your Mac.

## Understanding Large Language Models (LLMs)

At the heart of Docker GenAI stacks lie large language models (LLMs). These complex AI models possess remarkable capabilities, such as text generation, translation, and code completion. However, their computational demands often necessitate specialized environments for efficient execution.

## Ollama: The Local LLM Powerhouse

This is where [Ollama](https://github.com/ollama/ollama) comes in. Ollama server acts as a local bridge between your Docker containers and LLMs. It provides the necessary infrastructure and APIs for your containers to interact with and leverage the power of LLMs for various AI tasks.

## Key Benefits of Running Ollama Locally on Mac

### 1. Faster Inference

By processing LLMs directly on your Mac, Ollama eliminates the need for remote cloud services, resulting in significantly faster response times for your GenAI applications.

### 2. Enhanced Privacy

Sensitive data can be processed locally within your controlled environment, addressing privacy concerns associated with sending data to external servers.

### 3. Greater Control and Customization

Ollama empowers you to tailor the LLM environment and allocate resources specific to your GenAI project's needs, offering greater flexibility and control.



## 4. Integration with Docker GenAI

Ollama server acts as a bridge between your Docker GenAI stack and the LLMs. It provides the necessary infrastructure and APIs for your Docker containers to interact with and utilize the LLMs for tasks like text generation, translation, or code completion.

## 5. Flexibility

Ollama server supports various open-source LLMs, allowing you to choose the one best suited for your specific needs within your GenAI stack.

## Quick Considerations for running Ollama 

However, running Ollama server locally also comes with some considerations:

## Hardware Requirements

LLMs can be computationally intensive, requiring sufficient hardware resources (CPU, memory, and disk space) on your Mac to run smoothly.

## Technical Expertise

Setting up and configuring Ollama server might require some technical knowledge and familiarity with command-line tools.

Overall, running Ollama server locally offers significant benefits for running LLMs within your Docker GenAI stack, especially when prioritizing speed, privacy, and customization. However, it's crucial to consider the hardware requirements and potential technical complexities before implementing this approach.

## Getting Started

Download Ollama from this [download link](https://ollama.com/download/Ollama-darwin.zip)

## Beyond the Basics

Ollama not only supports running LLMs locally but also offers additional functionalities:

- Multiple LLM Support: Ollama allows you to manage and switch between different LLM models based on your project requirements.
- Resource Management: Ollama provides mechanisms to control and monitor resource allocation for efficient LLM execution.

Ollama supports a list of open-source models available on [ollama.com/library](https://ollama.com/library 'ollama model library')

Here are some example open-source models that can be downloaded:

| Model              | Parameters | Size  | Download                       |
| ------------------ | ---------- | ----- | ------------------------------ |
| Llama 2            | 7B         | 3.8GB | `ollama run llama2`            |
| Mistral            | 7B         | 4.1GB | `ollama run mistral`           |
| Dolphin Phi        | 2.7B       | 1.6GB | `ollama run dolphin-phi`       |
| Phi-2              | 2.7B       | 1.7GB | `ollama run phi`               |
| Neural Chat        | 7B         | 4.1GB | `ollama run neural-chat`       |
| Starling           | 7B         | 4.1GB | `ollama run starling-lm`       |
| Code Llama         | 7B         | 3.8GB | `ollama run codellama`         |
| Llama 2 Uncensored | 7B         | 3.8GB | `ollama run llama2-uncensored` |
| Llama 2 13B        | 13B        | 7.3GB | `ollama run llama2:13b`        |
| Llama 2 70B        | 70B        | 39GB  | `ollama run llama2:70b`        |
| Orca Mini          | 3B         | 1.9GB | `ollama run orca-mini`         |
| Vicuna             | 7B         | 3.8GB | `ollama run vicuna`            |
| LLaVA              | 7B         | 4.5GB | `ollama run llava`             |

> Note: You should have at least 8 GB of RAM available to run the 7B models, 16 GB to run the 13B models, and 32 GB to run the 33B models.


Open the terminal and run the following command:

```
ollama
Usage:
  ollama [flags]
  ollama [command]

Available Commands:
  serve       Start ollama
  create      Create a model from a Modelfile
  show        Show information for a model
  run         Run a model
  pull        Pull a model from a registry
  push        Push a model to a registry
  list        List models
  cp          Copy a model
  rm          Remove a model
  help        Help about any command

Flags:
  -h, --help      help for ollama
  -v, --version   Show version information

Use "ollama [command] --help" for more information about a command.
```

## Listing the model

```
ollama list
NAME         	ID          	SIZE  	MODIFIED
llama2:latest	78e26419b446	3.8 GB	4 weeks ago
```

The output you provided, ollama list, shows that you have one large language model (LLM) downloaded and available on your system:

- NAME: llama2:latest
- ID: 78e26419b446
- SIZE: 3.8 GB
- MODIFIED: 4 weeks ago

This indicates that you have the latest version of the llama2 LLM downloaded and ready to be used with your Docker GenAI stack. Ollama server is likely already running and managing this LLM.

## Pulling the Model

```
$ ollama pull mistral
pulling manifest
pulling manifest
pulling manifest
pulling e8a35b5937a5...  67% ▕██████████      ▏ 2.7 GB/4.1 GB  4.7 MB/s   4m53s
```

## In Conclusion

Ollama server plays an indispensable role in unlocking the full potential of Docker GenAI stacks on Mac. By enabling local LLM execution, Ollama empowers developers to build and deploy cutting-edge AI applications with enhanced speed, privacy, and control. So, the next time you embark on your Docker GenAI journey on Mac, remember that Ollama is your trusted companion for success.

## References

- [How to Install and Run Ollama with Docker: A Beginner’s Guide](https://collabnix.com/getting-started-with-ollama-and-docker/)
- [Ollama: A Lightweight, Extensible Framework for Building Language Models](https://collabnix.com/why-ollama-is-damn-popular/)
- [Getting Started with GenAI Stack powered with Docker, LangChain, Neo4j and Ollama](https://collabnix.com/getting-started-with-genai-stack-powered-with-docker-langchain-neo4j-and-ollama/)