()
| 590 | |
| 591 | |
| 592 | def main(): |
| 593 | args = parse_args() |
| 594 | if args.report_to == "wandb" and args.hub_token is not None: |
| 595 | raise ValueError( |
| 596 | "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." |
| 597 | " Please use `huggingface-cli login` to authenticate with the Hub." |
| 598 | ) |
| 599 | |
| 600 | logging_dir = os.path.join(args.output_dir, args.logging_dir) |
| 601 | accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) |
| 602 | accelerator = Accelerator( |
| 603 | gradient_accumulation_steps=args.gradient_accumulation_steps, |
| 604 | mixed_precision=args.mixed_precision, |
| 605 | log_with=args.report_to, |
| 606 | project_config=accelerator_project_config, |
| 607 | ) |
| 608 | |
| 609 | # Disable AMP for MPS. |
| 610 | if torch.backends.mps.is_available(): |
| 611 | accelerator.native_amp = False |
| 612 | |
| 613 | if args.report_to == "wandb": |
| 614 | if not is_wandb_available(): |
| 615 | raise ImportError("Make sure to install wandb if you want to use it for logging during training.") |
| 616 | |
| 617 | # Make one log on every process with the configuration for debugging. |
| 618 | logging.basicConfig( |
| 619 | format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", |
| 620 | datefmt="%m/%d/%Y %H:%M:%S", |
| 621 | level=logging.INFO, |
| 622 | ) |
| 623 | logger.info(accelerator.state, main_process_only=False) |
| 624 | if accelerator.is_local_main_process: |
| 625 | transformers.utils.logging.set_verbosity_warning() |
| 626 | diffusers.utils.logging.set_verbosity_info() |
| 627 | else: |
| 628 | transformers.utils.logging.set_verbosity_error() |
| 629 | diffusers.utils.logging.set_verbosity_error() |
| 630 | |
| 631 | # If passed along, set the training seed now. |
| 632 | if args.seed is not None: |
| 633 | set_seed(args.seed) |
| 634 | |
| 635 | # Handle the repository creation |
| 636 | if accelerator.is_main_process: |
| 637 | if args.output_dir is not None: |
| 638 | os.makedirs(args.output_dir, exist_ok=True) |
| 639 | |
| 640 | if args.push_to_hub: |
| 641 | repo_id = create_repo( |
| 642 | repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token |
| 643 | ).repo_id |
| 644 | |
| 645 | # Load tokenizer |
| 646 | if args.tokenizer_name: |
| 647 | tokenizer = CLIPTokenizer.from_pretrained(args.tokenizer_name) |
| 648 | elif args.pretrained_model_name_or_path: |
| 649 | tokenizer = CLIPTokenizer.from_pretrained(args.pretrained_model_name_or_path, subfolder="tokenizer") |
no test coverage detected