()
| 681 | |
| 682 | |
| 683 | def main(): |
| 684 | args = parse_args() |
| 685 | |
| 686 | if args.report_to == "wandb" and args.hub_token is not None: |
| 687 | raise ValueError( |
| 688 | "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token." |
| 689 | " Please use `huggingface-cli login` to authenticate with the Hub." |
| 690 | ) |
| 691 | |
| 692 | if args.non_ema_revision is not None: |
| 693 | deprecate( |
| 694 | "non_ema_revision!=None", |
| 695 | "0.15.0", |
| 696 | message=( |
| 697 | "Downloading 'non_ema' weights from revision branches of the Hub is deprecated. Please make sure to" |
| 698 | " use `--variant=non_ema` instead." |
| 699 | ), |
| 700 | ) |
| 701 | logging_dir = os.path.join(args.output_dir, args.logging_dir) |
| 702 | |
| 703 | config = OmegaConf.load(args.config_path) |
| 704 | accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir) |
| 705 | |
| 706 | accelerator = Accelerator( |
| 707 | gradient_accumulation_steps=args.gradient_accumulation_steps, |
| 708 | mixed_precision=args.mixed_precision, |
| 709 | log_with=args.report_to, |
| 710 | project_config=accelerator_project_config, |
| 711 | ) |
| 712 | |
| 713 | deepspeed_plugin = accelerator.state.deepspeed_plugin if hasattr(accelerator.state, "deepspeed_plugin") else None |
| 714 | fsdp_plugin = accelerator.state.fsdp_plugin if hasattr(accelerator.state, "fsdp_plugin") else None |
| 715 | if deepspeed_plugin is not None: |
| 716 | zero_stage = int(deepspeed_plugin.zero_stage) |
| 717 | fsdp_stage = 0 |
| 718 | print(f"Using DeepSpeed Zero stage: {zero_stage}") |
| 719 | |
| 720 | args.use_deepspeed = True |
| 721 | if zero_stage == 3: |
| 722 | print(f"Auto set save_state to True because zero_stage == 3") |
| 723 | args.save_state = True |
| 724 | elif fsdp_plugin is not None: |
| 725 | from torch.distributed.fsdp import ShardingStrategy |
| 726 | zero_stage = 0 |
| 727 | if fsdp_plugin.sharding_strategy is ShardingStrategy.FULL_SHARD: |
| 728 | fsdp_stage = 3 |
| 729 | elif fsdp_plugin.sharding_strategy is None: # The fsdp_plugin.sharding_strategy is None in FSDP 2. |
| 730 | fsdp_stage = 3 |
| 731 | elif fsdp_plugin.sharding_strategy is ShardingStrategy.SHARD_GRAD_OP: |
| 732 | fsdp_stage = 2 |
| 733 | else: |
| 734 | fsdp_stage = 0 |
| 735 | print(f"Using FSDP stage: {fsdp_stage}") |
| 736 | |
| 737 | args.use_fsdp = True |
| 738 | if fsdp_stage == 3: |
| 739 | print(f"Auto set save_state to True because fsdp_stage == 3") |
| 740 | args.save_state = True |
no test coverage detected