feat: add checkpoint management to TrainingClient#29
Merged
Conversation
Add save_state, load_state, load_state_with_optimizer, and list_checkpoints methods to TrainingClient, enabling checkpoint-based resume training through the SDK. Fixes #28
- save_state: synchronous POST (not operation), sends {type, path}
- load_state: sends checkpoint_id (not path), returns OperationHandle
- Checkpoint.from_payload: handle server's "type" field
- Add integration test (save/list verified; load blocked by server)
The server should generate the checkpoint path (including model_id),
not the SDK. Changed save_state() to send {"name": ...} instead of
{"path": ...} so the server can construct proper namespaced paths
like weaver://{model_id}/checkpoints/{name}.
Also added checkpoint test scripts for LoRA, FullFT, and baseline.
Refs: china-qijizhifeng/weaver-server#106
save_state input is name, output is Checkpoint with server-generated path.
load_state/load_state_with_optimizer now accept a path string (weaver://
URI) or Checkpoint object (extracts .path), and send {"path": ...} to the
server instead of {"checkpoint_id": ...}.
Refs: china-qijizhifeng/weaver-server#106
Replace "training" with "weight" and "training_with_optimizer" with "weight_and_optimizer" for clearer checkpoint type semantics.
save_state now dispatches an async operation via enqueue_operation (same pattern as load_state) instead of a synchronous POST. The server will dispatch a save task to the trainer, which writes weight files to disk. Adds wait parameter with overloads: returns Checkpoint when wait=True (default), OperationHandle when wait=False. Refs: china-qijizhifeng/weaver-server#109
Server returns {"checkpoint": {...}, "operation": {...}} instead of
a flat operation response. Extract operation for polling and checkpoint
data for the result.
…onse
Server should return a flat Operation (like all other async endpoints)
instead of nested {"checkpoint": ..., "operation": ...}. Revert to the
standard enqueue_operation pattern. Checkpoint data will come from the
operation's response field after completion.
Refs: china-qijizhifeng/weaver-server#111
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
save_state(),load_state(),load_state_with_optimizer(), andlist_checkpoints()methods toTrainingClientCheckpointdataclass type inweaver/types/checkpoint.pyDetails
Implements the checkpoint management API specified in #28:
save_state()POST /models/:id/checkpointsload_state(checkpoint)POST /models/:id/loadload_state_with_optimizer(checkpoint)POST /models/:id/loadlist_checkpoints()GET /models/:id/checkpointsAPI notes (discovered during integration testing)
save_state()is synchronous (returnsCheckpointdirectly, not anOperationHandle)load_state()accepts aCheckpointobject or raw checkpoint ID stringtypefield (notcheckpoint_type) andcheckpoint_id(notpath) for loadIntegration test results
save_state(name="after-3-steps")201 Createdlist_checkpoints()load_state(checkpoint)load_weightsoperation stays pendingThe
load_weightsoperation not completing is a server-side/trainer-side gap, consistent with the issue noting dependency on weaver-server#74. The SDK correctly sends{checkpoint_id, include_optimizer}toPOST /models/:id/loadand polls the operation.Test plan
make cipasses (lint + mypy + 56 unit tests)save_state+list_checkpointsverified against live serverload_statesends correct payload (blocked by server-side)Fixes #28