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

Add special case for saving model when running with ZERO-3 optimisation. #149

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Willmish
Copy link
Collaborator

Tiny fix so a model sharded with Zero-3 can be saved! (To test if it doesnt also save the ugly placeholder confusing huggingface model loader)

@Willmish Willmish requested review from TheRootOf3 and Adamliu1 and removed request for TheRootOf3 September 18, 2024 12:08
@Willmish
Copy link
Collaborator Author

Weird thing is: when saving the model, it saves it fine, but also saves the placeholder model.safetensors file, hierarchy looks like:

config.json
generation_config.json
model-00001-of-00004.safetensors
model-00002-of-00004.safetensors
model-00003-of-00004.safetensors
model-00004-of-00004.safetensors
model.safetensors
model.safetensors.index.json
special_tokens_map.json
tokenizer_config.json
tokenizer.json

But model.safetensors shouldnt be there! (it causes things like AutoModelForCausalLM.from_pretrained( to fail, unless the placeholder file is removed!

@@ -468,7 +509,30 @@ def main(args) -> None:
model = model.merge_and_unload()

# Save final model.
if accelerator.is_local_main_process:
# NOTE: special case for zero 3
Copy link
Owner

Choose a reason for hiding this comment

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

why are we not handling model saving in the main process? I wonder

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Adamliu1 good q, I basedd this off of: https://huggingface.co/docs/accelerate/usage_guides/deepspeed#saving-and-loading , and I belive its because each process (on each of the 4 GPUs) has a portion of the model that needs to be synced across - hence cannot just unwrap it on a single process.

Signed-off-by: Szymon Duchniewicz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants