Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an extra call to load state dict and type cast in hf checkpointer #939

Merged
merged 1 commit into from
Feb 5, 2024
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
4 changes: 1 addition & 3 deletions llmfoundry/callbacks/hf_checkpointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,13 @@ def _save_checkpoint(self, state: State, logger: Logger):
new_model_instance = type(original_model)(
new_base_model_instance,
original_model.peft_config[active_adapter])
new_model_instance.to(dtype=self.dtype)
else:
# First create the model instance on meta device to avoid the
# initialization cost.
with init_empty_weights():
new_model_instance = type(original_model)(copied_config)

new_model_instance.to(dtype=self.dtype)
new_model_instance.load_state_dict(state_dict)

# Then load the state dict in with "assign" so that the state dict
# is loaded properly even though the model is initially on meta device.
new_model_instance.load_state_dict(state_dict, assign=True)
Expand Down
Loading