Together AI raises 800 million dollars in Series C as open-source cloud demand surges
Back to Tutorials
techTutorialintermediate

Together AI raises 800 million dollars in Series C as open-source cloud demand surges

July 1, 202624 views4 min read

Learn to deploy open-source AI models using Docker containers on cloud platforms, similar to services offered by Together AI.

Introduction

In the wake of Together AI's massive Series C funding, the demand for open-source cloud computing solutions is surging. This tutorial will teach you how to deploy and manage open-source AI models using Docker containers on a cloud platform. You'll learn to set up a scalable AI inference service that can handle multiple model deployments, which is exactly what companies like Together AI are building to meet this growing demand.

Prerequisites

  • Basic understanding of Docker and containerization
  • Access to a cloud platform (AWS, GCP, or Azure recommended)
  • Python 3.8+ installed on your local machine
  • Basic knowledge of REST APIs and HTTP requests
  • Docker installed on your local machine

Step-by-step Instructions

1. Set Up Your Cloud Environment

First, we'll prepare our cloud environment. We'll use AWS EC2 for this example, but the same principles apply to other platforms.

aws ec2 run-instances \
  --image-id ami-0c02fb55956c7d316 \
  --count 1 \
  --instance-type t3.medium \
  --key-name my-key-pair \
  --security-group-ids sg-01234567890abcdef0 \
  --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=AI-Inference-Server}]'

Why this step? We're creating a scalable compute instance that can handle AI model inference workloads. The t3.medium instance provides a good balance of CPU and memory for running multiple AI models.

2. Install Required Dependencies

Once your instance is running, SSH into it and install the necessary packages:

sudo apt update
sudo apt install -y docker.io python3-pip git
sudo usermod -aG docker $USER

Why this step? Docker is essential for containerizing our AI models, and Python provides the necessary libraries for model deployment and API handling.

3. Create a Model Deployment Script

Now we'll create a Python script that will serve as our AI model API:

import torch
from transformers import pipeline
from flask import Flask, request, jsonify
import os

app = Flask(__name__)
model = None

@app.route('/predict', methods=['POST'])
def predict():
    global model
    if model is None:
        model = pipeline('text-generation', model='gpt2')
    
    data = request.get_json()
    prompt = data.get('prompt', '')
    
    try:
        result = model(prompt, max_length=100, num_return_sequences=1)
        return jsonify({'response': result[0]['generated_text']})
    except Exception as e:
        return jsonify({'error': str(e)}), 500

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

Why this step? This script creates a REST API endpoint that can handle text generation requests using the GPT-2 model, which is a common open-source model used in AI inference services.

4. Create a Dockerfile

Next, we'll containerize our application using Docker:

FROM python:3.9-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install -r requirements.txt

COPY . .

EXPOSE 5000

CMD ["python", "app.py"]

Why this step? Containerization ensures our AI service runs consistently across different environments, which is crucial for scaling services like those offered by Together AI.

5. Build and Push Container to Registry

Build your Docker image and push it to a container registry:

# Build the image
sudo docker build -t ai-inference-service:latest .

# Tag for registry (using Docker Hub as example)
sudo docker tag ai-inference-service:latest yourusername/ai-inference-service:latest

# Push to registry
sudo docker push yourusername/ai-inference-service:latest

Why this step? This allows us to easily deploy our AI service across multiple instances and manage different versions, a practice that scales well for companies like Together AI.

6. Deploy Using Docker Compose

Create a docker-compose.yml file to manage multiple services:

version: '3.8'

services:
  ai-service:
    image: yourusername/ai-inference-service:latest
    container_name: ai-inference-server
    ports:
      - "5000:5000"
    environment:
      - MODEL_NAME=gpt2
    restart: unless-stopped

  nginx:
    image: nginx:alpine
    container_name: ai-api-gateway
    ports:
      - "80:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf
    depends_on:
      - ai-service
    restart: unless-stopped

Why this step? This setup allows us to easily scale our AI service and add API gateway functionality, which is essential for handling high volumes of requests in enterprise applications.

7. Test Your Deployment

Test your deployed service using curl:

curl -X POST http://your-instance-ip/predict \
  -H "Content-Type: application/json" \
  -d '{"prompt": "The future of AI is"}'

Why this step? Testing ensures our service is working correctly and can handle real requests, simulating how users would interact with services like those provided by Together AI.

Summary

In this tutorial, you've learned to deploy an open-source AI model service using Docker containers on a cloud platform. You've created a scalable, containerized AI inference service that can handle multiple model deployments, similar to what companies like Together AI are building to meet the growing demand for open-source cloud computing solutions. This approach provides the foundation for building robust, scalable AI services that can be easily managed and deployed across different environments.

Source: TNW Neural

Related Articles