dream.fine_tuning
Import it as from dream import fine_tuning.
Fine-tuning jobs on the Dream Labs data service: train Dream-1 on an uploaded dataset, then run the result.
dream.DreamClient carries the two calls most callers need with its key bound (finetune(), get_finetuning_status()); the functions here are the whole set on their own, for a caller that passes api_key itself. Each answers the service’s JSON as it came: a job is a dict, a listing a list of them.
- create(): queues a job on one of your
processeddatasets under a suffix; the fine-tuned model’s checkpoint id will bedream-1-ft:<uid8>-<suffix>, in the job asfine_tuned_modelonce it is published. The training knoblearning_rateis optional: a knob left out takes the service’s default, and the service refuses one outside its range withinvalid_requestnaming the knob.use_eef(default False) asks the job to train the end-effector pose beside the joints; the dataset’s embodiment must then carry the six EEF parts (shared.datasets.embodiments.EEF_PARTS) in bothstateandaction, which create() checks before sending and the service checks again.lr_scheduleis"constant"(the default) or"cosine"; cosine decay works best for specialization (a fine-tune on a single task), and specialist tasks may not be highly reliable yet. - list() and get(): your jobs, newest first, and one by its id.
- cancel(): a job runs to its end once queued, so the cancel is refused with
conflict. - queue(): the line as a job queued now would see it.
- training_data(): where one of your fine-tunes’ training data is, for comparing camera views.
A job is a dict with these keys:
id:ftj_+ hex; what get() and cancel() take.dataset,embodiment: the dataset it trains on and that dataset’s embodiment, each<username>/<name>.base_model: the id of the checkpoint it starts from.suffix: the suffix it was created with.fine_tuned_model: the new checkpoint’s id,dream-1-ft:<uid8>-<suffix>, once the job has succeeded and the checkpoint is published; None before. It is whatDreamClient.policy()takes ascheckpoint.status:queued(waiting for a training slot, or for a GPU once it has one),running,succeeded,failedorcancelled.hyperparameters: the training settings, as the service filled them in.queue_position: 1 for the next job to start, whilequeuedbehind other jobs; None otherwise, a job waiting for a GPU included.created_at,started_at,finished_at: ISO 8601 times in UTC;started_atis when training started on a GPU (None before),finished_atis None until the job ends.progress: where the job is,{"phase", "step", "total_steps", "loss", "updated_at"}, on a deployment that reports it, else None:phaseiswaiting_for_gpu,preparing(the dataset and the base are set up),training(with the last loggedstepand the actionlossover your own data) orsaving(training is over and the model is checked and published).error: whenfailed, one line: what to fix in your dataset when the cause was in it, else that the training did not finish; None otherwise.
Poll get() until fine_tuned_model is set, not until succeeded alone: the checkpoint is published in the same pass that marks the job succeeded, or a little later when that publication is retried. A failed or cancelled job never gets one, so stop polling there. Then DreamClient.policy({"checkpoint": job["fine_tuned_model"]}) runs the model; its first get_action() is refused pool_warming (a retryable DreamServerError with retry_after_s) while the model starts, and a model that cannot be started is refused cannot_scale with the reason.
Errors: the URL and key are dream.datasets‘s (either one left out is the credentials’), and so are the errors. A refusal is a DreamServerError whose code is the service’s: not_found for a dataset or job that is not yours; conflict for a suffix in use, a dataset that is not processed, a cancel where fine-tuning is priced or of a job already over, payment_required for a job the account’s credits do not cover, or an account at its limit of jobs queued or running at once; invalid_request for a suffix or a knob out of range, naming it; validation for a knob of the wrong type; an HTTP 5xx one is retryable: make the same call again after a short wait. A key the service does not accept is DreamAuthError (forbidden: the account has no username yet, ask Dream Labs support to set one); a service that cannot be reached, or an answer that is not the Dream API’s, is DreamProtocolError; no key (and the credentials name none) is DreamConfigError.
Example
import time from dream import fine_tuning job = fine_tuning.create("<your-username>/towels-v1", "towels", api_key=KEY) while job["fine_tuned_model"] is None and job["status"] in ("queued", "running", "succeeded"): time.sleep(60) job = fine_tuning.get(job["id"], api_key=KEY)
dream.fine_tuning.create
Section titled “dream.fine_tuning.create”dream.fine_tuning.create( dataset: str, suffix: str, *, purpose: str | None = None, steps: int | None = None, learning_rate: float | None = None, batch_size: int | None = None, use_eef: bool = False, lr_schedule: str | None = None, resume_from: str | None = None, base_share: float | None = None, api_key: str | None = None, ) -> dict[str, Any]
Queues a fine-tuning job on one of your processed datasets.
A knob left as None is not sent, and the service fills in its default; the job’s hyperparameters says what it trains with. A knob out of range is refused with invalid_request, naming it. With use_eef, the dataset’s embodiment is fetched and checked here first (check_eef()), so a body that cannot train the end-effector pose is refused before anything is queued; a dataset the service does not list is left for the service to refuse.
Parameters
dataset(str): The dataset’s<username>/<name>(aDataset’sname), one of your own andprocessed.suffix(str):[a-z0-9-]{1,40}: the tail of the checkpoint iddream-1-ft:<uid8>-<suffix>; free among your models and active jobs.purpose(str | None, defaultNone, keyword-only):"embodiment"(a new robot body: half of each batch is Dream Labs data by default; bimanual robots with parallel grippers are the ones officially supported, and an out-of-distribution body should train10000steps) or"task"(automate a task: your data alone by default; fewer than10000steps will not give the best result). None takes"embodiment", or"task"whenstepsis over10000.steps(int | None, defaultNone, keyword-only): The training steps, any multiple of100:500to10000for an embodiment, default500;5000to30000for a task, default10000. None takes the purpose’s default. The price grows with the steps, and so does the time.learning_rate(float | None, defaultNone, keyword-only): The learning rate, 1e-6 to 1e-4; None takes the service’s default of 1e-5.batch_size(int | None, defaultNone, keyword-only): Leave it as None: the service sets it.use_eef(bool, defaultFalse, keyword-only): Whether the job trains the end-effector pose beside the joints. The dataset’s embodiment must then carry the six EEF parts,right_eef_xyz(3 wide),right_eef_rot6(6),right_grip(1) and the same three forleft, in bothstateandaction. False, the default, trains every part as joints. A body whoseactioncarriesright_eef_rot6orleft_eef_rot6trains only with it; without it the service refuses the job withinvalid_request. So does one whoseactioncarriesright_eef_xyzorleft_eef_xyzwithout that side’s_eef_xyz(3 wide) and_eef_rot6(6 wide) instate. The pose follows the base model’s convention, per arm:<side>_eef_xyzis the tool centre point in metres (on YAM 0.1347 m past the wrist flange along the last link’s z axis),<side>_eef_rot6the last link’s orientation as the first two columns of its rotation matrix,[R00, R10, R20, R01, R11, R21], both in that arm’s own base frame, and<side>_gripthe gripper opening, 0 closed to 1 open. A pose recorded another way passes every check and trains a mismatched model. A robot registered withparts(what each part is) decidesuse_eefitself, so leave it out: the service trains its gripper poses when its parts can. Asking it of one whose poses are recorded, not trained, is refused here.lr_schedule(str | None, defaultNone, keyword-only): The learning-rate schedule,"constant"or"cosine"; None takes the service’s default,"constant". Both warm up first;"cosine"then decays the rate to 0 by the last step. Cosine decay works best for specialization (a fine-tune on a single task). You may not get high reliability on specialist tasks yet.resume_from(str | None, defaultNone, keyword-only): The id of one of your fine-tuned models (dream-1-ft:...) to keep training: the job picks up where its training ended, optimizer and learning-rate schedule included, forstepsnew steps, and is charged for those alone. The model must be yours, trained after resuming was added and finished to its last step; the dataset must be on the same robot, andlearning_rate,batch_sizeanduse_eefmust stay the model’s, at the"constant"schedule. None, the default, trains a new model from the base.base_share(float | None, defaultNone, keyword-only): The share of each training batch drawn from Dream-1’s own general training data,0.5or0.0; None takes the service’s default of0.5. Half keeps more of what the model already does in general;0.0trains on your sessions alone, which fits them more closely but can lose general skill. The site’s Fine-tune form offers the same choice as Training data: “Mix in Dream Labs data” is0.5, “Train on my data only” is0.0. A job that continues a model keeps that model’s value.api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Returns
dict[str, Any]: The job dict (its keys are listed above), status queued. Keep job["id"] and poll get() until fine_tuned_model is set, or the job is failed or cancelled.
Raises
DreamConfigError: There is no key (and the credentials name none), a knob is not a plain number, oruse_eefis asked of a dataset whose embodiment lacks an EEF part or has one at another width (the message names the part and its side).DreamAuthError: The key was refused, or the account has no username yet (forbidden).DreamServerError:not_foundfor a dataset that is not yours;conflictfor one that is notprocessed, a suffix in use, or an account at its limit of active jobs;invalid_requestfor a suffix or a knob out of range, naming it, aresume_fromthe job cannot continue, saying why, or for a dataset whose embodiment’s action carries an end-effector rotation, or a position without its state pose, withoutuse_eef; aretryableone (HTTP 5xx) may be made again after a short wait.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.
dream.fine_tuning.check_eef
Section titled “dream.fine_tuning.check_eef”dream.fine_tuning.check_eef(dataset: str, *, api_key: str | None = None) -> None
Checks that a dataset’s embodiment can train the end-effector pose, the way create() does before sending.
The dataset is found among your datasets by its name and its embodiment fetched; the config is then held to the rule the service applies (shared.datasets.embodiments.check_eef): the six EEF parts in both state and action at their widths. A config with parts is held to it as training reads it (embodiments.trained), and passes only when its parts train the gripper poses. A dataset the service does not list passes here, and the service answers not_found on the create.
Parameters
dataset(str): The dataset’s<username>/<name>.api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Raises
DreamConfigError: The embodiment cannot train the end-effector pose; the message names the first missing or wrong part and its side, or the action width. Or there is no key.DreamAuthError: The key was refused, or the account has no username yet (forbidden).DreamServerError: The service refused a read; aretryableone (HTTP 5xx, already retried by the client) may be made again after a short wait.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.
dream.fine_tuning.list
Section titled “dream.fine_tuning.list”dream.fine_tuning.list(*, api_key: str | None = None) -> list[dict[str, Any]]
Your account’s fine-tuning jobs.
Parameters
api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Returns
list[dict[str, Any]]: A list of job dicts (the keys are listed above), newest first.
Raises
DreamConfigError: There is no key (and the credentials name none).DreamAuthError: The key was refused, or the account has no username yet (forbidden).DreamServerError: The service refused the call; aretryableone (HTTP 5xx, already retried by the client) may be made again after a short wait.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.
dream.fine_tuning.get
Section titled “dream.fine_tuning.get”dream.fine_tuning.get(job_id: str, *, api_key: str | None = None) -> dict[str, Any]
One of your jobs by its id, as the service holds it now; poll it to follow a job.
Parameters
job_id(str): The job’sid(ftj_+ hex), as create() answered it.api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Returns
dict[str, Any]: The job dict (the keys are listed above). status is queued, running, succeeded, failed or cancelled. Poll until fine_tuned_model is set, then pass it to DreamClient.policy() as checkpoint; stop polling on failed (error says so) or cancelled, which never get one.
Raises
DreamConfigError: There is no key (and the credentials name none).DreamAuthError: The key was refused, or the account has no username yet (forbidden).DreamServerError:not_foundfor a job that is not yours; aretryableone (HTTP 5xx, already retried by the client) may be made again after a short wait.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.
dream.fine_tuning.cancel
Section titled “dream.fine_tuning.cancel”dream.fine_tuning.cancel(job_id: str, *, api_key: str | None = None) -> dict[str, Any]
Asks to cancel one of your jobs; a job runs to its end once queued, so the service refuses with conflict.
Parameters
job_id(str): The job’sid(ftj_+ hex), as create() answered it.api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Returns
dict[str, Any]: The job dict as the service answered the cancel, status cancelled; it never gets a model.
Raises
DreamConfigError: There is no key (and the credentials name none).DreamAuthError: The key was refused, or the account has no username yet (forbidden).DreamServerError:not_foundfor a job that is not yours,conflictfor one already finished or where fine-tuning is priced; aretryableone (HTTP 5xx) may be made again after a short wait.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.
dream.fine_tuning.queue
Section titled “dream.fine_tuning.queue”dream.fine_tuning.queue(*, api_key: str | None = None) -> dict[str, Any]
The line as a job queued now would see it, counted over every account.
Parameters
api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Returns
dict[str, Any]: {"jobs_ahead_of_new", "running", "slots_free", "slots_total", "updated_at"}: the jobs queued ahead of a new one, the jobs training now, the training slots free and in all (a job takes one slot while it runs), and when the counts were taken, an ISO 8601 time in UTC.
Raises
DreamConfigError: There is no key (and the credentials name none).DreamAuthError: The key was refused, or the account has no username yet (forbidden).DreamServerError: The service refused the call; aretryableone (HTTP 5xx, already retried by the client) may be made again after a short wait.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.
dream.fine_tuning.training_data
Section titled “dream.fine_tuning.training_data”dream.fine_tuning.training_data( model: str, *, api_key: str | None = None, ) -> dict[str, Any]
Where to read the dataset one of your fine-tunes was trained on; dreamcli setup compares camera views with it.
Parameters
model(str): The fine-tune’s id (fine_tuned_modelof its job).api_key(str | None, defaultNone, keyword-only): Your API key; the credentials’ when None.
Returns
dict[str, Any]: {"url", "video", "cameras", "prompts"}: a one-hour download URL of the dataset’s zip, camera role to its video key, camera role to each frame size its sessions recorded ([width, height]), and every task its sessions name, sorted.
Raises
DreamServerError:not_foundwhen none of your jobs made the model, or its dataset was deleted.DreamProtocolError: The service could not be reached, or did not answer as the Dream API.