Python SDK for Gradients.io training jobs
Project description
gradientsio Python SDK
Python SDK for launching and monitoring Gradients.io training jobs.
Installation
pip install gradientsio
export GRADIENTS_API_KEY="..."
Quick Start
from gradientsio import GradientsClient
from gradientsio import TaskType
client = GradientsClient()
task = client.train(
model="Qwen/Qwen2.5-7B-Instruct",
task_type=TaskType.INSTRUCT,
hours=1,
dataset="yahma/alpaca-cleaned",
field_instruction="instruction",
field_input="input",
field_output="output",
)
result = task.wait(poll_interval=600)
print(result.trained_model_repository)
For prepared JSON/S3 datasets:
from gradientsio import Datasets
from gradientsio import GradientsClient
from gradientsio import TaskType
client = GradientsClient()
task = client.train(
model="Qwen/Qwen2.5-7B-Instruct",
task_type=TaskType.INSTRUCT,
hours=1,
dataset=Datasets.S3("https://example.com/train.json", test_data="https://example.com/test.json"),
)
Supported task types are available from TaskType:
TaskType.INSTRUCT
TaskType.CHAT
TaskType.DPO
TaskType.GRPO
TaskType.IMAGE
Design
Gradients is a job-based training platform. The SDK mirrors that lifecycle:
- Configure API-key auth.
- Check pricing.
- Create a task.
- Persist the returned
task_id. - Poll status until
successor a failure state. - Fetch the trained model repository.
The SDK does not perform registration, funding, or automatic paid retries.
Account And API Key
Create a Gradients account and API key outside the SDK, either from the Gradients app or the public account API.
Minimal API bootstrap flow:
curl -X POST "https://api.gradients.io/account-create" \
-H "Content-Type: application/json" \
-d '{"username": "alice"}'
curl -X POST "https://api.gradients.io/auth-with-fingerprint" \
-H "Content-Type: application/json" \
-d '{"fingerprint": "<fingerprint>"}'
curl -X POST "https://api.gradients.io/api-key-create" \
-H "Authorization: Bearer <session_token>"
Then configure the SDK:
export GRADIENTS_API_KEY="..."
export GRADIENTS_SESSION_TOKEN="..." # Required only for account balance/deposit endpoints.
Most SDK calls use GRADIENTS_API_KEY. Account functions use GRADIENTS_SESSION_TOKEN because the API's balance and deposit endpoints require a session token rather than an API key.
Balance
Check your account balance before launching paid jobs:
from gradientsio import GradientsClient
client = GradientsClient() # Uses GRADIENTS_SESSION_TOKEN for client.account.
account = client.account.get_info()
print(account)
If you need the deposit address for funding, request your public key:
deposit = client.account.get_public_key()
print(deposit["public_key"])
You will need to send TAO to the public key address to get credits.
Pricing
Check pricing before creating tasks.
For text tasks such as instruct, chat, DPO, or GRPO:
from gradientsio import GradientsClient
client = GradientsClient()
quote = client.tasks.check_text_price(
model_repo="Qwen/Qwen2.5-7B-Instruct",
hours_to_complete=1,
)
print(quote.model_dump(exclude_none=True))
For image tasks:
quote = client.tasks.check_image_price(
model_repo="stabilityai/stable-diffusion-xl-base-1.0",
hours_to_complete=1,
)
print(quote.model_dump(exclude_none=True))
You can also fetch the current public price table:
prices = client.tasks.prices()
print(prices)
Tasks
Create a task with client.train(...) as shown above. The returned object is a task handle.
Monitor a newly created task:
task = client.train(...)
result = task.wait(poll_interval=600)
print(result.status)
print(result.trained_model_repository)
Monitor an existing task:
task = client.tasks.handle("task-id")
details = task.refresh()
print(details.status)
print(details.trained_model_repository)
Fetch task details directly:
details = client.tasks.get("task-id")
Scheduler
Use the scheduler for long-running or multi-iteration training where one or more datasets are merged, chunked, and trained across multiple iterations. Each successful iteration can build on the previous merged model. The scheduler currently supports InstructText, Chat, and CustomDatasetChat jobs.
from gradientsio import GradientsClient
from gradientsio import SchedulerDataset
client = GradientsClient()
job = client.scheduler.create_job(
name="alpaca-iterative-training",
task_type="InstructText",
model_repo="Qwen/Qwen2.5-1.5B-Instruct",
hours_to_complete=1,
samples_per_training=80000,
final_test_size=0.1,
datasets=[
SchedulerDataset(
name="yahma/alpaca-cleaned",
field_instruction="instruction",
field_input="input",
field_output="output",
max_rows=50000,
),
SchedulerDataset(
name="tatsu-lab/alpaca",
field_instruction="instruction",
field_input="input",
field_output="output",
max_rows=50000,
)
],
)
job.wait(poll_interval=600)
results = job.results()
print(results.latest_merged_model_repo)
Monitor an existing scheduler job:
job = client.scheduler.handle("scheduler-job-id")
details = job.refresh()
print(details.status)
results = job.results()
print(results.latest_merged_model_repo)
Or block until the scheduler job reaches a terminal state:
job = client.scheduler.handle("scheduler-job-id")
details = job.wait(poll_interval=600)
print(details.status)
print(job.results().latest_merged_model_repo)
Performance Data
Performance endpoints expose public tournament and weight-projection data. They can be useful to estimate the current tournament winners' emissions and calculate how much alpha would a new winner get on winning.
weights = client.performance.latest_tournament_weights()
projection = client.performance.weight_projection(percentage_improvement=10.0)
static_projection = client.performance.weight_projection_static()
boss_battle = client.performance.last_boss_battle()
Environment Variables
| Variable | Description |
|---|---|
GRADIENTS_API_KEY |
Gradients API key |
GRADIENTS_SESSION_TOKEN |
Session token required for account functions, such as balance checks and public key retrieval |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gradientsio-0.1.0.tar.gz.
File metadata
- Download URL: gradientsio-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d605ac2dc1df2c840a44cef5c63e3d50c8b756c27967ef9565fa85e0a60200b9
|
|
| MD5 |
af665d2a7cc0735224b33a17804976ab
|
|
| BLAKE2b-256 |
21da97763f75ef7ee5dd1f0f14b278d4a952de05ad5d716d1612078c9e55c163
|
File details
Details for the file gradientsio-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gradientsio-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f63ec8a5a4a3be9468d5623ec23abff5d152a7edda9f46e5002c95736719df7
|
|
| MD5 |
7a26f0f3a96f9b1dd665cd420e526761
|
|
| BLAKE2b-256 |
9cfee6c69b965358c449c7be742c9bfdcf9aaf61d3c2f963566a276563ccccca
|