Repository navigation
Commit 059bf5f
Stream sharded safetensors export + resumable full-checkpoint preflight (#576)
## Motivation
Exporting an official full-size sharded checkpoint (e.g.
`zai-org/GLM-5.2` — 753.3B params BF16, **1.507 TB across 282 shards**)
with the current eager loader concatenates every shard into one in-RAM
`state_dict`. Measured peak host RAM for that path is ~1.5–1.9 TB, which
**exceeds available RAM on a 1.7 TB box and OOMs**. There is also no way
to know the disk/RAM/VRAM budget before committing to a hundreds-of-GB
download.
This lands the generic, model-agnostic code to (a) stream a sharded
checkpoint to ONNX external data with a bounded working set, and (b)
refuse a download up front when the budget is insufficient. No
model-name allowlist.
## What
- **`stream_safetensors_to_model()`**
(`integrations/_weight_loading.py`): a pass-through lazy per-tensor
loader. Each ONNX initializer is bound to an `ir.LazyTensor` that reads
its tensor from the owning safetensors shard on demand (`safe_open`
reads headers only), so peak RAM is bounded to one tensor, not the whole
checkpoint. It **refuses** rather than mis-exporting when the source is
quantized (fp8 / `*_scale_inv`) or when a graph initializer has no
matching checkpoint tensor (needs fusion/split/quantization) — those
must use the eager `apply_weights` path.
- **`external_data_checksums()`**: deterministic sha256+size manifest
for verifying byte-reproducible re-exports.
- **`preflight.py` + `mobius preflight` CLI**: a resumable dry-run that
validates all shard URLs/metadata from the Hub or a local dir (no
success-shaped fallback), computes exact source/output disk, peak host
RAM (eager vs stream) and weights VRAM (sized from the export artifact),
sums download+output on a shared filesystem, checks free disk/RAM, and
**refuses (exit 2)** before download when budget is insufficient, RAM
can't be verified, or metadata is unavailable. Resumable JSON state
refuses on commit-identity drift.
The eager `apply_weights` / `_download_weights` path (incl. its pytorch
+ fp8 support) is unchanged.
## Proven behavior (real metadata, no download)
| model | source | int4 output | peak RAM stream / eager | int4 VRAM |
verdict |
|---|---|---|---|---|---|
| GLM-5.2 (int4-qmoe) | 1.507 TB | 0.436 TB | 10.7 GB / 1942.2 GB |
500.8 GB | READY on 8×80 GB agg; REFUSED on single 80 GB |
| DeepSeek-V4 | — | — | — | — | REFUSED (404 RepositoryNotFound — data
blocker) |
## Tests
- `preflight_test.py` (20) + `_weight_loading_stream_test.py` (10):
resolve/budget/refusal/resumability, streaming correctness + laziness,
shape/missing-weight/quantized refusals, deterministic checksums.
- Existing `_weight_loading_test.py` (54) unchanged. **84 pass**,
`CUDA_VISIBLE_DEVICES=""`. ruff clean (line-length 95).
An independent code review was run; all findings (fp8 silent mis-load,
false-READY shared-fs disk double count, fp8 output under-count,
download-fs mismatch, RAM-unverifiable success-shape) are fixed with
tests in the second commit.
> Note: this is the export/preflight plumbing. A real full GLM-5.2 run
additionally requires ~1.94 TB of storage (point `HF_HOME` at a large
volume), a pre-quantized int4 checkpoint (Mobius QMoE needs
pre-quantized weights), and a multi-GPU/offloaded `glm_moe_dsa` runtime.
Co-authored-by: Copilot <[email protected]>
---------
Co-authored-by: Copilot <[email protected]>1 parent 7003bc7 commit 059bf5f
6 files changed
Lines changed: 1670 additions & 1 deletion
File tree
- src/mobius
- integrations
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| 75 | + | |
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
| |||
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
139 | | - | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
711 | 711 | | |
712 | 712 | | |
713 | 713 | | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
714 | 796 | | |
715 | 797 | | |
716 | 798 | | |
| |||
1131 | 1213 | | |
1132 | 1214 | | |
1133 | 1215 | | |
| 1216 | + | |
| 1217 | + | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
| 1243 | + | |
| 1244 | + | |
| 1245 | + | |
| 1246 | + | |
| 1247 | + | |
| 1248 | + | |
| 1249 | + | |
| 1250 | + | |
| 1251 | + | |
| 1252 | + | |
| 1253 | + | |
| 1254 | + | |
| 1255 | + | |
| 1256 | + | |
| 1257 | + | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
| 1262 | + | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
| 1267 | + | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
1134 | 1300 | | |
1135 | 1301 | | |
1136 | 1302 | | |
| |||
0 commit comments