AI/ML
How to Run Phi-4 on AWS EC2: A Beginner’s Guide
Free Installation Guide - Step by Step Instructions Inside!
Introduction
Artificial intelligence models like Phi-4 bring immense power to text generation and processing. In this guide, we will walk through how to set up Phi-4 using Docker and Ollama, ensuring a smooth and isolated environment for AI execution.
Step 1: Preparing the Machine
Before running Phi-4, ensure that you have access to a Linux based system (Ubuntu recommended) with Docker installed. If you're using an AWS EC2 instance, connect to it first:
ssh -i "your-key.pem" ubuntu@your-ec2-ip
Then, update system packages:
sudo apt update && sudo apt upgrade -y
If Docker isn’t already installed, add it with:
sudo apt install docker.io -ysudo systemctl start dockersudo systemctl enable docker
Step 2: Deploying Ollama
To run Phi-4, you first need Ollama, a containerized environment optimized for large models. Set up Ollama with:
docker run -d --name ollama -v ollama:/root/.ollama -p 11434:11434 ollama/ollama
This initializes a background container with persistent storage.
Step 3: Loading Phi-4 into Ollama
Once the Ollama container is running, access it using:
docker exec -it ollama /bin/bash
Inside the container, pull Phi-4:
ollama pull phi:4
This step downloads all necessary dependencies.
Step 4: Executing the Model
After installation, start the Phi-4 model with:
ollama run phi:4
To check if it's working, enter a sample query:
>>> What are the key differences between deep learning and machine learning?
Step 5: Adding a Web-Based Interface
To simplify interactions, you can deploy a browser based UI:
docker run -d --name ollama-ui -p 4200:8080 -eLLAMA_BASE_URL=http://<YOUR-EC2-IP>:11434 -v openwebui:/app/backend/data --restart alwaysghcr.io/open-webui/open webui:main
Access the UI via http://<YOUR-EC2-IP>:4200.
Wrapping Up
Deploying Phi-4 using Docker and Ollama offers a seamless way to interact with the model while maintaining an efficient environment. Whether using the command-line or a web UI, this setup ensures easy access and optimal performance.
Ready to transform your business with our technology solutions? Contact Us today to Leverage Our AI/ML Expertise.
Comment