Skip to content

Model Management

Use the SDK to create and manage your models on the OpenGradient Model Hub.

Managing Models

To add files to existing or new model repositories, you need to define its name and version. If you use a model repository name that doesn't exist, it will automatically be created. Similarly, if you upload a file to a new version, the version will automatically be added to the repository.

You can use either our Python library or CLI to upload new files.

Using the CLI

  1. To create a new model repository, use the following command:
bash
opengradient create-model-repo --repo "my_model" --description "my description"
  1. To add files to a model repository, you need to create a version. In the above create-model call, version 0.01 is automatically initialized for you. Versions can be used to organize different iterations of the same model. To create a new version, use:
bash
opengradient create-version --repo "my_model" --notes "major feature"
  1. To upload your ONNX model file or any associated file to a given model and version, use the following command:
bash
opengradient upload-file path/to/model.onnx --repo "my_model" --version "0.01"
  1. To list the files of a particular version of a model, run the list_files command:
bash
opengradient list-files --repo "my_model" --version "0.01"

Using the Library

Using the Python library for model management. To create the opengradient client, run the following command:

python
import opengradient as og

client = og.Client(private_key="<private_key>", email="<email>", password="<password>")

TIP

Refer to our Getting Started guide to obtain these credentials

Creating a Model Repo

To create a new model, run the following command:

python
client.model_hub.create_model(model_name="<model_name>", model_desc="<model_description>")

create_model automatically calls create_version to initalize v0.01 of your new model

Check the API Reference for more details.

Creating a new version

python
new_version = client.model_hub.create_version(model_name="<model_name>", notes="<notes>")

Check the API Reference for more details.

File Upload

To upload a file to a specific model repo and version, use the following command:

python
client.model_hub.upload(model_path="<model_path>", model_name="<model_name>", version="<version>")

Check the API Reference for more details.

List Files

To see what files are in a model repo and version:

python
client.model_hub.list_files(model_name="<model_name>", version="<version>")

Tutorial

python
import opengradient as og

# Create the opengradient client
client = og.Client(private_key="<private_key>", email="<email>", password="<password>")

model_name = "<model_name>"

# Create a Model
client.model_hub.create_model(model_name, model_desc="OpenGradient's dynamic fee model")

# Create a Version for the Model
versionString = client.model_hub.create_version(model_name, notes="<notes>")

# Uploading a model
client.model_hub.upload(model_path="local_path_to_your_model.onnx", model_name=model_name, version=versionString)

SDK API Reference

Please refer to our API Reference for any additional details around the SDK methods.