(args)
| 732 | |
| 733 | |
| 734 | def main(args): |
| 735 | if args.report_to == "wandb" and args.hub_token is not None: |
| 736 | raise ValueError( |
| 737 | "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." |
| 738 | " Please use `hf auth login` to authenticate with the Hub." |
| 739 | ) |
| 740 | |
| 741 | logging_dir = Path(args.output_dir, args.logging_dir) |
| 742 | |
| 743 | accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) |
| 744 | |
| 745 | accelerator = Accelerator( |
| 746 | gradient_accumulation_steps=args.gradient_accumulation_steps, |
| 747 | mixed_precision=args.mixed_precision, |
| 748 | log_with=args.report_to, |
| 749 | project_config=accelerator_project_config, |
| 750 | ) |
| 751 | |
| 752 | # Disable AMP for MPS. |
| 753 | if torch.backends.mps.is_available(): |
| 754 | accelerator.native_amp = False |
| 755 | |
| 756 | # Make one log on every process with the configuration for debugging. |
| 757 | logging.basicConfig( |
| 758 | format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", |
| 759 | datefmt="%m/%d/%Y %H:%M:%S", |
| 760 | level=logging.INFO, |
| 761 | ) |
| 762 | logger.info(accelerator.state, main_process_only=False) |
| 763 | if accelerator.is_local_main_process: |
| 764 | transformers.utils.logging.set_verbosity_warning() |
| 765 | diffusers.utils.logging.set_verbosity_info() |
| 766 | else: |
| 767 | transformers.utils.logging.set_verbosity_error() |
| 768 | diffusers.utils.logging.set_verbosity_error() |
| 769 | |
| 770 | # If passed along, set the training seed now. |
| 771 | if args.seed is not None: |
| 772 | set_seed(args.seed) |
| 773 | |
| 774 | # Handle the repository creation |
| 775 | if accelerator.is_main_process: |
| 776 | if args.output_dir is not None: |
| 777 | os.makedirs(args.output_dir, exist_ok=True) |
| 778 | |
| 779 | if args.push_to_hub: |
| 780 | repo_id = create_repo( |
| 781 | repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token |
| 782 | ).repo_id |
| 783 | |
| 784 | # Load the tokenizer |
| 785 | if args.tokenizer_name: |
| 786 | tokenizer = AutoTokenizer.from_pretrained(args.tokenizer_name, revision=args.revision, use_fast=False) |
| 787 | elif args.pretrained_model_name_or_path: |
| 788 | tokenizer = AutoTokenizer.from_pretrained( |
| 789 | args.pretrained_model_name_or_path, |
| 790 | subfolder="tokenizer", |
| 791 | revision=args.revision, |
no test coverage detected
searching dependent graphs…