Skip to content

fix: share server checkpoint workflows and preserve saved weights - #300

Merged
Yunnglin merged 11 commits into
mainfrom
fix/issue-298-runtime-checkpoints
Oct 12, 2026
Merged

Yunnglin merged 11 commits into
mainfrom
fix/issue-298-runtime-checkpoints

Conversation

@Yunnglin

@Yunnglin Yunnglin commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Named sampler saves previously replaced a single latest directory, so saving y could invalidate x, failed saves could destroy the previous weights, and overwriting a name could reuse stale sampler cache entries. Twinkle training saves also recorded a checkpoint before the backend succeeded.

Both Tinker and Twinkle handlers now share the existing checkpoint manager's training and sampler save workflows. Training metadata is recorded after a successful backend save. Sampler saves stage complete weights, publish a new physical version behind the stable URI, roll back publication failures, and preserve named checkpoints while retaining latest-only unnamed saves. Serialization reuses the project's FileLock helpers. Load, resume and upload reuse path resolution while keeping their backend argument shapes, optimizer options and protocol responses.

The latest refactor flattens three path-resolution branches and clarifies storage ownership and commit boundaries, reducing the two shared manager files by 50 lines. Scope remains server code and server tests; there are no model, processor, vLLM, utility, dependency or user-documentation changes.

The latest test cleanup removes unused mock configuration and duplicate handler lifecycle checks. Tinker sampling tests now call the real manager and read materialized files, adapter mapping uses the real production method/property, and lock-wait cancellation observes actual contention. The shared filesystem failure matrix runs once, with both protocols retained for metadata/path compatibility. This cleanup changes only tests and reduces their total length by 23 lines.

Validation:

  • 178 local tests passed, with no failures or skips, covering both protocol handlers, real filesystem transactions, cancellation, overwrite, cross-protocol reads/deletes, gateway and protocol/static contracts. Redundant parameter combinations were removed; distinct failure stages remain covered.
  • 8 process-local negative controls were all detected: ignoring names, bypassing serialization or rollback, caching the public path, publishing training metadata before backend success, returning a URI without saving, incorrect full-mode adapter mapping, and accepting the reserved name.
  • Earlier path refactoring matched 132 comparisons against b2ee88d9; executable AST outside those three methods was unchanged.
  • All-file pre-commit and git diff --check passed.
  • Earlier isolated Linux validation passed 100 tests at b2ee88d9. Real PPU evidence belongs to a958ca42 (1 training/sampling E2E and 17 NAS failure tests); it is historical evidence, not a current-head device rerun.

Training backend file writes retain their existing behavior; this does not add training overwrite rollback, crash recovery or in-flight sampler snapshot isolation. GPU/PPU optimizer recovery and actual Hub network operations were not rerun for this refactor.

Refs #298

Copilot AI balanced review requested due to automatic review settings October 10, 2026 08:16

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.

🟡 Changes recommended

Sampler deletion is not coordinated with the new save lock and can invalidate a successfully published checkpoint.

1 open finding
What changed in this PR

Addresses issue #298 by enabling safe-mode Transformers training, improving isolated Ray deployments, and retaining versioned sampler checkpoints.

Changes:

  • Adds local processor execution and loopback-safe Ray initialization.
  • Implements transactional named/unnamed sampler checkpoints and revision-aware vLLM reloads.
  • Moves locks outside the working directory and expands regression coverage/documentation.
File Description
tests/​utils/​test_isolated_runtime.py Tests isolated networking and locking.
tests/​server/​utils/​test_sampler_checkpoints.py Tests checkpoint transactions and rollback.
tests/​server/​model/​test_twinkle_async_inputs.py Tests Twinkle sampler saves.
tests/​server/​model/​test_tinker_handlers.py Updates Tinker save-handler tests.
tests/​server/​integration/​test_safe_mode_checkpoints_e2e.py Adds safe-mode checkpoint E2E coverage.
tests/​sampler/​test_vllm_lora_loading.py Tests revision-based LoRA reloads.
tests/​model/​test_safe_mode.py Tests local processor execution in safe mode.
src/​twinkle/​utils/​parallel.py Makes lock storage lazy and configurable.
src/​twinkle/​utils/​network.py Adds loopback IP fallback.
src/​twinkle/​server/​model/​twinkle_handlers.py Uses transactional sampler saves.
src/​twinkle/​server/​model/​tinker_handlers.py Shares transactional sampler saves.
src/​twinkle/​server/​launcher/​env_propagation.py Propagates the lock-directory setting.
src/​twinkle/​server/​checkpoint/​training_run_manager.py Writes run metadata atomically.
src/​twinkle/​server/​checkpoint/​tinker.py Hides internal revision metadata.
src/​twinkle/​server/​checkpoint/​checkpoint_manager.py Implements durable named sampler checkpoints.
src/​twinkle/​sampler/​vllm_sampler/​vllm_engine.py Reloads changed cached LoRA weights.
src/​twinkle/​protocol/​types/​model.py Updates sampler-save semantics.
src/​twinkle/​processor/​base.py Adds worker-local processor dispatch.
src/​twinkle/​model/​transformers/​transformers.py Uses local processor execution.
src/​twinkle/​infra/​_ray/​ray_helper.py Validates Ray master addresses.
src/​twinkle/​infra/​__init__.py Supports scoped local remote-function calls.
pyproject.toml Adds the server file-lock dependency.
docs/​source_zh/​使用指引/​服务端和客户端/​服务端.md Documents isolated deployment behavior.
docs/​source_zh/​使用指引/​服务端和客户端/​Tinker兼容客户端.md Documents checkpoint lifetimes.
docs/​source_en/​Usage Guide/​Server and Client/​Tinker-Compatible-Client.md Documents checkpoint lifetimes.
docs/​source_en/​Usage Guide/​Server and Client/​Server.md Documents isolated deployment behavior.

🧠 Review effort: Balanced


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

@Yunnglin Yunnglin changed the title fix: support safe-mode training and durable sampler checkpoints fix: retain named sampler checkpoints in server Oct 10, 2026
@Yunnglin Yunnglin changed the title fix: retain named sampler checkpoints in server fix: share server checkpoint workflows and preserve saved weights Oct 11, 2026
@Yunnglin
Yunnglin merged commit ec8fd1f into main Oct 12, 2026
3 of 4 checks passed
loveleaves pushed a commit to loveleaves/twinkle that referenced this pull request Oct 26, 2026
…delscope#300)

* fix: keep worker-owned models off the safe-mode remote call path

* fix: support loopback deployments and read-only working directories

* fix: retain named sampler checkpoints and reload overwritten LoRA weights

* fix: preserve processor hooks and checkpoint metadata on failures

* test: consolidate checkpoint failure coverage

* docs: revert documentation updates from issue 298 fixes

* fix: scope sampler checkpoint repair to server storage

* refactor: clarify sampler checkpoint save lifecycle

* refactor: share checkpoint workflows across server protocols

* refactor: simplify checkpoint path flows and contracts

* test: focus checkpoint regressions on real storage behavior
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