Skip to content
Open
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
18 changes: 11 additions & 7 deletions src/weathergen/model/model_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,17 @@ def load_model(cf, model, device, run_id: str, mini_epoch=-1):
maybe_sharded_sd = {}
for param_name, full_tensor in params.items():
sharded_meta_param = meta_sharded_sd.get(param_name)
sharded_tensor = distribute_tensor(
full_tensor,
sharded_meta_param.device_mesh,
sharded_meta_param.placements,
)
# maybe_sharded_sd[param_name.replace("module.", "")] = nn.Parameter(sharded_tensor)
maybe_sharded_sd[param_name] = torch.nn.Parameter(sharded_tensor)
if sharded_meta_param is None:
logger.info(f"Sharding meta parameters is None for: {param_name}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it correct that sharded_meta_param is None means that this is a parameter in the checkpoint that is not present in the current model?

maybe_sharded_sd[param_name] = torch.nn.Parameter(full_tensor)
else:
sharded_tensor = distribute_tensor(
full_tensor,
sharded_meta_param.device_mesh,
sharded_meta_param.placements,
)
# maybe_sharded_sd[param_name.replace("module.", "")] = nn.Parameter(sharded_tensor)
maybe_sharded_sd[param_name] = torch.nn.Parameter(sharded_tensor)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we please remove the line below.

# choose `assign=True` for sharded model since we cannot call `copy_` on meta tensor
mkeys, ukeys = model.load_state_dict(maybe_sharded_sd, strict=False, assign=True)

Expand Down
Loading