Checkpoint
A checkpoint is a saved copy of a training run's model, stored on Looper under a name you choose. While a run trains, its weights live on Looper's GPUs. Saving a checkpoint keeps a copy of them, so you can sample the trained model later, from any program in your project.
This page covers:
- Two kinds of checkpoint: saving the whole training state, or only the weights.
- The cookbook or your own code: which saves the cookbook makes for you, and which you make yourself.
- Save: save a checkpoint from a training run.
- Wait for readiness: wait for the upload to finish before you use the checkpoint.
- Names, replacement and expiry: what happens when you reuse a name, and when a checkpoint expires.
- Look up, list and delete: find your checkpoints, and remove the ones you don't need.
- What a checkpoint records: the fields every checkpoint has.
- Sample a checkpoint: generate text with the model you saved.
- Download a checkpoint: copy a weights checkpoint's files to your machine.
- Not offered yet: what you can't do with a checkpoint yet.
The code on this page assumes you've already connected to Looper and have a service, and a training_client for a run that has trained for at least one step. See Open a session and Create a training client.
Two kinds of checkpoint
There are two ways to save, and each makes a different kind of checkpoint:
save_statesaves the weights and the optimizer's state. The optimizer's state is what the optimizer keeps between steps to decide each update, such as its running averages.save_weightssaves only the weights, in the standard Hugging Face format. That's safetensors for a full-parameter run, or PEFT's adapter layout for a LoRA run.
save_state |
save_weights |
|
|---|---|---|
| Holds | The weights and the optimizer's state, at the run's current step | The weights only |
| Returns | Operation[StateCheckpoint] |
Operation[WeightsCheckpoint] |
| When you sample it | The sampler converts it when it starts | The sampler loads it directly |
Today, you can sample either kind, and download a weights checkpoint. A run can't start from a checkpoint yet (see Not offered yet), so the optimizer's state in a state checkpoint isn't used for anything yet.
You can also turn a ready state checkpoint into a weights checkpoint afterwards. In the portal, open the state checkpoint's page and click Export weights. This makes a weights checkpoint named <name>-hf. For a full-parameter run, it holds the model in Hugging Face's format. For a LoRA run, it holds the LoRA adapter, in PEFT's format, which loads on top of the base model. You can export a step once the run that saved it has stopped. If the export fails, its page says why, and you can export again to retry.
The cookbook or your own code
The cookbook's loops save only some checkpoints for you:
train_sftdoesn't save. You save once it returns, with the calls on this page.train_rlandtrain_rl_asynccan save the run's state every few steps if you setsave_everyin the loop's config. Each save is named<run id>-step-<step>. The loops don't save at the end on their own, and they don't wait for the uploads to finish.
So whichever loop you use, the final save is yours, and so is waiting for it before you sample it.
Save
To save, call save_state or save_weights on the training client with a name. Like other training calls, it takes two awaits. The first sends the save to Looper, and result() waits until the run has written it.
save = await training_client.save_state("sft-step-100", ttl_s=7 * 24 * 3600)
saved = await save.result(timeout_s=300)
print(saved.id, saved.name, saved.state.value) # state is "uploading"
The checkpoint isn't usable yet. Its state is uploading while Looper copies it to storage. The run keeps training during the upload. Before you sample it, wait for it to be ready.
Both calls take the same arguments:
| Argument | Meaning |
|---|---|
name |
The name you'll use to find and sample the checkpoint. It can be 1 to 256 characters long, with no NUL character. Saving under a name that's in use replaces it, as Names, replacement and expiry explains. |
ttl_s |
How long to keep the checkpoint, in seconds, counted from when it's ready. The example keeps it for 7 days. None, the default, keeps it until you delete or replace it. At most 2,147,483,647. |
key, after |
For resending a call safely and setting its order, as for every training call. See Submit ahead and TrainingClient. |
Things to know:
- A save captures the run after its last
optim_step. It saves the model as it was after the lastoptim_stepyou sent before the save. If you've sent aforward_backwardsince then without anoptim_step, the save raisesGradientsPending. Runoptim_stepfirst. - You can't save before the first step. A save before the run's first
optim_stephas nothing trained to save, and itsresult()raisesInvalidArgument. - Bad arguments fail at once. A bad
name, or attl_sof 0 or less, raisesInvalidArgument. Attl_sover the limit raisesValueError. - A run saves one checkpoint at a time. If you save again before the previous checkpoint is ready or has failed, the new save waits for it. So does everything you send after the new save, including training steps.
Wait for readiness
A checkpoint can be sampled only once its upload has finished. service.wait_checkpoint(checkpoint_id, *, timeout_s=None) waits for that, and returns the checkpoint once its state is ready_to_use:
checkpoint = await service.wait_checkpoint(saved.id, timeout_s=15 * 60)
print(checkpoint.name, checkpoint.size_bytes, checkpoint.expires_at)
Wait by the checkpoint's id, as above, not by its name. If the name already had a checkpoint, a lookup by name can still return the old one until the new one is ready.
The wait can end in one of two errors:
| Error | What it means | What to do |
|---|---|---|
CheckpointFailed, for a save |
The upload didn't finish. Either the run's GPUs were lost, restarted or released before it was done, or the upload took more than 10 minutes from the save. | Save again. |
CheckpointFailed, for an export |
Looper couldn't start the export, or find room for it in time. Or the conversion or upload failed, was lost or ran out of time. Or the source checkpoint expired, or another checkpoint took the name first. Or the last step, making it available under its name, failed. Temporary errors are retried by Looper instead. | Export again, unless .failure says a retry won't help, or the source checkpoint has expired. If the name was taken, delete the checkpoint that holds it first. |
TimeoutError |
timeout_s passed. Only the wait ends, and the upload carries on. |
Call wait_checkpoint again. |
In both CheckpointFailed cases, .failure says why, and the name still points to the checkpoint it had before, if any.
You don't need to wait to keep training. But wait before you sample the checkpoint, and before you close the session:
- Closing the session cancels the run's queued calls. So await the save's
result()before you close it, or the save may never happen. - After
result()returns, the upload carries on even if the session closes, and the name is set when it's done. But a closed session can't wait for the checkpoint, so you won't find out if it fails. See Close the session.
Names, replacement and expiry
Every checkpoint has a name in your project, which you use to find it and sample it.
- Names belong to your project. Other projects can't read, replace or delete your checkpoints.
- Saving under a name in use replaces the old checkpoint, once the new one is ready. Until then, the name still points to the old one, and it stays that way if the new upload fails. If several saves use the same name, the last one to become ready wins, whichever run made it and whichever kind it is.
- A replaced checkpoint can't be found any more, by any lookup, including
get_checkpointwith its id. - The TTL starts when the checkpoint is ready, which sets its
expires_at. Once it ends, the name can't be looked up or listed, and new samplers can't load it. - An export has no TTL of its own. It takes its source checkpoint's
expires_at, copied when you first ask for the export. Exporting again after a failure keeps that same copy. - Don't start a name with
base:orrun:. A sampler reads those as a base model or a training run, not a checkpoint.
Look up, list and delete
These calls are on service, not on the training client, and they see every checkpoint in the session's project.
| Call | What it does |
|---|---|
get_checkpoint(checkpoint_id) |
Returns one checkpoint by its id, whether it's uploading, failed or ready_to_use. A ready one is found only while it still holds its name and hasn't expired. Otherwise it raises NotFound. |
get_checkpoint_by_name(name) |
Returns the checkpoint that holds the name now, which is the last one under that name to become ready. Raises NotFound if none is ready yet, or it was deleted or has expired. |
list_checkpoints(*, limit=100, after_name=None) |
Returns ready checkpoints in name order, up to limit (1 to 1000) at a time, starting after after_name. |
delete_checkpoint(checkpoint_id) |
Removes the checkpoint's name at once. Its files are cleaned up later. |
list_checkpoints returns one page at a time. To go through all your checkpoints, pass the last name on each page as after_name:
after = None
while page := await service.list_checkpoints(limit=100, after_name=after):
for item in page:
print(item.name, item.kind, item.version.step, item.expires_at)
after = page[-1].name
Deleting a checkpoint that isn't ready works differently:
- A save that's still uploading has no name yet, so deleting it does nothing, and raises no error.
- An export that's still uploading raises
CheckpointNotReady. Delete it once it's ready. - A failed save or export has no name either. Deleting it changes nothing, and
get_checkpointstill shows it asfailed.
What a checkpoint records
wait_checkpoint, the lookups and the list all return checkpoints with these fields. Both kinds have the same ones (Checkpoint):
| Field | What it holds |
|---|---|
id |
The id that get_checkpoint and wait_checkpoint take. |
name |
Its name once it's ready. Before that, the name its save or export asked for. |
kind |
"state" or "weights". |
state, failure |
uploading, ready_to_use or failed, and why it failed. |
model_spec |
The run's model, and its exact Full() or Lora(...) settings. |
version |
The run it came from, the run's epoch, and the optimizer step that was saved. |
size_bytes |
Its size in storage once it's ready, and 0 before. |
created_at |
When it became ready. Before that, when its save succeeded or, for an export, when the export was last asked for. |
expires_at |
When its TTL ends. None before it's ready, or if it has no TTL. |
source_run_id, operation_id, project, principal |
The run and the save that made it, its project, and who saved it. For an export, operation_id is None, and the rest are its source checkpoint's. |
A save's result() always shows the checkpoint as it was when the save was written, uploading. To see its current state, call get_checkpoint.
Sample a checkpoint
To try the trained model, start a sampler with the checkpoint's name as checkpoint_name. It's the same create_sampling_client call you use for a base model:
from looper_sdk import SamplerConfig
sampling_client = await service.create_sampling_client(
SamplerConfig(
checkpoint_name=checkpoint.name,
max_seq_len=4096,
max_concurrent_sequences=8,
),
timeout_s=20 * 60,
)
- Any session in the project can sample it by name, so you can sample it from a different program than the one that trained it.
- Wait for a new checkpoint before you sample it. If a newer checkpoint is still uploading under a name that already has a ready one, a sampler started now loads the older one.
Create a sampling client explains how a sampler finds the checkpoint by its name, and what its errors mean.
Download a checkpoint
You can download a weights checkpoint's files to your own machine, for example to run the model yourself. To download a state checkpoint, export its weights first, as Two kinds of checkpoint describes.
The SDK comes with a looper command for this. With LOOPER_API_KEY set, give it your project, the checkpoint's name or ID, and the folder to save the files in:
looper download --project research my-export ./my-model
- If the download stops partway, run the same command again. It carries on from the files already on disk.
- Each file is checked against its checksum, so you know the files arrived complete.
- From Python, the same download is
await service.download_checkpoint(checkpoint.id, "./my-model").
Not offered yet
You can't do these with a checkpoint yet:
- Start a new training run from it.
TrainingConfigandcreate_training_clientdon't take a checkpoint. - Load it into a run that's already training.
- Rename it, or change its TTL after the save.