Crates.io | tritonserver-rs |
lib.rs | tritonserver-rs |
version | 0.1.0 |
source | src |
created_at | 2024-12-04 09:43:25.610928 |
updated_at | 2024-12-04 09:43:25.610928 |
description | Pefrorm easy and efficient ML models inference |
homepage | |
repository | https://github.com/3xMike/tritonserver-rs |
max_upload_size | |
id | 1471751 |
size | 2,713,298 |
This crate is designed to run any Machine Learning model on any architecture with ease and efficiency.
It leverages the Triton Inference Server (specifically the Triton C library) and provides a similar API with comparable advantages. However, Tritonserver-rs allows you to build the inference server locally, offering significant performance benefits. Check the benchmark for more details.
Run inference in three simple steps:
Organize your model files in the following structure:
models/
├── yolov8/
| ├── config.pbtxt
| ├── 1/
| │ └── model.onnx
| ├── 2/
| │ └── model.onnx
| └── `<other versions of yolov8>`/
└── `<other models>`/
Rules:
models/
in this example).config.pbtxt
configuration file.model.onnx
).Add Tritonserver-rs to your Cargo.toml
:
[dependencies]
tritonserver-rs = "0.1"
Then write your application code:
use tritonserver_rs::{Buffer, options::Options, Server};
use std::time::Duration;
// Configure server options.
let mut opts = Options::new("models/")?;
opts.exit_timeout(Duration::from_secs(5))?
.backend_directory("/opt/tritonserver/backends")?;
// Create the server.
let server = Server::new(opts).await?;
// Input data.
let image = image::open("/data/cats.jpg")?;
let image = image.as_flat_samples_u8();
// Create a request (specify the model name and version).
let mut request = server.create_request("yolov8", 2)?;
// Add input data and an allocator.
request
.add_default_allocator()
.add_input("IMAGE", Buffer::from(image))?;
// Run inference.
let fut = request.infer_async()?;
// Obtain results.
let response = fut.await?;
Here is an example of how to deploy using docker-compose.yml
:
my_app:
image: {DEV_IMAGE}
volumes:
- ./Cargo.toml:/project/
- ./src:/project/src
- ../models:/models
- ../cats.jpg:/data/cats.jpg
entrypoint: ["cargo", "run", "--manifest-path=/project/Cargo.toml"]
We recommend using Dockerfile.dev as {DEV_IMAGE}
. For more details on suitable images and deployment instructions, see DEPLOY.md.
For further details, check out the following resources: