diff --git a/training/utils/load_fsdp_to_hf.py b/training/utils/load_fsdp_to_hf.py index e9b13b00..809c30ad 100644 --- a/training/utils/load_fsdp_to_hf.py +++ b/training/utils/load_fsdp_to_hf.py @@ -32,6 +32,27 @@ def main(fsdp_checkpoint_path, huggingface_model_path, output_path, push_to_hub= tokenizer = AutoTokenizer.from_pretrained(huggingface_model_path) tokenizer.save_pretrained(output_path) + # Push to hub if requested + if push_to_hub: + if not output_path: + raise ValueError("output path must be provided when push_to_hub=True") + + print(f"Pushing model to Hugging Face Hub: {output_path}") + + # Create repository if it doesn't exist + api = HfApi(token=hub_token) + try: + create_repo(repo_id=output_path, private=private, exist_ok=True, token=hub_token) + print(f"Repository {output_path} created or already exists") + except Exception as e: + print(f"Repository creation info: {e}") + + # Push model and tokenizer to hub + model.push_to_hub(output_path, token=hub_token, private=private) + tokenizer.push_to_hub(output_path, token=hub_token, private=private) + + print(f"✅ Model successfully pushed to https://huggingface.co/{output_path}") + if __name__ == "__main__": fire.Fire(main)