(args)
| 799 | |
| 800 | |
| 801 | def main(args): |
| 802 | if args.report_to == "wandb" and args.hub_token is not None: |
| 803 | raise ValueError( |
| 804 | "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." |
| 805 | " Please use `huggingface-cli login` to authenticate with the Hub." |
| 806 | ) |
| 807 | |
| 808 | logging_out_dir = Path(args.output_dir, args.logging_dir) |
| 809 | |
| 810 | if torch.backends.mps.is_available() and args.mixed_precision == "bf16": |
| 811 | # due to pytorch#99272, MPS does not yet support bfloat16. |
| 812 | raise ValueError( |
| 813 | "Mixed precision training with bfloat16 is not supported on MPS. Please use fp16 (recommended) or fp32 instead." |
| 814 | ) |
| 815 | |
| 816 | accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=str(logging_out_dir)) |
| 817 | |
| 818 | accelerator = Accelerator( |
| 819 | gradient_accumulation_steps=args.gradient_accumulation_steps, |
| 820 | mixed_precision=args.mixed_precision, |
| 821 | log_with=args.report_to, |
| 822 | project_config=accelerator_project_config, |
| 823 | ) |
| 824 | |
| 825 | # Disable AMP for MPS. A technique for accelerating machine learning computations on iOS and macOS devices. |
| 826 | if torch.backends.mps.is_available(): |
| 827 | print("MPS is enabled. Disabling AMP.") |
| 828 | accelerator.native_amp = False |
| 829 | |
| 830 | # Make one log on every process with the configuration for debugging. |
| 831 | logging.basicConfig( |
| 832 | format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", |
| 833 | datefmt="%m/%d/%Y %H:%M:%S", |
| 834 | # DEBUG, INFO, WARNING, ERROR, CRITICAL |
| 835 | level=logging.INFO, |
| 836 | ) |
| 837 | logger.info(accelerator.state, main_process_only=False) |
| 838 | |
| 839 | if accelerator.is_local_main_process: |
| 840 | transformers.utils.logging.set_verbosity_warning() |
| 841 | diffusers.utils.logging.set_verbosity_info() |
| 842 | else: |
| 843 | transformers.utils.logging.set_verbosity_error() |
| 844 | diffusers.utils.logging.set_verbosity_error() |
| 845 | |
| 846 | # If passed along, set the training seed now. |
| 847 | if args.seed is not None: |
| 848 | set_seed(args.seed) |
| 849 | |
| 850 | # Handle the repository creation |
| 851 | if accelerator.is_main_process: |
| 852 | if args.output_dir is not None: |
| 853 | os.makedirs(args.output_dir, exist_ok=True) |
| 854 | |
| 855 | if args.push_to_hub: |
| 856 | repo_id = create_repo( |
| 857 | repo_id=args.hub_model_id or Path(args.output_dir).name, exist_ok=True, token=args.hub_token |
| 858 | ).repo_id |
no test coverage detected