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

Don't push checkpoints to hub in no_trainer scripts #16703

Merged
merged 5 commits into from
Apr 11, 2022
Merged
Changes from 2 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
10 changes: 9 additions & 1 deletion examples/pytorch/language-modeling/run_clm_no_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ def main():
else:
repo_name = args.hub_model_id
repo = Repository(args.output_dir, clone_from=repo_name)
gitignore_path = os.path.join(args.output_dir, ".gitignore")
if not os.path.exists(gitignore_path):
open(gitignore_path, "a").close() # Creates a .gitignore
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd directly put here the step-* key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yeah that would be a bit more simplistic. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Simplified it to:

            with open(os.path.join(args.output_dir, ".gitignore"), 'w+') as gitignore:
                if "step_*" not in gitignore:
                    gitignore.write("step_*\n")
                if "epoch_*" not in gitignore:
                    gitignore.write("epoch_*\n")

Since we can have both epoch_ and step_

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice!

elif args.output_dir is not None:
os.makedirs(args.output_dir, exist_ok=True)
accelerator.wait_for_everyone()
Expand Down Expand Up @@ -542,7 +545,9 @@ def group_texts(examples):
if args.output_dir is not None:
output_dir = os.path.join(args.output_dir, output_dir)
accelerator.save_state(output_dir)

if accelerator.is_main_process and args.push_to_hub:
with open(gitignore_path, "a") as gitignore:
gitignore.write(output_dir)
if completed_steps >= args.max_train_steps:
break

Expand Down Expand Up @@ -589,6 +594,9 @@ def group_texts(examples):
if args.output_dir is not None:
output_dir = os.path.join(args.output_dir, output_dir)
accelerator.save_state(output_dir)
if accelerator.is_main_process and args.push_to_hub:
with open(gitignore_path, "a") as gitignore:
gitignore.write(output_dir)

if args.output_dir is not None:
accelerator.wait_for_everyone()
Expand Down