Crates.io | jams |
lib.rs | jams |
version | 0.1.27 |
source | src |
created_at | 2024-06-06 19:04:50.303824 |
updated_at | 2024-12-02 03:54:38.535188 |
description | jams is an easy-to-use CLI application for interaction with J.A.M.S - Just Another Model Server |
homepage | https://github.com/gagansingh894/jams-rs |
repository | https://github.com/gagansingh894/jams-rs/tree/main/jams |
max_upload_size | |
id | 1263998 |
size | 318,555 |
This crate provides a CLI for interacting J.A.M.S - Just Another Model Server.
⚠️ DISCLAIMER: jams is reaching stable version but may not run properly on ARM chips. Future releases will fix this. For now use docker image or Linux x86_64 architecture. Only Pytorch 2.2.0 is supported for now due to dependencies on FFI bindings. Although you may be able to run models trained on version <= 2.2.0
J.A.M.S is hosted on DockerHub.
docker pull gagansingh894/jams
Ensure that you have docker compose
installed on your system. Please follow instructions here
Note: If you are on Apple Silicon, please disable Use Rosetta for x86_64/amd64 emulation on Apple Silicon
option under settings
To quickly get started running with J.A.M.S
, please run the following commands
The script creates a jams-playground directory with a subdirectory models, and then downloads a Docker Compose configuration file and several machine learning model files from a GitHub repository into the respective directories. It runs with superuser privileges using sudo to ensure necessary permissions for directory creation and file downloads.
sudo bash -c 'mkdir -p jams-playground/models && \
wget -q -O jams-playground/docker-compose-http-grpc-minio.yml https://raw.githubusercontent.com/gagansingh894/jams-rs/main/build/docker-compose-http-grpc-minio.yml && \
wget -q -O jams-playground/models/catboost-titanic_model.tar.gz https://github.com/gagansingh894/jams-rs/raw/main/jams-serve/tests/model_store/catboost-titanic_model.tar.gz && \
wget -q -O jams-playground/models/lightgbm-my_awesome_reg_model.tar.gz https://github.com/gagansingh894/jams-rs/raw/main/jams-serve/tests/model_store/lightgbm-my_awesome_reg_model.tar.gz && \
wget -q -O jams-playground/models/pytorch-my_awesome_californiahousing_model.tar.gz https://github.com/gagansingh894/jams-rs/raw/main/jams-serve/tests/model_store/pytorch-my_awesome_californiahousing_model.tar.gz && \
wget -q -O jams-playground/models/tensorflow-my_awesome_penguin_model.tar.gz https://github.com/gagansingh894/jams-rs/raw/main/jams-serve/tests/model_store/tensorflow-my_awesome_penguin_model.tar.gz'
docker compose -f jams-playground/docker-compose-http-grpc-minio.yml up
If everything works fine, this should start a minio
server with some preloaded models as model store, J.A.M.S http
and J.A.M.S grpc
server for
making predictions. You can add new models by uploading them directly to minio
via UI (http://0.0.0.0:9001). The models
should be of supported types and follow the naming convention <model_framework>-model_name.tar.gz
.
Use the curl commands to make predictions
curl --location '0.0.0.0:3000/api/predict' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
"model_name": "my_awesome_penguin_model",
"input": "{\"island\":[2.0,2.0,2.0,2.0,2.0],\"bill_length_mm\":[39.1,39.5,40.3,36.7,39.3],\"bill_depth_mm\":[18.7,17.4,18.0,19.3,20.6],\"flipper_length_mm\":[181.0,186.0,195.0,193.0,190.0],\"body_mass_g\":[3750.0,3800.0,3250.0,3450.0,3650.0],\"sex\":[1.0,0.0,0.0,0.0,1.0]}"
}'
curl --location '0.0.0.0:3000/api/predict' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
"model_name": "titanic_model",
"input": "{\"adult_male\":[\"True\",\"False\"],\"age\":[22.0,23.79929292929293],\"alone\":[\"True\",\"False\"],\"class\":[\"First\",\"Third\"],\"deck\":[\"Unknown\",\"Unknown\"],\"embark_town\":[\"Southampton\",\"Cherbourg\"],\"embarked\":[\"S\",\"C\"],\"fare\":[151.55,14.4542],\"parch\":[\"0\",\"0\"],\"pclass\":[\"1\",\"3\"],\"sex\":[\"male\",\"female\"],\"sibsp\":[\"0\",\"1\"],\"who\":[\"man\",\"woman\"]}"
}'
Alternatively, you can use Postman or equivalent.
The easiest way to start J.A.M.S is by providing a config TOML file
[config]
protocol = "http" # Specifies the protocol to be used by the server.
# Allowed values: "http", "grpc"
port = 3000 # Defines the port number on which the server will listen.
# This should be an integer between 1 and 65535.
# Example: 3000 for HTTP, 443 for HTTPS
model_store = "local" # Indicates the type of model store being used.
# Allowed values:
# - "local": Use local storage.
# - "aws": Use AWS S3 for model storage.
# - "azure": Use Azure Blob Storage.
model_dir = "<absolute path>" # Specifies the directory path where models are stored locally.
# If `model_store` is set to "local", this directory is used
# to store or load models.
azure_storage_container_name = "jamsmodelstore" # Specifies the name of the Azure Blob Storage container
# used for storing models when `model_store` is set to "azure".
# This should be a valid container name in Azure.
s3_bucket_name = "jamsmodelstore" # Indicates the name of the S3 bucket used for storing models
# when `model_store` is set to "aws".
# This should be a valid bucket name in AWS S3.
poll_interval = 600 # Defines the time interval (in seconds) for polling the model store
# to check for updates.
# Example: 600 means the application will poll every 10 minutes.
num_workers = 4 # Sets the number of Rayon threadpool worker threads
# Example: 4 threads
Then Run
docker run --rm -v /your/path/to/model_store:/model_store -p 3000:3000 gagansingh894/jams start -f config.toml
There are other ways to start J.A.M.S. Please follow the following commands to start the server inside docker.
If you want to disable polling, then do not pass --poll-interval
To run HTTP server, use
docker run --rm -v /your/path/to/model_store:/model_store -p 3000:3000 gagansingh894/jams start http --model-dir local --poll-interval 3600
To run gRPC server, use
docker run --rm -v /your/path/to/model_store:/model_store -p 4000:4000 gagansingh894/jams start grpc --model-store=local --poll-interval 3600
AWS_REGION
, AWS_ACCESS_KEY_ID
, AWS_SECRET_ACCESS_KEY
. Alternatively if you have multiple AWS profiles then just set the AWS_PROFILE-<profile_name>
You also need to set the bucket name. This can either be set via S3_BUCKET_NAME
env variable or passed via --s3-bucket-name
flagminio
, you will need to set these environment variables in addition to the above = MINIO_ACCESS_KEY_ID
, MINIO_SECRET_ACCESS_KEY
and MINIO_URL
. The default values are minioadmin
and http://0.0.0.0:9000
respectivelyS3_BUCKET_NAME
docker run --rm -p 3000:3000 gagansingh894/jams start http --model-store=<aws|minio> --poll-interval 3600
docker run --rm -p 4000:4000 gagansingh894/jams start grpc --model-store=<aws|minio> --poll-interval 3600
docker run --rm -p 3000:3000 gagansingh894/jams start http --model-store=<aws|minio> --s3-bucket-name=<bucket_name>
STORAGE_ACCOUNT
, STORAGE_ACCESS_KEY
. You also need to set the azure container name. This can either be set via AZURE_STORAGE_CONTAINER_NAME
env variable or passed via --azure-storage-container-name
flagAZURE_STORAGE_CONTAINER_NAME
docker run --rm -p 3000:3000 gagansingh894/jams start http --model-store=azure --poll-interval 3600
docker run --rm -p 4000:4000 gagansingh894/jams start grpc --model-store=azure --poll-interval 3600
docker run --rm -p 3000:3000 gagansingh894/jams start http --model-store=azure --azure-storage-container-name=<container_name> --poll-interval 3600
Please refer to OpenAPI Spec for API endpoints. Alternatively, you can also refer to the proto definition.
Ensure that Cargo and Rust compiler are installed. Follow instructions here if not installed
This project relies on a couple of shared libraries. To easily set up, please follow the steps below
brew install bazel lightgbm tensorflow
sudo sh -c '
echo "Downloading libtorch for macOS (ARM64)...";
wget https://download.pytorch.org/libtorch/cpu/libtorch-macos-arm64-2.2.0.zip -O /usr/local/lib/libtorch-macos-arm64-2.2.0.zip;
echo "Unzipping libtorch into /usr/local/lib/libtorch2_2_0...";
mkdir -p /usr/local/lib/libtorch2_2_0;
unzip /usr/local/lib/libtorch-macos-arm64-2.2.0.zip -d /usr/local/lib/libtorch2_2_0;
echo "Cleaning up by deleting the zip file...";
rm /usr/local/lib/libtorch-macos-arm64-2.2.0.zip;
echo "Please add the following to your .bashrc/.zshrc and restart terminal...";
COMMON_LIBS_PATH=/usr/local/lib
LIBTORCH=$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
LIBTORCH_INCLUDE=$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
LIBTORCH_LIB=$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
DYLD_LIBRARY_PATH=$COMMON_LIBS_PATH:$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
echo "Libtorch installed in /usr/local/lib/libtorch2_2_0 and zip file deleted.";
'
sudo wget -q https://github.com/catboost/catboost/releases/download/v1.2.5/libcatboostmodel-darwin-universal2-1.2.5.dylib -O /usr/local/lib/libcatboostmodel.dylib
sudo cp /opt/homebrew/Cellar/lightgbm/$(brew list --versions lightgbm | awk '{print $2}')/lib/lib_lightgbm.dylib /usr/local/lib/ && sudo cp /opt/homebrew/Cellar/libomp/$(brew list --versions libomp | awk '{print $2}')/lib/libomp.dylib /usr/local/lib/
export COMMON_LIBS_PATH=/usr/local/lib
export LIBTORCH=$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
export LIBTORCH_INCLUDE=$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
export LIBTORCH_LIB=$COMMON_LIBS_PATH/libtorch2_2_0/libtorch
export DYLD_LIBRARY_PATH=$COMMON_LIBS_PATH:$COMMON_LIBS_PATH/libtorch2_2_0/libtorch/lib
cargo install jams
Use the bash script here based on your system architecture
Run the following commands or add them to shell profile
# add environment variables
export COMMON_LIBS_PATH=/usr/local/lib
export LIGHTGBM_LIB_DIR=$COMMON_LIBS_PATH
export LIBTORCH=$COMMON_LIBS_PATH/libtorch
export LIBTORCH_INCLUDE=$COMMON_LIBS_PATH/libtorch
export LIBTORCH_LIB=$COMMON_LIBS_PATH/libtorch
export LD_LIBRARY_PATH=$COMMON_LIBS_PATH:$COMMON_LIBS_PATH/libtorch/lib
export LIBRARY_PATH=$LIBRARY_PATH:$COMMON_LIBS_PATH/libtensorflow
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$COMMON_LIBS_PATH/libtensorflow/lib
cargo install jams
Once J.A.M.S is up and running, these endpoints will help you interact with the server.
Please refer to OpenAPI Spec for details.
/healthcheck
: Endpoint for health checks
/api/predict
: Endpoint for making predictions
/api/models
: Endpoint for managing models
Alternatively, you can refer also refer to the proto definition. It provides the following RPCs
HealthCheck
Predict
GetModels
AddModel
UpdateModel
DeleteModel
The CLI provides the following commands
- jams start
- jams predict
Use this command to start either the HTTP/gRPC model server on 0.0.0.0:3000
/0.0.0.0:4000
with separate rayon threadpool for computing predictions
The server expects a model directory containing the models. This can be either passed using the
--model-dir
flag
To start HTTP server
jams start http --model-dir path/to/model_dir
To start gRPC server
jams start grpc --model-dir path/to/model_dir
Alternatively, you can set the MODEL_STORE_DIR env variable pointing to the model directory
and run jams start http
or jams start grpc
export MODEL_STORE_DIR=path/to/model_dir
By default, the server runs on port 3000
and 2
workers in the rayon threadpool.You can override using
the --port
and --num-workers
flags respectively. The log level can also be changed to
DEBUG
level using --use-debug-level=true
.
Below is the expected structure of model stores.
└── model_store
├── catboost-my_awesome_binary_model.tar.gz
├── catboost-my_awesome_multiclass_model.tar.gz
├── catboost-my_awesome_regressor_model.tar.gz
├── catboost-titanic_model.tar.gz
├── lightgbm-my_awesome_binary_model_2.tar.gz
├── lightgbm-my_awesome_reg_model.tar.gz
├── lightgbm-my_awesome_xen_binary_model.tar.gz
├── lightgbm-my_awesome_xen_prob_model.tar.gz
├── pytorch-my_awesome_californiahousing_model.tar.gz
├── tensorflow-my_awesome_autompg_model.tar.gz
├── tensorflow-my_awesome_penguin_model.tar.gz
├── tensorflow-my_awesome_sequential_model.tar.gz
└── torch-my_awesome_penguin_model.tar.gz
Use this command for making predictions via CLI for making predictions for the following models
Refer below for some examples of the predict command.
There are multiple python scripts in examples folder which would allow you to generate different models and their corresponding sample json input. Below are some examples
jams predict tensorflow --model-path=tensorflow_penguin_functional --input-path=tensorflow_input.json
jams predict torch --model-path=torch_penguin.pt --input-path=torch_input.json
jams predict catboost --model-path=catboost_titanic --input-path=catboost_input.json
jams predict lightgbm --model-path=lightgbm_iris.txt --input-path=lightgbm_input.json