(args)
| 886 | |
| 887 | |
| 888 | def main(args): |
| 889 | if args.report_to == "wandb" and args.hub_token is not None: |
| 890 | raise ValueError( |
| 891 | "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." |
| 892 | " Please use `huggingface-cli login` to authenticate with the Hub." |
| 893 | ) |
| 894 | |
| 895 | if torch.backends.mps.is_available() and args.mixed_precision == "bf16": |
| 896 | # due to pytorch#99272, MPS does not yet support bfloat16. |
| 897 | raise ValueError( |
| 898 | "Mixed precision training with bfloat16 is not supported on MPS. Please use fp16 (recommended) or fp32 instead." |
| 899 | ) |
| 900 | |
| 901 | logging_dir = Path(args.output_dir, args.logging_dir) |
| 902 | |
| 903 | accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) |
| 904 | kwargs = DistributedDataParallelKwargs(find_unused_parameters=True) |
| 905 | accelerator = Accelerator( |
| 906 | gradient_accumulation_steps=args.gradient_accumulation_steps, |
| 907 | mixed_precision=args.mixed_precision, |
| 908 | log_with=args.report_to, |
| 909 | project_config=accelerator_project_config, |
| 910 | kwargs_handlers=[kwargs], |
| 911 | ) |
| 912 | |
| 913 | # Disable AMP for MPS. |
| 914 | if torch.backends.mps.is_available(): |
| 915 | accelerator.native_amp = False |
| 916 | |
| 917 | if args.report_to == "wandb": |
| 918 | if not is_wandb_available(): |
| 919 | raise ImportError("Make sure to install wandb if you want to use it for logging during training.") |
| 920 | |
| 921 | # Make one log on every process with the configuration for debugging. |
| 922 | logging.basicConfig( |
| 923 | format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", |
| 924 | datefmt="%m/%d/%Y %H:%M:%S", |
| 925 | level=logging.INFO, |
| 926 | ) |
| 927 | logger.info(accelerator.state, main_process_only=False) |
| 928 | if accelerator.is_local_main_process: |
| 929 | transformers.utils.logging.set_verbosity_warning() |
| 930 | diffusers.utils.logging.set_verbosity_info() |
| 931 | else: |
| 932 | transformers.utils.logging.set_verbosity_error() |
| 933 | diffusers.utils.logging.set_verbosity_error() |
| 934 | |
| 935 | # If passed along, set the training seed now. |
| 936 | if args.seed is not None: |
| 937 | set_seed(args.seed) |
| 938 | |
| 939 | # Handle the repository creation |
| 940 | if accelerator.is_main_process: |
| 941 | if args.output_dir is not None: |
| 942 | os.makedirs(args.output_dir, exist_ok=True) |
| 943 | |
| 944 | if args.push_to_hub: |
| 945 | repo_id = create_repo( |
no test coverage detected