Skip to content

Commit

Permalink
fix ckpt_utils.py (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMMD authored Jul 12, 2024
1 parent 347e8a9 commit 476b6dc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions opensora/utils/ckpt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ def load_checkpoint(model, ckpt_path, save_as_pt=False, model_name="model", stri
missing_keys, unexpected_keys = model.load_state_dict(state_dict, strict=strict)
get_logger().info("Missing keys: %s", missing_keys)
get_logger().info("Unexpected keys: %s", unexpected_keys)
elif ckpt_path.endswith(".safetensors"):
from safetensors.torch import load_file
state_dict = load_file(ckpt_path)
missing_keys, unexpected_keys = model.load_state_dict(state_dict, strict=False)
print(f"Missing keys: {missing_keys}")
print(f"Unexpected keys: {unexpected_keys}")
elif os.path.isdir(ckpt_path):
load_from_sharded_state_dict(model, ckpt_path, model_name, strict=strict)
get_logger().info("Model checkpoint loaded from %s", ckpt_path)
Expand Down

0 comments on commit 476b6dc

Please sign in to comment.