Skip to content

Key the DCP conversion cache on the checkpoint, not its iteration name - #23

Merged
YuxiLiu-921 merged 1 commit into
AlibabaResearch:mainfrom
hiroki-abe-58:fix-dcp-cache-key
Oct 26, 2026
Merged

YuxiLiu-921 merged 1 commit into
AlibabaResearch:mainfrom
hiroki-abe-58:fix-dcp-cache-key

Conversation

@hiroki-abe-58

Copy link
Copy Markdown
Contributor

Fixes #22.

resolve_ckpt_root cached a converted DCP checkpoint as assets/_ckpts/<iter>_ema.pt. As the issue shows, run_A/iter_000000001/model and run_B/iter_000000001/model therefore shared one file, and the second request got the first run's weights. The same happened when a checkpoint was rewritten in place.

Change (scripts/inference/_resolve_ckpt.sh only)

  • The cache name now carries a key: assets/_ckpts/<iter>_<key>_ema.pt. The key is the first 16 hex digits of a SHA-256 over the shard directory's real path and its file names, sizes and mtimes.

    • Different runs get different files.
    • A repeat request for an unchanged checkpoint still reuses its file (using cached ... (from <dir>)).
    • A rewritten checkpoint is converted again.
  • dcp_to_pth.py writes to <file>.tmp.<pid>, which is renamed when the conversion finishes. An interrupted conversion therefore never leaves a file that a later run would take as cached.

  • Iteration directories now convert. _rc_is_dcp_dir accepts a directory whose shards are under model/, but the converter was given that parent directory and failed:

    AssertionError: metadata is None; global metadata read failed: [Errno 2] No such file or directory: '.../run_A/iter_000000001/.metadata'
    

    It now gets the directory that holds the shards. That directory also feeds the key, so .../iter_N and .../iter_N/model share one cached file.

Check

The check uses tiny real DCP checkpoints, written with torch.distributed.checkpoint.save on the CPU. In each one net_ema.w holds a marker:

  • A = 11 and B = 22, both laid out as run_X/iter_000000001/model;
  • C = 33, with its shards directly in iter_000000001.

Each scenario starts from an empty working directory with a copy of scripts/ (the resolver uses repo-relative paths). It calls resolve_ckpt_root with DIT_PATH=<dcp dir> and valid auxiliary paths, and reads net.w[0] back from the resolved DIT_PATH. Both trees were exported with git archive, with LF line endings.

requests expected 6149ac5 (main) this PR
A, then B 11, 22 11, 11 11, 22
B, then A 22, 11 22, 22 22, 11
B alone 22 22 22
A, then A 11, 11 (second from cache) 11, 11 11, 11 (using cached)
A's iteration dir (run_A/iter_000000001) 11 converter error (.metadata not found) 11 (same cached file as A)
C (flat layout) 33 33 33
one path, A's shards, then B's copied over them 11, 22 11, 11 11, 22

When the same calls run at the top level under set -euo pipefail (as eval_student_*.sh does), the resolver logs three things:

  • A converts once and is then reused;
  • B converts into its own file;
  • the iteration-dir request reuses A's file.

No .tmp file is left behind.

Environment: GNU bash 5.2.37 (Git for Windows), Python 3.12, PyTorch 2.12.0. No GPU or full model was used. The new code uses only the Python interpreter the resolver already calls for dcp_to_pth.py, plus compgen and mv.

Note: caches written before this change keep their old names. They are no longer picked up, and can be deleted from assets/_ckpts/.

🤖 Generated with Claude Code

resolve_ckpt_root cached a converted DCP checkpoint as
assets/_ckpts/<iter>_ema.pt, so run_A/iter_N and run_B/iter_N shared one
file and the second request silently got the first run's weights (AlibabaResearch#22).
A checkpoint rewritten in place also kept its stale conversion.

The cache name now carries a hash of the shard directory's real path and
its file names, sizes and mtimes. The converter writes to a temporary file
that is renamed when it finishes, so an interrupted conversion is never
reused.

An iteration directory whose shards sit under model/ is accepted by
_rc_is_dcp_dir, but the converter was given the iteration directory and
failed to find .metadata; it now gets the directory holding the shards.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@YuxiLiu-921
YuxiLiu-921 merged commit 3fd210c into AlibabaResearch:main Oct 26, 2026
1 check was pending
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.

DCP checkpoint cache can return weights from another training run

3 participants