Skip to content
Merged
Changes from all commits
Commits
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
24 changes: 8 additions & 16 deletions tools/checkpoint/checkpoint_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,14 @@

from megatron.core.distributed.fsdp.src.megatron_fsdp.uneven_dtensor import split_dtensor, gather_uneven_dtensor_to_full_tensor

from megatron.core.dist_checkpointing.serialization import (
get_default_load_sharded_strategy,
)
from megatron.core.dist_checkpointing.strategies.common import load_common
from megatron.core.dist_checkpointing.strategies.fully_parallel import (
FullyParallelLoadStrategyWrapper,
)
from megatron.core.dist_checkpointing.strategies.torch import (
TorchDistLoadShardedStrategy,
)
from megatron.core.dist_checkpointing.validation import (
verify_checkpoint_and_load_strategy,
)
from megatron.core.dist_checkpointing.validation import verify_checkpoint
from megatron.core.msc_utils import MultiStorageClientFeature


Expand Down Expand Up @@ -96,19 +92,17 @@ def inspect(checkpoint_dir, enable_msc, not_ignore_param_to_group_meta):

try:
# Strategies initialization
sharded_strategy = get_default_load_sharded_strategy(checkpoint_dir)
sharded_strategy = TorchDistLoadShardedStrategy()
sharded_strategy = FullyParallelLoadStrategyWrapper(sharded_strategy)
sharded_strategy, common_strategy = verify_checkpoint_and_load_strategy(
checkpoint_dir, sharded_strategy, common_strategy=None
)
verify_checkpoint(checkpoint_dir)
assert isinstance(
sharded_strategy.base_strategy, TorchDistLoadShardedStrategy
), click.style(
f"Unsupported sharded strategy: {sharded_strategy}", fg="red", bold=True
)

# Common state section
common_state = common_strategy.load_common(checkpoint_dir)
common_state = load_common(checkpoint_dir)
print_header(f"common state ({len(common_state)} items)", "cyan")
for key, value in common_state.items():
bullet = click.style("•", fg="magenta")
Expand Down Expand Up @@ -615,17 +609,15 @@ def has_layer_index(key: str) -> bool:
)

# Handle args, optimizer.param_groups and other shared objects.
sharded_strategy = get_default_load_sharded_strategy(input_dir)
sharded_strategy = TorchDistLoadShardedStrategy()
sharded_strategy = FullyParallelLoadStrategyWrapper(sharded_strategy)
sharded_strategy, common_strategy = verify_checkpoint_and_load_strategy(
input_dir, sharded_strategy, common_strategy=None
)
verify_checkpoint(str(input_dir))
assert isinstance(sharded_strategy.base_strategy, TorchDistLoadShardedStrategy), (
click.style(
f"Unsupported sharded strategy: {sharded_strategy}", fg="red", bold=True
)
)
common_state = common_strategy.load_common(input_dir)
common_state = load_common(input_dir)
try:
if "param_groups" in common_state["optimizer"]:
ckpt_param_groups = common_state["optimizer"]["param_groups"]
Expand Down
Loading