Skip to content

Model Management

Use the SDK for interacting with the OpenGradient Model Hub.

Uploading 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.

CLI Use

  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"

Library Use

Using the Python library for model management.

python
import opengradient as og

To initialize the opengradient client, run the following command:

python

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

Create a Model

To create a new model, run the following command:

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

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

Arguments
  • model_name: The name of the model repository.
  • model_desc: A brief description of the model.
Returns
  • model_name: The name of the model repository.

Create a Version of a Model

python
og.create_version(model_name="<model_name>", notes="<notes>")
Arguments
  • model_name: The name of the model repository.
  • notes: A note on the new version the model.
Returns
  • versionString: A new version.

Model Upload

To upload a new model, use the following command:

python
og.upload(model_path="<model_path>", model_name="<model_name>", version="<version>")
Arguments
  • model_path: The path to the model file you want to upload.
  • model_name: The unique string of the model name.
  • version: The unique string of the version.
Returns
  • The JSON response with the file upload:
json
{
  "cid": "QmbFMke...QH",
  "filename": "model_name.onnx",
  "input_types": [
    {
      "name": "input",
      "shape": [ ... ],
      "type": "tensor(float)"
    }
  ],
  "output_types": [
    {
      "name": "output",
        ...
    }
  ],
  "size": 1350011999,
  "total_time": 7.946619033813477
}

List Files of a Model Version

python
og.list_files(model_name="<model_name>", version="<version>")
Arguments
  • model_name: The name of the model repository.
  • notes: A note on the new version the model.
Returns
  • versionString: A new version.

Example

python
import opengradient as og

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

model_name = "<model_name>"

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

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

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

OpenGradient 2024