Skip to content

fix: convert_olmoe_merged.py no longer needs the whole checkpoint in RAM#543

Merged
JustVugg merged 1 commit into
JustVugg:devfrom
opxyc:feat/olmoe-safe-converter
Jul 25, 2026
Merged

fix: convert_olmoe_merged.py no longer needs the whole checkpoint in RAM#543
JustVugg merged 1 commit into
JustVugg:devfrom
opxyc:feat/olmoe-safe-converter

Conversation

@opxyc

@opxyc opxyc commented Jul 23, 2026

Copy link
Copy Markdown

Summary

convert_olmoe_merged.py --repo called snapshot_download (pulls the whole checkpoint to disk first) then loaded every shard fully into RAM via load_file before processing. For OLMoE-1B-7B's ~14GB bf16 checkpoint that's a real problem on a RAM-constrained machine — hit directly on a 21GB-RAM box already running other things. Rewrites both --model and --repo paths to be lazy (safetensors.safe_open, on-demand reads) and, for --repo, to download/process/delete one source shard at a time — peak extra disk is one shard, not the full checkpoint. Also resumable: existing output tensors are detected (header-only scan) and skipped on a rerun. Same CLI and output format as before; no behavior change for anyone already using it successfully, only less RAM/disk needed while doing so.

Validation

  • make -C c check — same disk-quota caveat as the sibling PRs (pre-existing, unrelated test, not caused by this change); everything else passes.
  • CUDA changes were tested with make -C c cuda-test (if applicable) — N/A.
  • Performance claims include hardware, commands, and repeatable measurements — no throughput claim; this changes RAM/disk footprint, not speed. Verified end-to-end: converted allenai/OLMoE-1B-7B-0125-Instruct on a 21GB-RAM machine (not previously possible with the eager-load version), all 1024 experts (16 layers × 64) present and complete, olmoe.c loads and runs correctly against the result.

Compatibility

  • The default CPU build remains dependency-free
  • No model files, generated binaries, or benchmark artifacts are included

The old --repo path called snapshot_download (pulls the whole checkpoint
to local disk first) then loaded every shard fully into RAM via load_file
before processing -- for OLMoE-1B-7B's ~14GB bf16 checkpoint, that's a
real problem on a RAM-constrained machine (this was hit directly: 21GB
total RAM, most already in use by other processes).

Rewrites both paths to be lazy:
- --model (local dir): opens shards with safetensors.safe_open and reads
  tensors on demand instead of safetensors.torch.load_file's eager
  full-shard load.
- --repo: downloads and processes ONE source shard at a time via
  hf_hub_download, deleting it immediately after extraction -- peak extra
  disk usage is one shard, not the full checkpoint. An expert's three
  projections can land in different shards; incomplete triples are held
  in a small in-RAM dict until their last projection arrives, then merged,
  quantized, and flushed.
- Resumable: existing output shards are scanned (header-only, via
  safe_open) and already-converted tensors are skipped on a rerun, so an
  interrupted conversion picks up where it left off instead of restarting.

Same output format and CLI as before (--repo/--model/--out), no behavior
change for anyone already using it successfully -- this only changes how
much RAM/disk it needs while doing so. Verified end-to-end: converted
allenai/OLMoE-1B-7B-0125-Instruct on a 21GB-RAM machine (previously not
attempted with the old eager-load version), all 1024 experts (16 layers x
64) present and complete, olmoe.c loads and runs correctly against the
result.
@opxyc opxyc changed the title tools: make convert_olmoe_merged.py disk/RAM-safe (streaming, resumable) fix: convert_olmoe_merged.py no longer needs the whole checkpoint in RAM Jul 23, 2026
@JustVugg JustVugg mentioned this pull request Jul 23, 2026
5 tasks
@JustVugg
JustVugg merged commit cd6a342 into JustVugg:dev Jul 25, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants