Skip to content

fix: preserve training state across checkpoints and shared adapters - #315

Merged
Yunnglin merged 4 commits into
mainfrom
fix/training-state-restoration
Oct 15, 2026
Merged

Yunnglin merged 4 commits into
mainfrom
fix/training-state-restoration

Conversation

@Yunnglin

@Yunnglin Yunnglin commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix checkpoint restoration and shared LoRA training in Transformers and Megatron. Independent of PR 312.

  • Load full-model weights and fill missing names only for identical shared parameters. Rebind each tenant's optimizer and select its checkpoint/template context.
  • Refresh Megatron optimizer master weights without clearing Adam state; collect one progress record after all workers finish restoring. Use PretrainedConfig for the configuration import.
  • Call native Megatron LoRA A/B layers to retain TP/SP communication, keeping full weight objects and zeroing inactive channels between the layers.

Validation

  • Current 9e855f03, CPU: 23 focused regressions and 18 additional review checks passed, with no failures/errors/skips. The additional checks cover Ray dispatch with simulated restore workers, tied-weight alias rules, and PEFT tenant optimizer isolation using CPU strategies; they do not exercise device sharding.
  • Current head, PPU: 3 TE/MCore grouped-layer cases passed: tenant ranks 2/4/16, maximum rank 16, three Adam steps each. Output/gradient errors were zero against native grouped layers with inactive weights zeroed; parameter updates, identity and weight contiguity checks passed. Single device, TP=PP=EP=1, SP/FP8 off.
  • Earlier 546d8d14, PPU: 17 scenarios on two ranks produced 34 JUnit passes, covering Native FSDP2 checkpoint continuation, Megatron TP2 with SP off/on, row/column layers, and Accelerate tied-weight loading with a tiny module. These were not rerun on the current head.
  • Recorded CI rerun: lint passed; citest reported 1807 passed, 115 skipped and one documentation-link HTTP 503 failure. NPU CI is queued.

Remaining issue

Full Qwen with Accelerate 1.14.0/FSDP2 still raises KeyError: 0 when exporting Adam state, observed on both the baseline and backend-fix commit.

@Yunnglin
Yunnglin marked this pull request as ready for review October 15, 2026 04:25
Copilot AI balanced review requested due to automatic review settings October 15, 2026 04:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

An unresolved correctness issue and cross-backend distributed-state changes require human review, with hardware CI still cancelled.

1 open finding
What changed in this PR

Repairs checkpoint restoration and shared-adapter training across Transformers and Megatron, independently of #312’s resource lifecycle changes.

Changes:

  • Restore weights, optimizer bindings, and tenant checkpoint context.
  • Preserve native parallel-layer communication and Megatron optimizer master parameters.
  • Add regression coverage and correct configuration imports.
File Description
tests/​transformers/​test_tied_weight_restore.py Tests tied aliases and strict loading.
tests/​transformers/​test_native_fsdp_strategy.py Tests tenant-specific optimizer rebinding.
tests/​transformers/​test_multi_lora_checkpoint_context.py Tests checkpoint tenant activation.
tests/​transformers/​test_megatron_weight_only_resume.py Tests master-parameter refresh.
tests/​transformers/​test_megatron_resume_response.py Tests progress collection and Ray ownership.
tests/​transformers/​test_full_checkpoint_resume.py Tests full-model checkpoint restoration.
tests/​model/​test_multi_lora_tensor_parallel.py Tests parallel outputs and gradients.
src/​twinkle/​model/​transformers/​transformers.py Wraps all optimizers and restores full weights.
src/​twinkle/​model/​transformers/​strategy/​weight_state.py Expands genuine tied-weight aliases.
src/​twinkle/​model/​transformers/​strategy/​sequence_parallel/​__init__.py Supports multiple optimizer returns.
src/​twinkle/​model/​transformers/​strategy/​native_fsdp.py Preserves optimizer bindings and tied aliases.
src/​twinkle/​model/​transformers/​strategy/​accelerate.py Expands aliases before distributed loading.
src/​twinkle/​model/​transformers/​multi_lora_transformers.py Activates checkpoint target tenants.
src/​twinkle/​model/​multi_lora.py Preserves native parallel-layer execution.
src/​twinkle/​model/​megatron/​strategy/​megatron.py Corrects configuration imports and annotations.
src/​twinkle/​model/​megatron/​multi_lora_megatron.py Refreshes target optimizer master parameters.
src/​twinkle/​model/​megatron/​megatron.py Refreshes master parameters and collects resume progress.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/twinkle/model/transformers/transformers.py
Comment thread src/twinkle/model/megatron/megatron.py
Comment thread src/twinkle/model/transformers/strategy/weight_state.py
Comment thread src/twinkle/model/transformers/transformers.py
Comment thread src/twinkle/model/transformers/transformers.py
Comment thread src/twinkle/model/multi_lora.py
@Yunnglin
Yunnglin merged commit 560b2ae into main Oct 15, 2026
2 of 5 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.

3 participants