SDK Quickstart
Overview
Use the Gradient SDKs to easily fine-tune your own models and deploy them into your applications.
Python SDK:
Javascript SDK:
Note: Users have encountered issues installing Gradient with Python versions 3.9 or earlier. We recommend using Python 3.10 or later for a smoother user experience.
This quickstart guide will get you set up with the Python SDK and give you an example.
You can also try out our Google Colab notebook as a starter kit. The code is already written for you. All you need is to add your access token and workspace ID.
🏕️ Set up your environment
Note that Gradient requires Python version 3.10 or newer.
Install the Gradient Python SDK
If you do not have Python installed, install it here.
Install the Gradient Python SDK with the following command:
$ pip install gradientai --upgrade
Then import the package:
import gradientai
Authentication
Create a .env
file to add in your API access token and workspace ID in place of each empty field ...
in the file.
GRADIENT_ACCESS_TOKEN=...
GRADIENT_WORKSPACE_ID=...
Once this file is updated, your Python files will be able to pull authentication information from your environment.
Get an access token
Generate a new access token at https://auth.gradient.ai/access-tokens. See Authentication for more information.
Find your workspace ID
You can find your workspace ID at https://auth.gradient.ai/select-workspace below the number of members in your workspace.
Complete Setup
Create a new Python file and paste in the following code. Run it to complete your environment setup.
from gradientai import Gradient
from dotenv import load_dotenv
load_dotenv()
def main():
gradient = Gradient()
base_model = gradient.get_base_model(base_model_slug="bloom-560m")
new_model_adapter = base_model.create_model_adapter(
name="my test model adapter"
)
print(f"Created model adapter with id {new_model_adapter.id}")
new_model_adapter.fine_tune(samples=[{"inputs": "princess, dragon, castle"}])
sample_query = "what is the largest animal?"
print(f"Asking: {sample_query}")
completion = new_model_adapter.complete(query=sample_query, max_generated_token_count=100).generated_output
print(f"Generated: {completion}")
new_model_adapter.delete()
gradient.close()
if __name__ == "__main__":
main()
🖥️ Python Example
Note: The example is still in development. Please let us know if you are running into errors.
Download Example
Here is an example to get started. You can see some of the example code in the SDK Tutorial.
Clone this Github repository.
Authentication
If you have not created your .env
file with authentication information, please follow instructions above in Authentication.
Install Poetry
Poetry is a tool for dependency management and packaging in Python. It will install and update the libraries your project depends on.
This example uses Poetry. Install the Poetry package with:
$ pip install poetry
Complete the setup with:
$ poetry install
Run
Run the example python program:
$ poetry run fine_tune
The program creates a new instance of a base model, runs a simple fine-tune, and generates a completion.
Help
In some cases Python 3 might not be set as the default. In this case you may need to use python3
and pip3
to install Gradient. Please note that Gradient requires at least version 3.10 of Python. You can verify your version is compatible by running python3 --version
.
Updated 21 days ago