Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
8773090
[ops, dist] fix: compute NPU expert weight gradients in FP32
YLlllllllllll Oct 29, 2026
3d94278
[ops, dist] simplify NPU expert precision validation
YLlllllllllll Oct 29, 2026
0cb2364
[dist, optim] feat: selective expert CPU offload with resident modules
YLlllllllllll Oct 29, 2026
ebbb513
[ckpt, tests] fix: preserve CPU expert checkpoint storage
YLlllllllllll Oct 29, 2026
204465c
[ckpt] fix: match full optimizer parameter namespaces
YLlllllllllll Oct 30, 2026
166c1c9
[ops] merge: align FP32 expert gradients with instance config
YLlllllllllll Oct 30, 2026
0e0e57c
[test] use complete mixed precision fixtures
YLlllllllllll Oct 30, 2026
01d29bf
[dist] fix: use CPU for default Gloo process groups
YLlllllllllll Oct 30, 2026
b334b0f
[test] cover native default process groups
YLlllllllllll Oct 30, 2026
b1bcb87
[optim] preserve sparse optimizer parameter group state
YLlllllllllll Oct 31, 2026
e9f451f
[test, optim] cover sparse groups with FSDP2 DCP
YLlllllllllll Oct 31, 2026
93c9ab5
[checkpoint] version canonical extra-parallel model layout
YLlllllllllll Oct 31, 2026
6f0e5fd
[checkpoint] merge sparse optimizer state dependency
YLlllllllllll Nov 1, 2026
adf1951
[checkpoint] prove multi-optimizer resume identity
YLlllllllllll Oct 31, 2026
b47d315
[checkpoint] coordinate strict load preflight failures
YLlllllllllll Nov 1, 2026
c36b855
[checkpoint] publish optimizer receipt after barrier
YLlllllllllll Nov 1, 2026
54e0f32
[checkpoint] invalidate file state on load barrier failure
YLlllllllllll Nov 1, 2026
f7831f6
[ci] declare CPU plans for rank-local checkpoint tests
YLlllllllllll Nov 1, 2026
3697deb
[checkpoint] reject unsafe asynchronous multi-optimizer saves early
YLlllllllllll Nov 1, 2026
139299c
[ci] allow CUDA fixture in process-group test
YLlllllllllll Nov 1, 2026
784217d
Merge commit '139299ca0bd093bf4a3d9761d42e0673a90c4980' into HEAD
YLlllllllllll Nov 1, 2026
3f1a114
[checkpoint] preserve positional configuration compatibility
YLlllllllllll Nov 1, 2026
29797c9
[checkpoint] reject nonboolean canonical layout policy
YLlllllllllll Nov 2, 2026
1b81246
[test] schedule sparse optimizer state regressions
YLlllllllllll Nov 2, 2026
ce5fecd
[checkpoint] avoid redundant layout agreement gathers
YLlllllllllll Nov 2, 2026
6a86a20
[checkpoint] sync reviewed layout and optimizer test prerequisites
YLlllllllllll Nov 2, 2026
81fd202
[checkpoint] integrate upstream expert layout provenance
YLlllllllllll Nov 2, 2026
47d438c
[integration] preserve NPU expert precision with FP8 config
YLlllllllllll Nov 2, 2026
5c4fab0
Merge upstream FP8 expert layout with CPU offload
YLlllllllllll Nov 2, 2026
c61c733
[checkpoint] remove unsupported divergent-layout test
YLlllllllllll Nov 2, 2026
17f5903
[docs] fix SeedOmni runtime source anchors
YLlllllllllll Nov 2, 2026
8884950
[checkpoint] verify legacy expert provenance across targets
YLlllllllllll Nov 2, 2026
79309ef
Refresh remaining SeedOmni documentation links
YLlllllllllll Nov 2, 2026
a2ca5eb
Fix AnyPrecision checkpoint state dtype and ownership
YLlllllllllll Nov 2, 2026
dcc195d
Correct remaining SeedOmni documentation anchors
YLlllllllllll Nov 2, 2026
5b11c02
Test asymmetric EP expert checkpoint recovery
YLlllllllllll Nov 2, 2026
924e8ec
Reject mismatched trainer and optimizer checkpoints
YLlllllllllll Nov 2, 2026
c25cf3f
Document rank-local adapter and support nested Omni hooks
YLlllllllllll Nov 2, 2026
13745a3
Ignore transient-only cache aliases in checkpoint identity
YLlllllllllll Nov 2, 2026
a38c191
Reject unproven dynamic RoPE checkpoint recovery
YLlllllllllll Nov 2, 2026
6669054
Apply canonical checkpoint layout to Omni modules
YLlllllllllll Nov 2, 2026
4ed0d45
Keep expert cold resume coverage on production checkpoint path
YLlllllllllll Nov 2, 2026
01f6728
Merge main and preserve checkpoint layout precision
YLlllllllllll Nov 2, 2026
2b7cdcd
Simplify checkpoint guards under trusted runtime contract
YLlllllllllll Nov 2, 2026
d9232af
Preserve lazy state under PyTorch DCP optimizer wrappers
YLlllllllllll Nov 2, 2026
9438e7a
Migrate optimizer CI fixtures to proven DCP recovery
YLlllllllllll Nov 2, 2026
c4050a0
[checkpoint] docs: classify multi-optimizer resume changes
YLlllllllllll Nov 2, 2026
4e40d31
[checkpoint] fix: declare scheduler for proven resume
YLlllllllllll Nov 2, 2026
09a428a
[checkpoint] fix: validate legacy expert sources
YLlllllllllll Nov 2, 2026
02f0753
[checkpoint] fix: keep export options keyword-only
YLlllllllllll Nov 2, 2026
f73d416
[checkpoint] allow trusted scheduler instrumentation
YLlllllllllll Nov 2, 2026
478ae4c
[checkpoint] prove EP1 source and simplify layout validation
YLlllllllllll Nov 3, 2026
830d625
[checkpoint] remove redundant leaf consensus checks
YLlllllllllll Nov 3, 2026
2ae3848
[checkpoint] reuse proven MultiOptimizer export save
YLlllllllllll Nov 3, 2026
462cdac
[test] preserve same-config RoPE failure coverage
YLlllllllllll Nov 3, 2026
d18fd11
Reuse same-step exports across module checkpoint owners
YLlllllllllll Nov 3, 2026
c917429
Reuse completed exports across empty epochs
YLlllllllllll Nov 3, 2026
228c0af
Declare expert-only fixture without GDN layers
YLlllllllllll Nov 3, 2026
a267fae
Preserve proven checkpoint transactions after cold resume
YLlllllllllll Nov 3, 2026
20219eb
Fail closed on checkpoint destination lookup errors
YLlllllllllll Nov 3, 2026
f3b4328
[checkpoint] remove unsupported rank-dependent fixture
YLlllllllllll Nov 3, 2026
8a4fbf0
[checkpoint] prove custom expert layouts and safe exports
YLlllllllllll Nov 3, 2026
32871dd
[checkpoint] guard sparse and legacy extra-parallel states
YLlllllllllll Nov 3, 2026
ff5108b
[checkpoint] combine expert provenance with rank-local recovery
YLlllllllllll Nov 3, 2026
9d1341d
[checkpoint] synchronize extra-parallel provenance guards
YLlllllllllll Nov 3, 2026
9385940
[checkpoint] remove counterfeit adapter fixture
YLlllllllllll Nov 3, 2026
7d7d86d
[checkpoint] use consistent replica values in test
YLlllllllllll Nov 3, 2026
b482339
Merge commit '7d7d86db1861a38ea91d1c46f2cb3c77bc5bd722' into HEAD
YLlllllllllll Nov 3, 2026
dbef082
[test] declare absent scheduler in expert cold test
YLlllllllllll Nov 3, 2026
3745392
[checkpoint] keep configuration preflight local
YLlllllllllll Nov 3, 2026
b4bc8a1
[docs] link optimizer adapter consumers and tests
YLlllllllllll Nov 3, 2026
81c8bbe
[docs] link optimizer adapter context call sites
YLlllllllllll Nov 4, 2026
50c60ff
[checkpoint] defer dynamic RoPE checks to save and load
YLlllllllllll Nov 4, 2026
98836e0
[checkpoint] reject unproven TP expert saves early
YLlllllllllll Nov 4, 2026
bf2a37f
[docs] clarify verified checkpoint migration wording
YLlllllllllll Nov 4, 2026
8feba69
[test] cover replicated EP checkpoint preflight
YLlllllllllll Nov 4, 2026
6d5f772
[docs] fix checkpoint manifest field link
YLlllllllllll Nov 4, 2026
a50fdb6
[test] keep TP checkpoint checks within model contract
YLlllllllllll Nov 4, 2026
3eef397
[checkpoint] test: enforce native preflight capacity
YLlllllllllll Nov 4, 2026
366fa23
[checkpoint] prove TP FSDP source layouts
YLlllllllllll Nov 4, 2026
e3e3350
[test] remove preflight guard-only cases
YLlllllllllll Nov 4, 2026
1768cca
[checkpoint] merge TP FSDP provenance guard
YLlllllllllll Nov 4, 2026
3e67bc4
[test] schedule TP provenance on its actual backend
YLlllllllllll Nov 4, 2026
2ba4cf6
[test] derive checkpoint launch plans from geometry
YLlllllllllll Nov 4, 2026
d199b7e
Merge branch 'review-fix-pr1396' of /tmp/veomni-review-20261104/pr139…
YLlllllllllll Nov 4, 2026
6dd9407
[test] fail assigned accelerator group shortages
YLlllllllllll Nov 4, 2026
9be7026
[test] remove accelerator skip meta tests
YLlllllllllll Nov 4, 2026
4800b5e
[test] use CPU plan for expert layout tests
YLlllllllllll Nov 4, 2026
f6a449c
[test] use CPU plan for expert layout tests
YLlllllllllll Nov 4, 2026
845ccfd
[checkpoint, model] fix: preserve safe RoPE reset and dense layouts
YLlllllllllll Nov 4, 2026
0c9002d
[checkpoint] fix: bind dynamic RoPE table bytes on resume
YLlllllllllll Nov 4, 2026
1a96e9b
[checkpoint] reject nonfinite RoPE tables without changing FP8 identity
YLlllllllllll Nov 4, 2026
80f61cf
[checkpoint] limit RoPE finiteness checks to supported types
YLlllllllllll Nov 4, 2026
f1b3e03
[checkpoint] document reserved runtime state keys
YLlllllllllll Nov 4, 2026
e4bdb9e
Merge upstream main and retain both feature paths
YLlllllllllll Nov 5, 2026
d075345
[docs] describe file-backed checkpoint abort hook
YLlllllllllll Nov 5, 2026
be924f2
Merge main and preserve extra-parallel CPU layouts
YLlllllllllll Nov 5, 2026
34aa016
Merge main and guard expert offload checkpoint layouts
YLlllllllllll Nov 5, 2026
8c97fbc
[checkpoint] unify scheduler identity validation
YLlllllllllll Nov 5, 2026
230f18c
[checkpoint] Coordinate EP optimizer type preflight
YLlllllllllll Nov 5, 2026
ed055f7
[checkpoint] Coordinate optimizer type lookup errors
YLlllllllllll Nov 5, 2026
3f7002e
[checkpoint] Coordinate EP preflight and align layouts
YLlllllllllll Nov 5, 2026
cccc1df
[checkpoint] Validate nested scheduler identity
YLlllllllllll Nov 5, 2026
ed21c45
Merge commit 'e6486d3847536d6a5cf72a433040914b69f1957d' into HEAD
YLlllllllllll Nov 5, 2026
6384c62
[checkpoint] fix standalone SwapAdamW recovery guards
YLlllllllllll Nov 5, 2026
82fbfc9
[checkpoint] constrain scheduler identity to trusted runtime
YLlllllllllll Nov 5, 2026
be814f4
[checkpoint] fix: validate versioned expert ownership
YLlllllllllll Nov 5, 2026
37b473e
[checkpoint] simplify extra-parallel optimizer preflight
YLlllllllllll Nov 6, 2026
95d0855
[checkpoint] simplify extra-parallel optimizer preflight
YLlllllllllll Nov 6, 2026
a64fd96
[checkpoint] simplify multi-optimizer leaf coordination
YLlllllllllll Nov 6, 2026
8424b85
[checkpoint] support deterministic scheduler formatting
YLlllllllllll Nov 6, 2026
ec34eef
[docs] refresh checkpoint configuration references
YLlllllllllll Nov 6, 2026
5a5520d
[test] fix SeedOmni offload config fixture
YLlllllllllll Nov 6, 2026
a656e43
[docs] fix checkpoint and offline cache anchors
YLlllllllllll Nov 6, 2026
3d0b28e
[checkpoint] integrate canonical expert provenance
YLlllllllllll Nov 6, 2026
a2708c3
[test] retain historical checkpoint rejection coverage
YLlllllllllll Nov 6, 2026
be8195a
[checkpoint] coordinate optimizer policy preflight
YLlllllllllll Nov 6, 2026
1fefa13
fix: compose expert precision with parallel patch paths
YLlllllllllll Nov 6, 2026
759e6fb
fix: coordinate cursor and optimizer checkpoint recovery
YLlllllllllll Nov 6, 2026
ad278e3
ci: isolate selective expert test entries
YLlllllllllll Nov 6, 2026
ed45ea5
fix: coordinate invalid checkpoint snapshots
YLlllllllllll Nov 6, 2026
9a8f1fe
fix: coordinate fatal optimizer generation failures
YLlllllllllll Nov 6, 2026
6f867fe
docs: clarify optimizer placement resume identity
YLlllllllllll Nov 6, 2026
4392697
fix: compose selective offload guard with optimizer setup
YLlllllllllll Nov 6, 2026
8f1b7d3
test: run selective optimizer guard in existing CI suite
YLlllllllllll Nov 6, 2026
d03c6c3
Merge selective expert CPU offload with FP32 expert gradients
YLlllllllllll Nov 7, 2026
2202497
Merge owner-aware checkpoint with selective expert offload
YLlllllllllll Nov 7, 2026
1b0f552
Clarify selective expert offload resume requirements
YLlllllllllll Nov 7, 2026
fa072c6
Merge offload documentation correction
YLlllllllllll Nov 7, 2026
2f0012d
Synchronize offload documentation dependency
YLlllllllllll Nov 7, 2026
6d520d9
Initialize checkpoint manager config in failure fixture
YLlllllllllll Nov 7, 2026
135f718
[docs] clarify legacy HF export collective
YLlllllllllll Nov 9, 2026
a47732c
[docs] clarify SeedOmni FP32 expert gradient scope
YLlllllllllll Nov 9, 2026
5c2837c
[docs] clarify checkpoint resume and source links
YLlllllllllll Nov 9, 2026
158d83e
[tests] fix: resolve checkpoint export CLI path
YLlllllllllll Nov 9, 2026
c051d9c
[checkpoint] clarify existing save destination
YLlllllllllll Nov 9, 2026
cfafa43
[test] guard invalid prefixed dynamic rope cache
YLlllllllllll Nov 10, 2026
f111b91
[ci, tests] require assigned NPU and fix precision fixture
YLlllllllllll Nov 10, 2026
f222247
[checkpoint] bind model storage views for resume
YLlllllllllll Nov 10, 2026
543ae79
Merge remote-tracking branch 'upstream/main' into HEAD
YLlllllllllll Nov 10, 2026
e63ffa5
Merge remote-tracking branch 'upstream/main' into HEAD
YLlllllllllll Nov 10, 2026
25a42ab
Merge upstream main
YLlllllllllll Nov 11, 2026
14e5e51
Merge upstream main
YLlllllllllll Nov 11, 2026
5926c99
[docs] fix HF export and cursor test anchors
YLlllllllllll Nov 11, 2026
1687b82
[test] exercise checkpoint storage aliases on accelerators
YLlllllllllll Nov 11, 2026
3ab98ca
Merge upstream MoE operator interface
YLlllllllllll Nov 12, 2026
efe34c2
Merge upstream checkpoint layouts and validate EP policy
YLlllllllllll Nov 12, 2026
f05a537
Normalize persistent shard axes in checkpoint preflight
YLlllllllllll Nov 12, 2026
e14b678
Check expert provenance before checkpoint overwrite
YLlllllllllll Nov 12, 2026
d3852e7
Merge split-layout checkpoint and model updates
YLlllllllllll Nov 12, 2026
81ed593
Merge verified checkpoint provenance guards
YLlllllllllll Nov 12, 2026
ca843be
Merge NPU MoE precision interface coverage
YLlllllllllll Nov 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions docs/usage/checkpoint.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,82 @@ To drop legacy resume, delete `veomni/checkpoint/legacy_v0_1_12.py` and the
imports that load it (search for `legacy_v0_1_12`). An old checkpoint then fails
resume instead of falling back.

## Versioned ExtraParallel layout

The EP-outer layout is opt-in through `SpecInfo.checkpoint_layout_v2`; existing
plans remain on their original layout. A plan enabling it must retain the
original `global_shape` and must use FSDP DTensor parameters. Every
non-persistent ExtraParallel shard in a checkpoint must use the canonical
layout: mixing legacy and canonical shards is rejected. The v2 tensor namespace
identifies canonical global values independently of source geometry, so DCP can
reshard a model checkpoint across supported FSDP shard axes. Use
`DistributedCheckpointer` for save and resume: it rejects old/unversioned
layouts before copying model tensors. Migrating a legacy checkpoint requires
verified source layout information. Canonical v2 optimizer save and resume use
the rank-local codec described below. The standard VeOmni HF export strips the
namespace.

Raw `torch.distributed.checkpoint.load(..., planner=DefaultLoadPlanner(allow_partial_load=True))` is not a
supported migration API: it can return success without reading any tensor when
the namespaces differ. Replicated values must already agree across ranks.
## MultiOptimizer recovery identity

Use `DistributedCheckpointer` for training checkpoints containing a
`MultiOptimizer`. The save is synchronous and requires a completed optimizer
step with no pending gradients. Its identity records parameter ownership,
group structure, scheduler recipe and checkpoint generation. Loading rejects an
unversioned checkpoint, a changed optimizer layout, or a model/optimizer/sidecar
from different saves. An old checkpoint whose original group and scheduler
identity cannot be established needs a verified offline migration.

The generic codec supports AdamW, AnyPrecisionAdamW and DistributedMuon
without ExtraParallel when every checkpoint rank has the same logical parameter
inventory and replicated values already agree. For the ExtraParallel candidate,
optimizer state is stored under rank-specific keys and recovery requires the
identical rank-to-mesh mapping. This avoids merging distinct expert-owner steps
and uninitialized states, but increases checkpoint storage for replicated
optimizer shards and does not support elastic resharding. Model replica shards
are checked for bitwise equality before DCP deduplication. The check streams
bounded chunks to CPU and adds work during checkpoint save. Unknown model
or optimizer hooks, asynchronous saves and unsupported layouts fail closed;
callers should validate these constraints before starting a long run. Synchronous
staged saves are supported.
Partially overlapping shards with different geometries are rejected, even when
their shared values agree; exact replicas and disjoint shards remain supported.
Group/state inventory and generation mismatches are rejected before model
copying. If an I/O or optimizer-application error occurs after model copying,
the load fails and clears its receipt but does not roll back in-memory objects;
discard and rebuild that runtime before retrying.
`MultiOptimizer.state_dict()` returns a detached inspection snapshot for
supported leaves, but `load_state_dict()` alone cannot prove group/scheduler
identity and rejects restoration; use the proven DCP path instead.
The codec also rejects tensor learning rates shared between groups and
overlapping storage between distinct model or optimizer tensors. Its byte-range
check is conservative for non-contiguous interleaved views.
Mutable optimizer options must not be shared between groups or optimizer
defaults: ordinary YAML `betas` are normalized to a tuple; custom shared lists,
dictionaries and tensor-valued learning rates require explicitly independent
copies. This avoids changing aliasing semantics on resume.
The model implementation and training program must also be the same trusted
version on save and resume; custom `state_dict`/`load_state_dict` overrides or
other user code can change training semantics outside this identity check.
Do not use raw DCP `OptimizerState` or `MultiOptimizer.load_state_dict` to
resume: they cannot establish scheduler and group provenance. The standalone
`MultiOptimizer.state_dict()` returns a snapshot and copies tensor states on
their current devices, which can temporarily require as much extra device
memory as the optimizer tensors themselves. That raw snapshot supports the
built-in AdamW, AnyPrecisionAdamW and DistributedMuon leaves, as well as
registered adapters, provided they have no unsupported serialization hooks.
It does not prove the identity needed for raw restoration. Use the high-level
`DistributedCheckpointer` for save and restore; its save path avoids this copy.

For the base and DPO policy ExtraParallel runtimes, a versioned checkpoint's rank inventory is
used to temporarily include its previously owned frozen parameters while building
the optimizer. Their frozen flags are restored before the first forward and the
complete source group and scheduler identity is still checked on load. Frozen
parameters can be intentionally unfrozen after recovery. Unproven legacy
checkpoints and changed freeze configurations require verified migration.

## Related pages

- [Checkpoint conversion](checkpoint_conversion.md) — DCP shards → HuggingFace safetensors (`scripts/merge_dcp_to_hf.py`).
Expand Down
52 changes: 24 additions & 28 deletions tests/checkpoints/test_dcp_checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

def _fsdp2_multi_optimizer_worker(rank: int, world_size: int, tmp_path: Path, endpoint):
"""Worker for the FSDP2 MultiOptimizer DCP round-trip test."""
from veomni.checkpoint.dcp_checkpointer import ModelState, OptimizerState
from veomni.checkpoint.dcp_checkpointer import DistributedCheckpointer
from veomni.optim.optimizer import MultiOptimizer
from veomni.utils.device import get_device_type, get_dist_comm_backend, get_torch_device

Expand Down Expand Up @@ -75,25 +75,17 @@ def build_model_and_optimizer():
x = torch.randn(2, 4, device=device)
source_model(x).sum().backward()
source_optimizer.step()
expected = source_optimizer.state_dict()
source_optimizer.zero_grad()
expected = source_optimizer._sparse_state_dict()

checkpoint_dir = tmp_path / "ckpt"
dcp.save(
{"model": ModelState(source_model), "optimizer": OptimizerState(source_model, source_optimizer)},
checkpoint_id=str(checkpoint_dir),
)
DistributedCheckpointer.save(str(checkpoint_dir), {"model": source_model, "optimizer": source_optimizer})
dist.barrier()

target_model, target_optimizer = build_model_and_optimizer()
dcp.load(
{
"model": ModelState(target_model),
"optimizer": OptimizerState(target_model, target_optimizer, load=True),
},
checkpoint_id=str(checkpoint_dir),
)
DistributedCheckpointer.load(str(checkpoint_dir), {"model": target_model, "optimizer": target_optimizer})

actual = target_optimizer.state_dict()
actual = target_optimizer._sparse_state_dict()
assert expected.keys() == actual.keys()
for key in expected:
expected_value = expected[key]
Expand Down Expand Up @@ -164,7 +156,7 @@ class TestMultiOptimizerState:
"""Non-ExtraParallel MultiOptimizer must use its own DCP protocol."""

def test_single_process_dcp_roundtrip(self, tmp_path):
from veomni.checkpoint.dcp_checkpointer import OptimizerState
from veomni.checkpoint.dcp_checkpointer import DistributedCheckpointer
from veomni.optim.optimizer import MultiOptimizer

def build_model_and_optimizer():
Expand All @@ -184,21 +176,20 @@ def build_model_and_optimizer():
for param in source_model.parameters():
param.grad = torch.randn_like(param)
source_optimizer.step()
expected = source_optimizer.state_dict()
source_optimizer.zero_grad()
expected = source_optimizer._sparse_state_dict()
assert any("exp_avg" in key for key in expected)
assert any("step" in key for key in expected)

target_model, target_optimizer = build_model_and_optimizer()
dcp.save(
{"optimizer": OptimizerState(source_model, source_optimizer, parallel_state=parallel_state)},
checkpoint_id=tmp_path,
DistributedCheckpointer.save(
str(tmp_path), {"model": source_model, "optimizer": source_optimizer}, parallel_state=parallel_state
)
dcp.load(
{"optimizer": OptimizerState(target_model, target_optimizer, parallel_state=parallel_state, load=True)},
checkpoint_id=tmp_path,
DistributedCheckpointer.load(
str(tmp_path), {"model": target_model, "optimizer": target_optimizer}, parallel_state=parallel_state
)

actual = target_optimizer.state_dict()
actual = target_optimizer._sparse_state_dict()
assert expected.keys() == actual.keys()
for key, expected_value in expected.items():
actual_value = actual[key]
Expand All @@ -219,7 +210,7 @@ def test_multi_optimizer_sparse_state_excludes_synthetic(self, tmp_path):
from torch.distributed.checkpoint import FileSystemReader
from torch.distributed.checkpoint.metadata import Metadata

from veomni.checkpoint.dcp_checkpointer import OptimizerState
from veomni.checkpoint.dcp_checkpointer import DistributedCheckpointer
from veomni.optim.optimizer import MultiOptimizer

model = nn.Linear(4, 4)
Expand All @@ -234,16 +225,16 @@ def test_multi_optimizer_sparse_state_excludes_synthetic(self, tmp_path):
# Only bias gets a gradient; the adamw_w sub-optimizer remains empty.
model.bias.grad = torch.randn_like(model.bias)
optimizer.step()
optimizer.zero_grad()
assert optimizer.optimizers_dict["adamw_b"].state
assert not optimizer.optimizers_dict["adamw_w"].state

parallel_state = SimpleNamespace(dp_mode="fsdp2")
dcp.save(
{"optimizer": OptimizerState(model, optimizer, parallel_state=parallel_state)},
checkpoint_id=tmp_path,
DistributedCheckpointer.save(
str(tmp_path), {"model": model, "optimizer": optimizer}, parallel_state=parallel_state
)

reader = FileSystemReader(tmp_path)
reader = FileSystemReader(tmp_path / "model" / "optimizer")
metadata = reader.read_metadata()
assert isinstance(metadata, Metadata)
keys = list(metadata.state_dict_metadata.keys())
Expand Down Expand Up @@ -2367,6 +2358,11 @@ def test_a_rank_that_cannot_remove_the_markers_fails_the_group(self, tmp_path):
with (
patch("veomni.checkpoint.dcp_checkpointer.dist.is_initialized", return_value=True),
patch("veomni.checkpoint.dcp_checkpointer.dist.get_rank", return_value=1),
patch("veomni.checkpoint.dcp_checkpointer._reject_unproven_extra_parallel_optimizer"),
patch(
"veomni.checkpoint.dcp_checkpointer._coordinated_optimizer_flag",
side_effect=lambda value, *_a, **_k: value,
),
patch("veomni.utils.dist_utils.any_rank_failed", return_value=True),
patch.object(DistributedCheckpointer, "execute_save") as execute_save,
):
Expand Down
Loading
Loading