Looper Documentation
Looper Cookbook

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:

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_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:

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:

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:

Names, replacement and expiry

Every checkpoint has a name in your project, which you use to find it and sample it.

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:

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,
)

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

Not offered yet

You can't do these with a checkpoint yet: