• Stars
    star
    288
  • Rank 143,818 (Top 3 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 4 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

☁️ Terraform plugin for machine learning workloads: spot instance recovery & auto-termination | AWS, GCP, Azure, Kubernetes

TPI

Terraform Provider Iterative (TPI)

docs tests Apache-2.0

TPI is a Terraform plugin built with machine learning in mind. This CLI tool offers full lifecycle management of computing resources (including GPUs and respawning spot instances) from several cloud vendors (AWS, Azure, GCP, K8s)... without needing to be a cloud expert.

  • Lower cost with spot recovery: transparent data checkpoint/restore & auto-respawning of low-cost spot/preemptible instances
  • No cloud vendor lock-in: switch between clouds with just one line thanks to unified abstraction
  • No waste: auto-cleanup unused resources (terminate compute instances upon task completion/failure & remove storage upon download of results), pay only for what you use
  • Developer-first experience: one-command data sync & code execution with no external server, making the cloud feel like a laptop

Supported cloud vendors include:

Amazon Web Services (AWS) Microsoft Azure Google Cloud Platform (GCP) Kubernetes (K8s)

Why TPI?

There are a several reasons to use TPI instead of other related solutions (custom scripts and/or cloud orchestrators):

  1. Reduced management overhead and infrastructure cost: TPI is a CLI tool, not a running service. It requires no additional orchestrating machine (control plane/head nodes) to schedule/recover/terminate instances. Instead, TPI runs (spot) instances via cloud-native scaling groups1, taking care of recovery and termination automatically on the cloud provider's side. This design reduces management overhead & infrastructure costs. You can close your laptop while cloud tasks are running -- auto-recovery happens even if you are offline.
  2. Unified tool for data science and software development teams: TPI provides consistent tooling for both data scientists and DevOps engineers, improving cross-team collaboration. This simplifies compute management to a single config file, and reduces time to deliver ML models into production.
  3. Reproducible, codified environments: Store hardware requirements in a single configuration file alongside the rest of your ML pipeline code.

TPI is used to power CML, bringing cloud providers to existing GitHub, GitLab & Bitbucket CI/CD workflows (repository).

Usage

Requirements

  • Install Terraform 1.0+, e.g.:
    • Brew (Homebrew/Mac OS): brew tap hashicorp/tap && brew install hashicorp/tap/terraform
    • Choco (Chocolatey/Windows): choco install terraform
    • Conda (Anaconda): conda install -c conda-forge terraform
    • Debian (Ubuntu/Linux):
      sudo apt-get update && sudo apt-get install -y gnupg software-properties-common curl
      curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
      sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
      sudo apt-get update && sudo apt-get install terraform
      
  • Create an account with any supported cloud vendor and expose its authentication credentials via environment variables

Define a Task

In a project root directory, create a file named main.tf with the following contents:

terraform {
  required_providers { iterative = { source = "iterative/iterative" } }
}
provider "iterative" {}

resource "iterative_task" "example" {
  cloud      = "aws" # or any of: gcp, az, k8s
  machine    = "m"   # medium. Or any of: l, xl, m+k80, xl+v100, ...
  spot       = 0     # auto-price. Default -1 to disable, or >0 for hourly USD limit
  disk_size  = -1    # GB. Default -1 for automatic

  storage {
    workdir = "."       # default blank (don't upload)
    output  = "results" # default blank (don't download). Relative to workdir
  }
  script = <<-END
    #!/bin/bash

    # create output directory if needed
    mkdir -p results
    # read last result (in case of spot/preemptible instance recovery)
    if test -f results/epoch.txt; then EPOCH="$(cat results/epoch.txt)"; fi
    EPOCH=$${EPOCH:-1}  # start from 1 if last result not found

    echo "(re)starting training loop from $EPOCH up to 1337 epochs"
    for epoch in $(seq $EPOCH 1337); do
      sleep 1
      echo "$epoch" | tee results/epoch.txt
    done
  END
}

See the reference for the full list of options for main.tf -- including more information on machine types with and without GPUs.

console

Run this once (in the directory containing main.tf) to download the required_providers:

terraform init
export TF_LOG_PROVIDER=INFO

Run Task

terraform apply

This launches a machine in the cloud, uploads workdir, and runs the script. Upon completion (or error), the machine is terminated.

With spot/preemptible instances (spot >= 0), auto-recovery logic and persistent (disk_size) storage will be used to relaunch interrupted tasks.

Query Status

Results and logs are periodically synced to persistent cloud storage. To query this status and view logs:

terraform refresh
terraform show

End Task

terraform destroy

This terminates the machine (if still running), downloads output, and removes the persistent disk_size storage.

Example Projects

How it Works

This diagram may help to see what TPI does under-the-hood:

flowchart LR
subgraph tpi [what TPI manages]
direction LR
    subgraph you [what you manage]
        direction LR
        A([Personal Computer])
    end
    B[("Cloud Storage (low cost)")]
    C{{"Cloud instance scaler (zero cost)"}}
    D[["Cloud (spot) Instance"]]
    A ---> |2. create cloud storage| B
    A --> |1. create cloud instance scaler| C
    A ==> |3. upload script & workdir| B
    A -.-> |"4. offline (lunch break)"| A
    C -.-> |"5. (re)provision instance"| D
    D ==> |7. run script| D
    B <-.-> |6. persistent workdir cache| D
    D ==> |8. script end,\nshutdown instance| B
    D -.-> |outage| C
    B ==> |9. download output| A
end
style you fill:#FFFFFF00,stroke:#13ADC7
style tpi fill:#FFFFFF00,stroke:#FFFFFF00,stroke-width:0px
style A fill:#13ADC7,stroke:#333333,color:#000000
style B fill:#945DD5,stroke:#333333,color:#000000
style D fill:#F46737,stroke:#333333,color:#000000
style C fill:#7B61FF,stroke:#333333,color:#000000

Future Plans

TPI is a CLI tool bringing the power of bare-metal cloud to a bare-metal local laptop. We're working on more featureful and visual interfaces. We'd also like to have more native support for distributed (multi-instance) training, more data sync optimisations & options, and tighter ecosystem integration with tools such as DVC. Plus of course more examples for Data Scientists and Machine Learning Engineers - from Jupyter, VSCode, and Codespaces to improving the live logging/monitoring/reporting experience.

Help

The getting started guide has some more information. In case of errors, extra debugging information is available using TF_LOG_PROVIDER=DEBUG instead of INFO.

Feature requests and bugs can be reported via GitHub issues, while general questions and feedback are very welcome on our active Discord server.

Contributing

Instead of using the latest stable release, a local copy of the repository must be used.

  1. Install Go 1.17+
  2. Clone the repository & build the provider
    git clone https://github.com/iterative/terraform-provider-iterative
    cd terraform-provider-iterative
    make install
    
  3. Use source = "github.com/iterative/iterative" in your main.tf to use the local repository (source = "iterative/iterative" will download the latest release instead), and run terraform init --upgrade

Copyright

This project and all contributions to it are distributed under Apache-2.0

Footnotes

  1. AWS Auto Scaling Groups, Azure VM Scale Sets, GCP managed instance groups, and Kubernetes Jobs.

More Repositories

1

dvc

🦉 ML Experiments and Data Management with Git
Python
13,294
star
2

cml

♾️ CML - Continuous Machine Learning | CI/CD for ML
JavaScript
3,996
star
3

datachain

AI-dataframe to enrich, transform and analyze data from cloud storages for ML training and LLM apps
Python
757
star
4

mlem

🐶 A tool to package, serve, and deploy any ML model on any platform. Archived to be resurrected one day🤞
Python
717
star
5

PyDrive2

Google Drive API Python wrapper library. Maintained fork of PyDrive.
Python
565
star
6

shtab

↔️ Automagic shell tab completion for Python CLI applications
Python
362
star
7

dvc.org

📖 DVC website and documentation
TypeScript
320
star
8

vscode-dvc

Machine learning experiment tracking and data versioning with DVC extension for VS Code
TypeScript
187
star
9

example-get-started

Get started DVC project
Python
167
star
10

dvclive

📈 Log and track ML metrics, parameters, models with Git and/or DVC
Python
161
star
11

gto

🏷️ Git Tag Ops. Turn your Git repository into Artifact Registry or Model Registry.
Python
138
star
12

awesome-iterative-projects

A list of projects relying on Iterative.AI tools to achieve awesomeness
64
star
13

dataset-registry

Dataset registry DVC project
60
star
14

magnetic-tiles-defect

Demo Computer Vision Project
Jupyter Notebook
59
star
15

example-get-started-experiments

Get started DVC project
Python
45
star
16

course-ds-base

Jupyter Notebook
44
star
17

demo-bank-customer-churn

Demo DVC project training a classification model on tabular data
Jupyter Notebook
38
star
18

aita_dataset

AITA dataset based on r/AmItheAsshole/
Python
33
star
19

setup-dvc

DVC GitHub action
JavaScript
30
star
20

ldb-resources

Python
27
star
21

mlem.ai

✨ Landing page for MLEM
TypeScript
27
star
22

example_cml

Python
27
star
23

workshop-uncool-mlops

Accompanies the uncool MLOps workshop
Python
26
star
24

setup-cml

GitHub Action for CML setup
TypeScript
24
star
25

scmrepo

SCM wrapper and fsspec filesystem for Git for use in DVC.
Python
21
star
26

cml_base_case

Python
21
star
27

example-repos-dev

Source code and generator scripts for example DVC projects
Python
21
star
28

cml_cloud_case

Python
20
star
29

dvc-bench

Benchmarks for DVC
Shell
20
star
30

cml_dvc_case

Python
18
star
31

dvc-data

DVC's data management subsystem
Python
18
star
32

intellij-dvc

DVC integration plugin for Intellij IDEs including PyCharm, IntelliJ IDEA and CLion
Java
17
star
33

studio-support

❓ DVC Studio Issues, Question, and Discussions
16
star
34

pytest-servers

Create temporary directories on the various filesystems for testing
Python
15
star
35

studio-selfhosted

This repository contains auxiliary installation code for self-hosting Studio
Shell
14
star
36

py-template

Hypermodern Python Cookiecutter
Python
14
star
37

VSCode-DVC-Workshop

Workshop about DVC VSCode Extension
Jupyter Notebook
14
star
38

example-dvc-experiments

DVC Get Started Project with a focus on `dvc experiment` features.
HTML
13
star
39

cml.dev

🔗 CML website and documentation
TypeScript
12
star
40

dvcyaml-schema

Schema for dvc.yaml
Python
10
star
41

dvc-objects

dvc objects - contains filesystem and object-db level abstractions to use in dvc and dvc-data
Python
10
star
42

example-versioning

Data sets and ML models versioning example from DVC get started
Python
9
star
43

dvc-streamlit-components

Streamlit components for DVC
Python
9
star
44

morefs

A collection of self-contained fsspec-based filesystems
Python
9
star
45

priority-list

⛏️ Make a dent in GitHub issue & PR backlogs across repositories
Python
8
star
46

cml_tensorboard_case

Python
8
star
47

dvc-s3

AWS S3 plugin for dvc
Python
8
star
48

llm-demo

Demo of using DVC with LangChain
Python
8
star
49

example-mlem-get-started

Get Started MLEM project
Python
7
star
50

dvc-task

Celery task queue used in DVC
Python
7
star
51

tpi

Python wrapper for terraform-provider-iterative
Python
7
star
52

example-gto

Get Started GTO Project
7
star
53

example-pokemon-classifier

Example project with a CNN to train a Pokémon type classifier.
Python
7
star
54

dvc-render

Library for rendering DVC plots
Python
6
star
55

dvc-studio-client

Client to interact with DVC Studio
Python
6
star
56

pytest-test-utils

Python
6
star
57

workshop-uncool-mlops-solution

Python
6
star
58

gatsby-theme-iterative

A Gatsby theme for shared logic between all the websites from iterative.ai
JavaScript
6
star
59

stale-model-example

This is the repo for the Preventing Stale Models in Production blog post.
Jupyter Notebook
6
star
60

gto-action

⚙️ GTO Github Action
Shell
6
star
61

evidently-dvc

Tutorial: Automate Data Validation and Model Monitoring Pipelines with DVC and Evidently
HTML
6
star
62

features

A collection of development container 'features' for machine learning and data science
Shell
6
star
63

course-checkpoints-project

This is the project we use for the DVC educational course to demonstrate how checkpoints work.
HTML
6
star
64

sqltrie

SQL-based prefix tree implementation inspired by pygtrie and python-diskcache
Python
5
star
65

dvc-checkpoints-mnist

Example of checkpoints in a DVC project training a simple convolutional neural net to classify MNIST data
Python
5
star
66

dvc-s3-repo

Maintain deb and rpm repositories on s3
Python
5
star
67

enhancement-proposals

5
star
68

dvc-gs

Google Storage plugin for dvc
Python
4
star
69

link-check

A Node-based tool to verify if links are alive. Built to be used anywhere!
TypeScript
4
star
70

dvc-snap

dvc snap package
Shell
4
star
71

sagemaker-pipeline

An example project, showcasing a DVC pipeline using SageMaker SDK for data preparation and model training
Python
4
star
72

cml-runner-base-case

Python
4
star
73

cml-playground

Shell
4
star
74

pretrained-model-demo

Python
4
star
75

homebrew-dvc

Automatic updates for dvc homebrew package
Shell
4
star
76

vscode-dvc-demo

Python
3
star
77

example_model_export_cml

Example on how to use CML to provision an AWS EC2 runner, train a model, and export the resulting model.
Python
3
star
78

dvc-azure

Azure plugin for dvc
Python
3
star
79

cnn_tutorial

CNN tutorial for DVC
Python
3
star
80

telemetry-python

Common library to send usage telemetry
Python
3
star
81

dvc-learn-project

This is the project used in the DVC Learn Meetups and videos.
HTML
3
star
82

checkpoints-tutorial

This is the code used in the checkpoints tutorial.
Python
3
star
83

ldb

Python
3
star
84

chocolatey-dvc

Chocolatey package for dvc
PowerShell
3
star
85

blog-tpi-jupyter

Terraform Provider Iterative + Jupyter + TensorBoard + AWS/Azure/GCP/K8s
Jupyter Notebook
3
star
86

dvc-gdrive

Google Drive plugin for DVC
Python
2
star
87

link-check.action

A GitHub Action driver for link-check, deployed via submodules.
JavaScript
2
star
88

katacoda-scenarios

Interactive Katacoda Scenarios
Shell
2
star
89

dvc-exe

Private repository for building and signing dvc for windows
Inno Setup
2
star
90

jameson-metrics

Metrics examples
Python
2
star
91

example-mlem

Example of using MLEM with DVC Pipeline
Python
2
star
92

example-get-started-s3

Example get started (metrics and plots in S3)
Python
2
star
93

dvc_action_example

Python
2
star
94

dvc-oss

Alibaba OSS plugin for dvc
Python
2
star
95

dvc-test

Integration tests for dvc
Python
2
star
96

reflink-copy

Python wrapper for `reflink_copy` Rust library
Python
2
star
97

vscode-dvc-pack

2
star
98

dvclive-exp-tracking

Example repo to show how to start tracking experiments in DVC by adding DVCLive to your Python code.
Jupyter Notebook
2
star
99

cookiecutter-dvc-plugin

A Cookiecutter template for dvc plugins
Python
2
star
100

testing-ldb

Aug 10th Hackathon
Python
2
star