o41-checkpoint 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- o41_checkpoint-0.1.0/LICENSE +176 -0
- o41_checkpoint-0.1.0/PKG-INFO +166 -0
- o41_checkpoint-0.1.0/README.md +152 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/.gitignore +1 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/Cargo.lock +1851 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/Cargo.toml +23 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/LICENSE +176 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/README.md +116 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/examples/smoke.rs +151 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/examples/smoke.sky.yaml +27 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/config.rs +54 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/lib.rs +661 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/local.rs +108 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/manifest.rs +140 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/o41.rs +820 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/place.rs +266 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/store.rs +149 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/src/transfer.rs +288 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/tests/contract.rs +21 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/tests/local.rs +235 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/tests/o41.rs +709 -0
- o41_checkpoint-0.1.0/crates/o41-checkpoint/tests/store.rs +121 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/Cargo.lock +1915 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/Cargo.toml +28 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/LICENSE +176 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/README.md +152 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/docs/development.md +87 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/rust/lib.rs +331 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/scripts/smoke_wheel.py +43 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/tests/test_checkpoints.py +206 -0
- o41_checkpoint-0.1.0/libs/o41_checkpoint/tests/test_o41.py +320 -0
- o41_checkpoint-0.1.0/pyproject.toml +24 -0
- o41_checkpoint-0.1.0/src/o41_checkpoint/__init__.py +30 -0
- o41_checkpoint-0.1.0/src/o41_checkpoint/_core.pyi +38 -0
- o41_checkpoint-0.1.0/src/o41_checkpoint/client.py +315 -0
- o41_checkpoint-0.1.0/src/o41_checkpoint/py.typed +0 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: o41-checkpoint
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Requires-Dist: pytest>=8.0.0 ; extra == 'dev'
|
|
5
|
+
Requires-Dist: ruff>=0.15.12 ; extra == 'dev'
|
|
6
|
+
Requires-Dist: ty>=0.0.34 ; extra == 'dev'
|
|
7
|
+
Provides-Extra: dev
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Summary: Python bindings for 041's Rust checkpoint engine
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
Requires-Python: >=3.14, <3.15
|
|
12
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
13
|
+
|
|
14
|
+
# 041 Checkpoint for Python
|
|
15
|
+
|
|
16
|
+
Save, resume, and fork training checkpoints with Python bindings to the
|
|
17
|
+
`o41-checkpoint` Rust engine.
|
|
18
|
+
|
|
19
|
+
The Rust core handles multipart uploads, parallel ranged reads, retries, signed
|
|
20
|
+
URL refresh, placement, and writer fencing. The Python interface accepts bytes
|
|
21
|
+
and paths and returns typed checkpoint objects. Blocking calls release the GIL.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
uv add o41-checkpoint
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Requires Python 3.14. Wheels target Linux x86-64, Linux arm64, and macOS arm64.
|
|
30
|
+
Building from source requires Rust.
|
|
31
|
+
|
|
32
|
+
## Resume and save
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from pathlib import Path
|
|
36
|
+
from o41_checkpoint import Checkpoints, step_name
|
|
37
|
+
|
|
38
|
+
checkpoints = Checkpoints("o41://experiments/run-1")
|
|
39
|
+
writer = checkpoints.resume()
|
|
40
|
+
|
|
41
|
+
if writer.resumed is not None:
|
|
42
|
+
writer.resumed.download("./restored")
|
|
43
|
+
|
|
44
|
+
saved = writer.save(
|
|
45
|
+
step_name(600),
|
|
46
|
+
{
|
|
47
|
+
"weights.safetensors": Path("weights.safetensors"),
|
|
48
|
+
"state.json": b'{"step": 600}',
|
|
49
|
+
},
|
|
50
|
+
meta={"step": 600, "loss": 0.42},
|
|
51
|
+
)
|
|
52
|
+
print(saved.path, saved.size)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`resume()` returns a writer whose `resumed` checkpoint is the latest, or `None`
|
|
56
|
+
when the location is empty. The same writer can save many checkpoints.
|
|
57
|
+
`writer.latest` is the name that the next save must exceed. Use `start()` to
|
|
58
|
+
require an empty location.
|
|
59
|
+
|
|
60
|
+
Each file value is bytes or a filesystem path. Strings are paths. Rust reads
|
|
61
|
+
paths one upload part at a time. Keep source files unchanged until `save()`
|
|
62
|
+
returns. The core commits the manifest last, so interrupted saves do not appear
|
|
63
|
+
in `load()` or `list()`.
|
|
64
|
+
|
|
65
|
+
`save()` returns a `Saved` receipt with `name`, `path`, `committed`, `size`,
|
|
66
|
+
`placement`, and `warning`. It returns after commit, without a follow-up read.
|
|
67
|
+
Names must ascend in byte order. `step_name(600)` produces `step-00000600`. Use
|
|
68
|
+
your own naming scheme for runs beyond 99,999,999 steps.
|
|
69
|
+
|
|
70
|
+
## Read a checkpoint
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
latest = checkpoints.load() # None when no checkpoint is committed
|
|
74
|
+
at_step = checkpoints.load(step_name(600))
|
|
75
|
+
|
|
76
|
+
if at_step is not None:
|
|
77
|
+
state = at_step["state.json"].read()
|
|
78
|
+
header = at_step["weights.safetensors"].read(start=0, stop=8)
|
|
79
|
+
at_step["weights.safetensors"].download("./weights.safetensors")
|
|
80
|
+
at_step.download("./checkpoint")
|
|
81
|
+
print(at_step.meta, at_step.committed)
|
|
82
|
+
|
|
83
|
+
for checkpoint in checkpoints.list():
|
|
84
|
+
print(checkpoint.name, checkpoint.size)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Reading and listing do not open a writer. `load()` and `load("latest")` return
|
|
88
|
+
the latest checkpoint. A missing checkpoint returns `None`.
|
|
89
|
+
|
|
90
|
+
`checkpoint.files` maps names to files with `name` and `size`. Checkpoints also
|
|
91
|
+
expose `path`, `name`, `committed`, `size`, `meta`, `source`, `location`, and
|
|
92
|
+
`transfer`. Commit times are timezone-aware `datetime` values. `location` and
|
|
93
|
+
`transfer` are `None` for local directories and raw buckets.
|
|
94
|
+
|
|
95
|
+
`read()` returns bytes. Ranges use Python's exclusive `stop` convention. Large
|
|
96
|
+
reads use the core's parallel range reader. `download()` transfers files in
|
|
97
|
+
bounded windows and returns a `Path`. It stages downloads beside the target and
|
|
98
|
+
replaces files after successful transfer. A checkpoint download stages all files
|
|
99
|
+
before moving them into the destination, one file at a time. Other files in the
|
|
100
|
+
destination remain in place. It downloads the checkpoint's data files; it does
|
|
101
|
+
not create a checkpoint catalog at the destination.
|
|
102
|
+
|
|
103
|
+
## Fork a run
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
source = checkpoints.load(step_name(600))
|
|
107
|
+
if source is not None:
|
|
108
|
+
fork = Checkpoints("o41://experiments/run-2").fork(source)
|
|
109
|
+
assert fork.resumed is not None
|
|
110
|
+
fork.resumed.download("./fork-source")
|
|
111
|
+
fork.save(step_name(700), {"state.json": b'{"step": 700}'})
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`fork()` requires an empty destination. It accepts a `Checkpoint` or a concrete
|
|
115
|
+
checkpoint path, such as `o41://experiments/run-1/step-00000600`. Load the
|
|
116
|
+
latest checkpoint first to fork it. The source stays in its existing location.
|
|
117
|
+
The first save records `checkpoint.source`; subsequent saves do not.
|
|
118
|
+
|
|
119
|
+
## Choose storage
|
|
120
|
+
|
|
121
|
+
The same API supports these locations:
|
|
122
|
+
|
|
123
|
+
| Location | Storage | Writer fencing |
|
|
124
|
+
| --------------------------------- | --------------------------------------- | -------------- |
|
|
125
|
+
| `./checkpoints/run-1` or a `Path` | Local directory | No |
|
|
126
|
+
| `s3://bucket/run-1` | S3-compatible bucket | No |
|
|
127
|
+
| `gs://bucket/run-1` | Google Cloud Storage | No |
|
|
128
|
+
| `az://account/container/run-1` | Azure Blob Storage | No |
|
|
129
|
+
| `o41://experiments/run-1` | 041 Artifacts placement and signed URLs | Yes |
|
|
130
|
+
|
|
131
|
+
Local directories need no credentials. Raw buckets use the Rust `object_store`
|
|
132
|
+
credential configuration. Pass overrides through
|
|
133
|
+
`store_options={"aws_region": "us-east-1"}`, using `object_store` option names.
|
|
134
|
+
|
|
135
|
+
For `o41://`, set `O41_ARTIFACTS_API_KEY` to an organization API key.
|
|
136
|
+
`O41_ARTIFACTS_URL` overrides `https://artifacts.041.io`. `O41_ARTIFACTS_CLOUD`
|
|
137
|
+
and `O41_ARTIFACTS_REGION` override placement together. Otherwise the core
|
|
138
|
+
detects placement through SkyPilot or VM metadata and uses the organization's
|
|
139
|
+
fallback when unknown.
|
|
140
|
+
|
|
141
|
+
`Checkpoints(location, api_key=..., url=..., organization=..., cloud=..., region=..., retry_for=..., store_options=...)`
|
|
142
|
+
overrides the core's environment configuration. `retry_for` is a duration in
|
|
143
|
+
seconds. Omitted options use the Rust defaults, including its retry rules and
|
|
144
|
+
longer begin/commit deadlines.
|
|
145
|
+
|
|
146
|
+
## Notes and failures
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
checkpoints.write_note("evaluated.json", b'{"step": 600}')
|
|
150
|
+
note = checkpoints.note("evaluated.json") # bytes, or None when absent
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Notes hold up to 64 KiB beside the checkpoints and do not require a writer. A
|
|
154
|
+
checkpoint holds 1 to 1000 files and up to 16 KiB of JSON metadata. File names
|
|
155
|
+
cannot contain directories.
|
|
156
|
+
|
|
157
|
+
`CheckpointError` reports failures from the Rust engine. `NotEmpty` and
|
|
158
|
+
`Superseded` derive from it. On `o41://`, another writer opening the artifact
|
|
159
|
+
fences the old writer. Catch `Superseded` to stop that run. Exceptions expose
|
|
160
|
+
`code`, `status`, `epoch`, and `location` when the core supplies them. Python
|
|
161
|
+
argument conversion errors use `TypeError` or `ValueError`, and local staging
|
|
162
|
+
failures can raise `OSError`.
|
|
163
|
+
|
|
164
|
+
Handles retain the Rust runtime for as long as they are referenced. Create them
|
|
165
|
+
inside each worker process rather than sharing them across a process fork.
|
|
166
|
+
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# 041 Checkpoint for Python
|
|
2
|
+
|
|
3
|
+
Save, resume, and fork training checkpoints with Python bindings to the
|
|
4
|
+
`o41-checkpoint` Rust engine.
|
|
5
|
+
|
|
6
|
+
The Rust core handles multipart uploads, parallel ranged reads, retries, signed
|
|
7
|
+
URL refresh, placement, and writer fencing. The Python interface accepts bytes
|
|
8
|
+
and paths and returns typed checkpoint objects. Blocking calls release the GIL.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
uv add o41-checkpoint
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Requires Python 3.14. Wheels target Linux x86-64, Linux arm64, and macOS arm64.
|
|
17
|
+
Building from source requires Rust.
|
|
18
|
+
|
|
19
|
+
## Resume and save
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from pathlib import Path
|
|
23
|
+
from o41_checkpoint import Checkpoints, step_name
|
|
24
|
+
|
|
25
|
+
checkpoints = Checkpoints("o41://experiments/run-1")
|
|
26
|
+
writer = checkpoints.resume()
|
|
27
|
+
|
|
28
|
+
if writer.resumed is not None:
|
|
29
|
+
writer.resumed.download("./restored")
|
|
30
|
+
|
|
31
|
+
saved = writer.save(
|
|
32
|
+
step_name(600),
|
|
33
|
+
{
|
|
34
|
+
"weights.safetensors": Path("weights.safetensors"),
|
|
35
|
+
"state.json": b'{"step": 600}',
|
|
36
|
+
},
|
|
37
|
+
meta={"step": 600, "loss": 0.42},
|
|
38
|
+
)
|
|
39
|
+
print(saved.path, saved.size)
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`resume()` returns a writer whose `resumed` checkpoint is the latest, or `None`
|
|
43
|
+
when the location is empty. The same writer can save many checkpoints.
|
|
44
|
+
`writer.latest` is the name that the next save must exceed. Use `start()` to
|
|
45
|
+
require an empty location.
|
|
46
|
+
|
|
47
|
+
Each file value is bytes or a filesystem path. Strings are paths. Rust reads
|
|
48
|
+
paths one upload part at a time. Keep source files unchanged until `save()`
|
|
49
|
+
returns. The core commits the manifest last, so interrupted saves do not appear
|
|
50
|
+
in `load()` or `list()`.
|
|
51
|
+
|
|
52
|
+
`save()` returns a `Saved` receipt with `name`, `path`, `committed`, `size`,
|
|
53
|
+
`placement`, and `warning`. It returns after commit, without a follow-up read.
|
|
54
|
+
Names must ascend in byte order. `step_name(600)` produces `step-00000600`. Use
|
|
55
|
+
your own naming scheme for runs beyond 99,999,999 steps.
|
|
56
|
+
|
|
57
|
+
## Read a checkpoint
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
latest = checkpoints.load() # None when no checkpoint is committed
|
|
61
|
+
at_step = checkpoints.load(step_name(600))
|
|
62
|
+
|
|
63
|
+
if at_step is not None:
|
|
64
|
+
state = at_step["state.json"].read()
|
|
65
|
+
header = at_step["weights.safetensors"].read(start=0, stop=8)
|
|
66
|
+
at_step["weights.safetensors"].download("./weights.safetensors")
|
|
67
|
+
at_step.download("./checkpoint")
|
|
68
|
+
print(at_step.meta, at_step.committed)
|
|
69
|
+
|
|
70
|
+
for checkpoint in checkpoints.list():
|
|
71
|
+
print(checkpoint.name, checkpoint.size)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Reading and listing do not open a writer. `load()` and `load("latest")` return
|
|
75
|
+
the latest checkpoint. A missing checkpoint returns `None`.
|
|
76
|
+
|
|
77
|
+
`checkpoint.files` maps names to files with `name` and `size`. Checkpoints also
|
|
78
|
+
expose `path`, `name`, `committed`, `size`, `meta`, `source`, `location`, and
|
|
79
|
+
`transfer`. Commit times are timezone-aware `datetime` values. `location` and
|
|
80
|
+
`transfer` are `None` for local directories and raw buckets.
|
|
81
|
+
|
|
82
|
+
`read()` returns bytes. Ranges use Python's exclusive `stop` convention. Large
|
|
83
|
+
reads use the core's parallel range reader. `download()` transfers files in
|
|
84
|
+
bounded windows and returns a `Path`. It stages downloads beside the target and
|
|
85
|
+
replaces files after successful transfer. A checkpoint download stages all files
|
|
86
|
+
before moving them into the destination, one file at a time. Other files in the
|
|
87
|
+
destination remain in place. It downloads the checkpoint's data files; it does
|
|
88
|
+
not create a checkpoint catalog at the destination.
|
|
89
|
+
|
|
90
|
+
## Fork a run
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
source = checkpoints.load(step_name(600))
|
|
94
|
+
if source is not None:
|
|
95
|
+
fork = Checkpoints("o41://experiments/run-2").fork(source)
|
|
96
|
+
assert fork.resumed is not None
|
|
97
|
+
fork.resumed.download("./fork-source")
|
|
98
|
+
fork.save(step_name(700), {"state.json": b'{"step": 700}'})
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`fork()` requires an empty destination. It accepts a `Checkpoint` or a concrete
|
|
102
|
+
checkpoint path, such as `o41://experiments/run-1/step-00000600`. Load the
|
|
103
|
+
latest checkpoint first to fork it. The source stays in its existing location.
|
|
104
|
+
The first save records `checkpoint.source`; subsequent saves do not.
|
|
105
|
+
|
|
106
|
+
## Choose storage
|
|
107
|
+
|
|
108
|
+
The same API supports these locations:
|
|
109
|
+
|
|
110
|
+
| Location | Storage | Writer fencing |
|
|
111
|
+
| --------------------------------- | --------------------------------------- | -------------- |
|
|
112
|
+
| `./checkpoints/run-1` or a `Path` | Local directory | No |
|
|
113
|
+
| `s3://bucket/run-1` | S3-compatible bucket | No |
|
|
114
|
+
| `gs://bucket/run-1` | Google Cloud Storage | No |
|
|
115
|
+
| `az://account/container/run-1` | Azure Blob Storage | No |
|
|
116
|
+
| `o41://experiments/run-1` | 041 Artifacts placement and signed URLs | Yes |
|
|
117
|
+
|
|
118
|
+
Local directories need no credentials. Raw buckets use the Rust `object_store`
|
|
119
|
+
credential configuration. Pass overrides through
|
|
120
|
+
`store_options={"aws_region": "us-east-1"}`, using `object_store` option names.
|
|
121
|
+
|
|
122
|
+
For `o41://`, set `O41_ARTIFACTS_API_KEY` to an organization API key.
|
|
123
|
+
`O41_ARTIFACTS_URL` overrides `https://artifacts.041.io`. `O41_ARTIFACTS_CLOUD`
|
|
124
|
+
and `O41_ARTIFACTS_REGION` override placement together. Otherwise the core
|
|
125
|
+
detects placement through SkyPilot or VM metadata and uses the organization's
|
|
126
|
+
fallback when unknown.
|
|
127
|
+
|
|
128
|
+
`Checkpoints(location, api_key=..., url=..., organization=..., cloud=..., region=..., retry_for=..., store_options=...)`
|
|
129
|
+
overrides the core's environment configuration. `retry_for` is a duration in
|
|
130
|
+
seconds. Omitted options use the Rust defaults, including its retry rules and
|
|
131
|
+
longer begin/commit deadlines.
|
|
132
|
+
|
|
133
|
+
## Notes and failures
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
checkpoints.write_note("evaluated.json", b'{"step": 600}')
|
|
137
|
+
note = checkpoints.note("evaluated.json") # bytes, or None when absent
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Notes hold up to 64 KiB beside the checkpoints and do not require a writer. A
|
|
141
|
+
checkpoint holds 1 to 1000 files and up to 16 KiB of JSON metadata. File names
|
|
142
|
+
cannot contain directories.
|
|
143
|
+
|
|
144
|
+
`CheckpointError` reports failures from the Rust engine. `NotEmpty` and
|
|
145
|
+
`Superseded` derive from it. On `o41://`, another writer opening the artifact
|
|
146
|
+
fences the old writer. Catch `Superseded` to stop that run. Exceptions expose
|
|
147
|
+
`code`, `status`, `epoch`, and `location` when the core supplies them. Python
|
|
148
|
+
argument conversion errors use `TypeError` or `ValueError`, and local staging
|
|
149
|
+
failures can raise `OSError`.
|
|
150
|
+
|
|
151
|
+
Handles retain the Rust runtime for as long as they are referenced. Create them
|
|
152
|
+
inside each worker process rather than sharing them across a process fork.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/target/
|