Skip to main content

Vastify automagically runs your function on a vast.ai GPU cloud machine by using a simple decorator.

Project description

Vastify - Effortlessly Run GPU-Intensive Workloads on vast.ai 🚀

Vastify is a Python library designed to simplify running GPU-heavy workloads on vast.ai instances. With features like decorator-based execution, dynamic code deployment, and smart file management, Vastify allows you to focus on your code while it handles the infrastructure.

🌟 Key Features

  • Decorator-Based Execution: Use a simple decorator to execute your Python functions remotely on vast.ai.
  • Smart Instance Management: Automatically find and launch GPU instances that match your specifications.
  • Dynamic Code Packaging: Vastify packages your function, dependencies, and additional files at runtime—no need to bake them into Docker images.
  • Efficient File Management: Sync large files to the instance efficiently, avoiding redundant transfers.
  • Per-File Optimization: Transfers only missing or outdated files to the instance.
  • Cost Efficiency: Instances automatically shut down after a configurable idle time to avoid unnecessary costs.

⚠️ Important Note

This is an internally used project. Maintenance, support and updates are not guaranteed. Use at your own risk.

🛠️ Installation

Install Vastify via PyPI:

pip install vastify

Set Up Your Vast.ai API Key

Vastify uses your Vast.ai API key to manage GPU instances. You must set the environment variable VASTAI_API_KEY before running your code. Here are multiple ways to do this:

  1. Set it Temporarily in Your Shell:
    Run this in your terminal before executing your script:

    export VASTAI_API_KEY="your_api_key_here"
    
  2. Add it to Your Shell Configuration:
    Add the following line to your ~/.bashrc or ~/.zshrc file for a permanent setup:

    export VASTAI_API_KEY="your_api_key_here"
    

    Then, reload your shell:

    source ~/.bashrc
    
  3. Use a .env File:
    Create a .env file in your project directory with this content:

    VASTAI_API_KEY=your_api_key_here
    

    Then, use a library like python-dotenv to load the variable:

    from dotenv import load_dotenv
    load_dotenv()
    
  4. Set it Programmatically:
    Set the variable directly in your Python script:

    import os
    os.environ["VASTAI_API_KEY"] = "your_api_key_here"
    

🚀 Quick Start

1. Set Up Your Environment

Before using Vastify:

  • Ensure you have a vast.ai account and API key.
  • Optionally, store large files in a supported cloud storage provider.

2. Write Your Vastify Function

Annotate your Python function with the @run_on_vastai decorator to run it on vast.ai:

from vastify import run_on_vastai

@run_on_vastai(
    gpu_name="RTX_2080_Ti", 
    price=0.5, 
    include_files=["./model.pt", "./config.json"]
)
def train_model():
    import torch
    print("Training a model on a vast.ai instance!")
    # Your GPU-intensive logic here
    # You can even return a value from the function (for example the trained model)
    return trained_model

if __name__ == "__main__":
    # The return value will be transferred back from the remote execution to your local environment automagically
    result = train_model()

3. Run Your Code

When you call the decorated function:

  1. Vastify searches for an available vast.ai instance that matches your specifications.
  2. It packages your code, dependencies, and specified files.
  3. The function runs on the GPU instance, and the result is returned to your local environment.

⚙️ Advanced Usage

Specify GPU Requirements

Customize the instance configuration directly in the decorator:

@run_on_vastai(gpu_name="A100", price=1.0, disk=200, regions=["Europe", "North_America"])
def perform_inference():
    # Perform GPU-intensive inference here
    pass

Include Large Files and Directories

Specify files or directories to be uploaded to the vast.ai instance. Files are transferred individually, ensuring efficiency by skipping files that already exist on the remote instance.

@run_on_vastai(
    gpu_name="RTX_3090", 
    include_files=["/path/to/dataset", "/path/to/model_weights.pt"]
)
def analyze_data():
    # Function logic here
    pass

🏗️ How It Works

1. Dynamic Code Packaging

Vastify packages:

  • Your Python code.
  • Dependencies (collected automatically).
  • Additional files or directories specified in the include_files parameter.

2. Smart File Transfer

  • Uses per-file checks to avoid transferring files that already exist on the instance.
  • Files are compressed before transfer and decompressed on the instance.

3. Vast.ai Instance Management

  • Vastify uses your provided API key to find or start a GPU instance that matches your specifications.
  • Instances detect inactivity and shut down automatically after a configurable idle time.

🧰 Requirements

  • Python 3.8+
  • Vast.ai account with API key
  • Paramiko and other Python dependencies (installed automatically with Vastify)

📖 Documentation


🤝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.


🚨 Troubleshooting

Common Issues

  • Instance Not Found:

    • Check if your GPU and memory requirements are too strict.
    • Increase your price cap to include more instances.
    • Expand the regions parameter to include more geographical locations.
  • File Transfer Issues:

    • Ensure the paths in include_files are correct and accessible.
    • Verify that remote files are not corrupted by inspecting the remote logs.
  • API Key Issues:

    • Ensure your vast.ai API key is valid and properly set in the environment.

For further assistance, open an issue on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vastify-0.4.7.tar.gz (66.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vastify-0.4.7-py3-none-any.whl (69.1 kB view details)

Uploaded Python 3

File details

Details for the file vastify-0.4.7.tar.gz.

File metadata

  • Download URL: vastify-0.4.7.tar.gz
  • Upload date:
  • Size: 66.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Darwin/22.6.0

File hashes

Hashes for vastify-0.4.7.tar.gz
Algorithm Hash digest
SHA256 911b53c97296d4dc66378f974e634d12270523a3de07e57cf4a9b0318c7006cd
MD5 41cbfdfc1c6f5152a6e68304812e43ba
BLAKE2b-256 4f77b980def31dc33a54f6dc066648ee09aa5bceb06e12c6c8ecb1cd9294e638

See more details on using hashes here.

File details

Details for the file vastify-0.4.7-py3-none-any.whl.

File metadata

  • Download URL: vastify-0.4.7-py3-none-any.whl
  • Upload date:
  • Size: 69.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.19 Darwin/22.6.0

File hashes

Hashes for vastify-0.4.7-py3-none-any.whl
Algorithm Hash digest
SHA256 89a5d2ce66c7a874ec7f54857cc04d676434d08a692a2e989568a611e2342fcf
MD5 72ec8f5cfde7904c265609c48d32f606
BLAKE2b-256 0932022a83af78f9aed3e8995a42c428fc903b916f2f22bbf3b6a4f8d979beca

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page