Skip to main content

Deploying Your First Model on Swift Compute

Aug 6, 2025
12 min read
By Alex Rodriguez

Getting started with Swift Compute is designed to be as simple as possible. In this guide, we'll walk you through deploying your first model from start to finish, including common pitfalls and best practices.

Prerequisites

Before we begin, make sure you have:

  • A Swift Compute account (sign up for free)
  • The Swift CLI installed on your machine
  • A trained model ready for deployment
  • Basic familiarity with Docker (optional but helpful)

Step 1: Install the Swift CLI

The Swift CLI is your primary interface for managing deployments. Install it with:

curl -sSL https://cli.swiftcompute.com/install.sh | bash

Verify the installation:

swift --version

Step 2: Authenticate

Log in to your Swift Compute account:

swift auth login

This will open your browser for authentication. Once complete, you're ready to deploy.

Step 3: Prepare Your Model

Swift Compute supports multiple model formats:

  • PyTorch: .pt, .pth files
  • TensorFlow: SavedModel format
  • ONNX: .onnx files
  • Hugging Face: Direct model hub integration

Example: PyTorch Model

Create a simple inference script:


# inference.py
import torch
import json

def predict(input_data):
    model = torch.load('model.pt')
    model.eval()
    
    with torch.no_grad():
        result = model(input_data)
    
    return result.tolist()

def handler(event, context):
    input_data = torch.tensor(event['data'])
    prediction = predict(input_data)
    
    return {
        'statusCode': 200,
        'body': json.dumps({'prediction': prediction})
    }
      

Step 4: Create a Deployment Configuration

Create a swift.yaml file in your project directory:


name: my-first-model
runtime: python3.9
gpu: T4
memory: 8GB
handler: inference.handler

files:
  - model.pt
  - inference.py
  - requirements.txt

environment:
  TORCH_SERVE_WORKERS: 1
      

Step 5: Deploy

Deploy your model with a single command:

swift deploy

You'll see output similar to:


✓ Uploading files...
✓ Building container...
✓ Deploying to GPU cluster...
✓ Running health checks...

Deployment successful!
Endpoint: https://api.swiftcompute.com/v1/models/my-first-model
      

Step 6: Test Your Deployment

Test your model with a simple curl request:


curl -X POST https://api.swiftcompute.com/v1/models/my-first-model \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"data": [[1, 2, 3, 4]]}'
      

Monitoring and Scaling

Once deployed, you can monitor your model's performance:

swift logs my-first-model

Scale based on demand:

swift scale my-first-model --min-instances 2 --max-instances 10

Best Practices

  • Optimize model size: Use model quantization and pruning techniques
  • Implement health checks: Add a /health endpoint for monitoring
  • Use environment variables: Keep configuration separate from code
  • Monitor performance: Set up alerts for latency and error rates

That's it! You've successfully deployed your first model on Swift Compute. Check out our uptime guide to learn about production best practices. uptime guide to learn about production best practices.

Ready to Get Started?

Join thousands of developers already using Swift Compute to build and deploy AI models faster and more cost-effectively.