Skip to content

exporter: fall back to earlier step on broken final checkpoint - #242

Merged
PeterLi-jpg merged 1 commit into
mainfrom
export-step-fallback
May 3, 2026
Merged

PeterLi-jpg merged 1 commit into
mainfrom
export-step-fallback

Conversation

@PeterLi-jpg

Copy link
Copy Markdown
Owner

tunix PeftTrainer can leave the newest orbax checkpoint structurally invalid if the trainer exits right after save_checkpoint() is queued at end-of-training. seed7/99/101 hit this on step 300; step 250 loads fine.

Iterates checkpoint candidates newest-first; on FileNotFoundError falls back to next-highest. Prevents the same export failure for fresh training runs (seed13/42).

tunix PeftTrainer can leave the highest-numbered orbax checkpoint
with an incomplete manifest if the trainer exits right after save_checkpoint
is queued at end-of-training. Earlier saves taken DURING training are
structurally complete since they had time to flush.

On FileNotFoundError loading the newest step, fall back to next-highest
and retry. seed7/99/101 step 300 saw exactly this; step 250 is fine.
@PeterLi-jpg
PeterLi-jpg merged commit 9bd7522 into main May 3, 2026
2 checks passed
PeterLi-jpg added a commit that referenced this pull request May 3, 2026
tunix PeftTrainer saves composite checkpoints with model_params/ and
optimizer_state/ as siblings under each step dir. PyTreeCheckpointer.restore
needs the inner pytree dir (model_params), not the composite root. Passing
the composite root produces "No structure could be identified" because
manifest.ocdbt lives inside model_params/, not at the top level.

Fix: probe for model_params/ subdir; restore from it if present, else
fall back to the leaf (legacy flat layout). Combined with PR #242 step
fallback, this fixes Stage 3-export for seed7/13/42/99/101.
PeterLi-jpg added a commit that referenced this pull request May 3, 2026
)

tunix PeftTrainer saves composite checkpoints with model_params/ and
optimizer_state/ as siblings under each step dir. PyTreeCheckpointer.restore
needs the inner pytree dir (model_params), not the composite root. Passing
the composite root produces "No structure could be identified" because
manifest.ocdbt lives inside model_params/, not at the top level.

Fix: probe for model_params/ subdir; restore from it if present, else
fall back to the leaf (legacy flat layout). Combined with PR #242 step
fallback, this fixes Stage 3-export for seed7/13/42/99/101.
PeterLi-jpg added a commit that referenced this pull request May 3, 2026
* exporter: load model_params subdir for composite orbax checkpoints

tunix PeftTrainer saves composite checkpoints with model_params/ and
optimizer_state/ as siblings under each step dir. PyTreeCheckpointer.restore
needs the inner pytree dir (model_params), not the composite root. Passing
the composite root produces "No structure could be identified" because
manifest.ocdbt lives inside model_params/, not at the top level.

Fix: probe for model_params/ subdir; restore from it if present, else
fall back to the leaf (legacy flat layout). Combined with PR #242 step
fallback, this fixes Stage 3-export for seed7/13/42/99/101.

* exporter: handle bare "layers" + digit segment layout

tunix orbax save writes the layer index as a SEPARATE path segment after
a bare "layers" key:
    ("layers", "0", "attn", "q_einsum", "w_lora_a", "value")
The previous _LAYER_RE only matched compound segments like "layer_0" or
"layer.0", so it never recognized the tunix layout and the export raised
"no qwix LoRA leaves found".

Verified locally on seed42 production checkpoint: 248 LoRA leaves at
layers/<i>/attn/{q,kv}_einsum/w_lora_{a,b}/value paths.
PeterLi-jpg added a commit that referenced this pull request May 4, 2026
tunix PeftTrainer can leave the highest-numbered orbax checkpoint
with an incomplete manifest if the trainer exits right after save_checkpoint
is queued at end-of-training. Earlier saves taken DURING training are
structurally complete since they had time to flush.

On FileNotFoundError loading the newest step, fall back to next-highest
and retry. seed7/99/101 step 300 saw exactly this; step 250 is fine.
PeterLi-jpg added a commit that referenced this pull request May 4, 2026
)

tunix PeftTrainer saves composite checkpoints with model_params/ and
optimizer_state/ as siblings under each step dir. PyTreeCheckpointer.restore
needs the inner pytree dir (model_params), not the composite root. Passing
the composite root produces "No structure could be identified" because
manifest.ocdbt lives inside model_params/, not at the top level.

Fix: probe for model_params/ subdir; restore from it if present, else
fall back to the leaf (legacy flat layout). Combined with PR #242 step
fallback, this fixes Stage 3-export for seed7/13/42/99/101.
PeterLi-jpg added a commit that referenced this pull request May 4, 2026
* exporter: load model_params subdir for composite orbax checkpoints

tunix PeftTrainer saves composite checkpoints with model_params/ and
optimizer_state/ as siblings under each step dir. PyTreeCheckpointer.restore
needs the inner pytree dir (model_params), not the composite root. Passing
the composite root produces "No structure could be identified" because
manifest.ocdbt lives inside model_params/, not at the top level.

Fix: probe for model_params/ subdir; restore from it if present, else
fall back to the leaf (legacy flat layout). Combined with PR #242 step
fallback, this fixes Stage 3-export for seed7/13/42/99/101.

* exporter: handle bare "layers" + digit segment layout

tunix orbax save writes the layer index as a SEPARATE path segment after
a bare "layers" key:
    ("layers", "0", "attn", "q_einsum", "w_lora_a", "value")
The previous _LAYER_RE only matched compound segments like "layer_0" or
"layer.0", so it never recognized the tunix layout and the export raised
"no qwix LoRA leaves found".

Verified locally on seed42 production checkpoint: 248 LoRA leaves at
layers/<i>/attn/{q,kv}_einsum/w_lora_{a,b}/value paths.
PeterLi-jpg added a commit that referenced this pull request May 4, 2026
orbax CheckpointManager.save() is async, so the last-step save can still
be in flight when the trainer process exits. The result is a final
checkpoint dir (e.g. orbax/300/) with data files but no manifest, which
downstream loaders reject with 'No structure could be identified for the
checkpoint at .../orbax/300'. Witnessed on seed7/seed99/seed101 step-300
ckpts; the exporter step-fallback (PR #242) is a workaround, this is the
fix.

Reach through tunix's CheckpointManager wrapper to the underlying orbax
manager and call wait_until_finished() after trainer.train() returns.
Wrapped in try/except so a missing manager (eval-only paths) does not
crash the script.
PeterLi-jpg added a commit that referenced this pull request May 4, 2026
…o-delete (#248)

bundle of 5 fixes for tpu/launch_5seeds_tunix.sh hit during tonight's
pipeline run:

a) repo-clone check now tests ~/bohdi-lora/.git, not just the dir, so a
   pre-populated ~/bohdi-lora/checkpoints/... no longer skips clone and
   trips the next git fetch. aborts loudly if the dir exists without
   .git/ instead of silently clobbering.
b) shell-side watchdog around each eval invocation. kills the eval with
   rc=124 after VLLM_WAIT_TIMEOUT (default 600s) without a Running
   vllm-tpu container, or rc=1 the moment a container is observed
   exited (logs ExitCode). overrides the killed-process signal exit so
   eval_fail_count tracking sees the right rc.
c) cleanup_eval restarts the tpu-runtime container so chip state is
   reset between Stage-4 configs. previously the next config's vllm
   inherited dirty device state and failed to init.
d) Stage 3 train invocation now skips when checkpoints/seed_<N>/orbax/
   250/_CHECKPOINT_METADATA exists locally (resumed from GCS). step
   250 is the last reliably-complete save (300 is invalid per #242).
e) cleanup() trap's delete_vm gated behind LAUNCHER_DELETE_VM_ON_EXIT,
   default off. successful runs no longer auto-destroy spot slots that
   we cannot get back due to TRC capacity contention. PREEMPTED retry
   path keeps deleting because preempted is terminal.
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.

1 participant