Getting Started with the Python SDK
The easiest and quickest way to upload your PyTorch models onto the Cellulose dashboard is via our Python SDK.
Installation
Let’s start by installing it with pip
:
While the Python SDK doesn’t currently require PyTorch 2.0
(torch > 2.0.0
),
some of our future SDK features will require it as we’ll start using many of
the new PyTorch 2.0 APIs / IRs such as .compile()
.
Add Cellulose decorator to your nn.Module
Let’s create a new Python script that contains a simple nn.Module
that we
eventually want to export and upload to the dashboard.
First, let’s import everything we’ll need in the later steps:
We’ll first use the Cellulose
decorator and come back to CelluloseContext
in a later section.
Decorate the SuperResolutionNet
module with the Cellulose
decorator, then
provide the input_names
and output_names
arguments:
Now that we’ve defined the model, let’s instantiate it as torch_model
,
call load_state_dict
and set it to eval mode:
Create an input tensor
Instantiate a CelluloseContext
Now let’s create a CelluloseContext
and pass in a personal API key. You can
read more on how to create / retrieve your API keys
here.
We generally do not recommend setting these API keys in plain text for security reasons. It’s better to handle it via a secrets manager like AWS Secrets Manager or Doppler then have it injected as an environment variable.
Export and upload the model to the dashboard
We just provide the torch_model
module and the input tensor to
CelluloseContext
’s export()
method like below:
This step would handle the model upload automatically for you.
If all goes well, you’ll get something like the following:
You can now navigate to your dashboard to find the uploaded model!
Uploaded PyTorch model in the model list
Graph of uploaded PyTorch model
If it didn’t go well, you might get the following:
Please reach out to support@cellulose.ai in this case. We’d like to help and get you on your way ASAP!
Generate the Cellulose artifact with all exported model assets
The SDK also has a flush
method that conveniently packs all the generated
ONNX outputs in a zip file.
The line of code above generates a generated_artifacts.cellulose.zip
folder
in the “current” directory.
Here are the contents once it is unzipped:
The TOML metadata file is autogenerated and shouldn’t be directly modified. This is mostly useful to us for debugging and diagnostics purposes so we can help you resolve issues quickly if you run into them.
While limited in feature scope today, the Cellulose artifact will play a larger role when interfacing with the larger Cellulose roadmap and future product offerings.
Congratulations! You’ve uploaded your first PyTorch model to the dashboard via the SDK!
For your convenience, the full example Python script is also available here.
Have questions / need help?
Please reach out to support@cellulose.ai, and we’ll get back to you as soon as possible.