Skip to content

Latest commit

 

History

History
124 lines (87 loc) · 3.67 KB

File metadata and controls

124 lines (87 loc) · 3.67 KB

Heroku Deployment Guide for TransPolymer

This guide will help you deploy your TransPolymer Streamlit app to Heroku with an optimized setup that stays under the 500MB slug size limit.

📋 What We've Optimized

  1. CPU-only PyTorch: Replaced CUDA-enabled PyTorch (~3GB) with CPU-only version (~100MB)
  2. Minimal Dependencies: Removed unnecessary packages (seaborn, scipy) that aren't used in the web app
  3. File Exclusion: Created .slugignore to exclude training scripts and data files
  4. Heroku Configuration: Added proper Procfile and runtime.txt

🚀 Deployment Steps

1. Prepare Your Repository

Make sure you have these new files in your repository:

  • requirements-heroku.txt (optimized dependencies)
  • Procfile (tells Heroku how to run your app)
  • runtime.txt (specifies Python version)
  • .slugignore (excludes unnecessary files)

2. Deploy to Heroku

Option A: Using Heroku CLI

# Install Heroku CLI if you haven't already
# https://devcenter.heroku.com/articles/heroku-cli

# Login to Heroku
heroku login

# Create a new Heroku app
heroku create your-transpolymer-app

# Rename requirements file for deployment
cp requirements-heroku.txt requirements.txt

# Deploy
git add .
git commit -m "Optimize for Heroku deployment"
git push heroku main

# Open your app
heroku open

Option B: Using Heroku Dashboard

  1. Go to Heroku Dashboard
  2. Click "New" → "Create new app"
  3. Connect your GitHub repository
  4. Important: Before deploying, rename requirements-heroku.txt to requirements.txt
  5. Deploy from the main branch

3. Post-Deployment

Your app should now be running with a slug size under 500MB! The optimizations include:

  • Estimated slug size: ~200-300MB (down from 3.1GB)
  • CPU-only inference: Works perfectly for web predictions
  • Faster build times: Fewer dependencies to install

🔧 Troubleshooting

If you still get slug size errors:

  1. Check your requirements.txt: Make sure you're using the CPU-only PyTorch:

    torch>=1.12.0,<3.0.0 --index-url https://download.pytorch.org/whl/cpu
    
  2. Verify .slugignore is working: Make sure unnecessary files are excluded

  3. Further optimize: If still too large, consider removing matplotlib:

    # Remove from requirements-heroku.txt if not essential
    # matplotlib>=3.5.0,<4.0.0

If the app doesn't start:

  1. Check Heroku logs:

    heroku logs --tail -a your-app-name
  2. Verify Procfile: Make sure it's exactly:

    web: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0
    

📊 Performance Notes

  • Model Loading: The app uses random weights by default since pretrained model files are excluded
  • Predictions: Still functional for demonstration purposes
  • Memory Usage: CPU inference is memory-efficient for Heroku's standard dynos

🔄 Switching Between Environments

For Development (Full PyTorch + CUDA):

pip install -r requirements.txt

For Heroku (CPU-only):

pip install -r requirements-heroku.txt

📝 Additional Tips

  1. Dyno Types: Standard dynos should be sufficient for this app
  2. Scaling: For high traffic, consider upgrading to performance dynos
  3. Caching: The app uses @st.cache_resource for efficient model loading
  4. Monitoring: Use Heroku metrics to monitor performance

⚠️ Important Notes

  • The deployed app will use random model weights (for demo purposes)
  • If you need actual predictions, you'll need to host model weights separately (e.g., Hugging Face Hub)
  • Consider using environment variables for any sensitive configurations

Happy deploying! 🚀