Custom Model Tutorial
This tutorial will upload our custom model to OpenGradient and use it from a smart contract and through our off-chain Python SDK.
The model and related files can be found in our GitHub repo: https://github.com/opengradient
Our model repository will contain 2 files: dynamic_fee_model.onnx and a README.md file. The model is contained inside a directory called model.
model % ls
dynamic_fee_model.onnx README.md
To upload our model to OpenGradient, we will use our CLI bundled with our Python SDK. To install and set it up, go to Python SDK.
We will use the upload command to upload the files to our new repository directly. The repository is automatically created as part of uploading the files.
opengradient upload ...
After uploading the files, we must grab the unique Model Identifier of the dynamic_fee_model.onnx
. We can use this to send inference requests to our dynamic fee model. You can find it in the output of the upload command.
In this case, the Model ID is fewjietoj
.
To quickly test it for inference, you can use the CLI tool to send an on-chain transaction to OpenGradient that executes the model with your given input: opengradient infer "xxxx" "[]"
As an alternative, you can also write a Python script that uses our SDK to programatically send inference requests.
import opengradient as og
og.init()
og.infer()
Finally, we can also use our model directly from a smart contract on OpenGradient. Start by creating a new file called dynamic_fee_contract.sol
.
contract DynamicFeeContract {
}
TODO: finish