Tungstenkit: Developer-friendly container toolkit for machine learning
Project description
Tungstenkit
ML containerization tool with a focus on developer productivity and versatility.
Features | Installation | Usage | Getting Started | Documentation
Features
- Easy: Require only a few lines of Python code.
- Versatile: Support multiple usages:
- Abstracted: User-defined JSON input/output.
- Scalable: Support adaptive batching and clustering (coming soon).
Prerequisites
- Python 3.7+
- Docker
- (Optional) nvidia-docker for running GPU models.
Installation
pip install tungstenkit
Usage
Build a Tungsten model
Building a Tungsten model is easy. All you have to do is write a simple tungsten_model.py
like below:
from typing import List
import torch
from tungstenkit import BaseIO, Image, TungstenModel, model_config
class Input(BaseIO):
prompt: str
class Output(BaseIO):
image: Image
@model_config(gpu=True, python_packages=["torch", "torchvision"], batch_size=4)
class TextToImageModel(TungstenModel[Input, Output]):
def setup(self):
weights = torch.load("./weights.pth")
self.model = load_torch_model(weights)
def predict(self, inputs: List[Input]) -> List[Output]:
input_tensor = preprocess(inputs)
output_tensor = self.model(input_tensor)
outputs = postprocess(output_tensor)
return outputs
Now, you can start a build process with the following command:
$ tungsten build
✅ Successfully built tungsten model: 'text-to-image:latest'
Run as a REST API server
You can start a prediction with a REST API call.
Start a server:
$ docker run -p 3000:3000 --gpus all text-to-image:latest
INFO: Setting up the model
INFO: Getting inputs from the input queue
INFO: Starting the prediction service
INFO: Started server process [1]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:3000 (Press CTRL+C to quit)
Send a prediction request with a JSON payload:
$ curl -X 'POST' 'http://localhost:3000/predict' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '[{"prompt": "a professional photograph of an astronaut riding a horse"}]'
{
"outputs": [{"image": "data:image/png;base64,..."}],
}
Run as a GUI application
If you need a more user-friendly way to make predictions, start a GUI app with the following command:
$ tungsten demo text-to-image:latest -p 8080
INFO: Uvicorn running on http://localhost:8080 (Press CTRL+C to quit)
Run as a CLI application
Run a prediction in a terminal:
$ tungsten predict text-to-image \
-i prompt="a professional photograph of an astronaut riding a horse"
{
"image": "./output.png"
}
Run in a Python script
If you want to use a Tungsten model in your Python application, use the Python API:
>>> from tungstenkit import models
>>> model = models.get("text-to-image:latest")
>>> model.predict(
{"prompt": "a professional photograph of an astronaut riding a horse"}
)
{"image": PosixPath("./output.png")}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tungstenkit-0.0.1.tar.gz
.
File metadata
- Download URL: tungstenkit-0.0.1.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-42-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c37fd1417b38d00c1888c96000a58522346e52ab840fd65e75af35999b2d988 |
|
MD5 | e4b942dbe156c7e44f305ae3d1b36af5 |
|
BLAKE2b-256 | 41cc8505d91cc772bd93b27344075fd5c8515b928bfc4b8a5d9eb37da10e5f11 |
File details
Details for the file tungstenkit-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: tungstenkit-0.0.1-py3-none-any.whl
- Upload date:
- Size: 1.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.19.0-42-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a41435cc9641afeb219a64f70a48461156983bba419d118fba2d0e22f6cc7649 |
|
MD5 | 640bad005066fe0abf8fd86dcd564e8f |
|
BLAKE2b-256 | 40ec7496cd6c883cfc057cfccf64082294ae1f2628c74719af5fc53e0643e1bc |