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:
-
Set it Temporarily in Your Shell:
Run this in your terminal before executing your script:export VASTAI_API_KEY="your_api_key_here"
-
Add it to Your Shell Configuration:
Add the following line to your~/.bashrcor~/.zshrcfile for a permanent setup:export VASTAI_API_KEY="your_api_key_here"
Then, reload your shell:
source ~/.bashrc
-
Use a
.envFile:
Create a.envfile in your project directory with this content:VASTAI_API_KEY=your_api_key_here
Then, use a library like
python-dotenvto load the variable:from dotenv import load_dotenv load_dotenv()
-
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:
- Vastify searches for an available vast.ai instance that matches your specifications.
- It packages your code, dependencies, and specified files.
- 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_filesparameter.
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
regionsparameter to include more geographical locations.
-
File Transfer Issues:
- Ensure the paths in
include_filesare correct and accessible. - Verify that remote files are not corrupted by inspecting the remote logs.
- Ensure the paths in
-
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.
Metadata
Release files for vastify 0.4.20
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vastify-0.4.20.tar.gz | 65.2 kB | Without provenance | Details for vastify-0.4.20.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vastify-0.4.20-py3-none-any.whl | Python 3 | none | any | Details for vastify-0.4.20-py3-none-any.whl |
Total release size: 134.6 kB
Release files / vastify-0.4.20.tar.gz
| Download URL | vastify-0.4.20.tar.gz |
|---|---|
| Size | 65.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
634c46f8f100ec2f6258d7ec546f3d58ec4c1e6cdef59682c8fb80b1f197b219
|
|
BLAKE2b-256 checksum How to use checksums |
cfa9c6cb78467f7bc56c52cde8741712b1734ff5606bc50094bcaab468bc8adb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.2 Darwin/24.3.0
|
Release files / vastify-0.4.20-py3-none-any.whl
| Download URL | vastify-0.4.20-py3-none-any.whl |
|---|---|
| Size | 69.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2255bc3cb649899ca4e30efeb9ea0ff5aca82bc2297e74d7f968251eaf22281a
|
|
BLAKE2b-256 checksum How to use checksums |
8eff7508a0ffa5f1395637b9f2e8316e961dafbbac5f50efdf53254a97162ddb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.2 Darwin/24.3.0
|
Security for vastify 0.4.20
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.