MCPcopy Create free account
hub / github.com/TencentARC/BrushNet / main

Function main

examples/custom_diffusion/train_custom_diffusion.py:661–1357  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

659
660
661def main(args):
662 if args.report_to == "wandb" and args.hub_token is not None:
663 raise ValueError(
664 "You cannot use both --report_to=wandb and --hub_token due to a security risk of exposing your token."
665 " Please use `huggingface-cli login` to authenticate with the Hub."
666 )
667
668 logging_dir = Path(args.output_dir, args.logging_dir)
669
670 accelerator_project_config = ProjectConfiguration(project_dir=args.output_dir, logging_dir=logging_dir)
671
672 accelerator = Accelerator(
673 gradient_accumulation_steps=args.gradient_accumulation_steps,
674 mixed_precision=args.mixed_precision,
675 log_with=args.report_to,
676 project_config=accelerator_project_config,
677 )
678
679 if args.report_to == "wandb":
680 if not is_wandb_available():
681 raise ImportError("Make sure to install wandb if you want to use it for logging during training.")
682 import wandb
683
684 # Currently, it's not possible to do gradient accumulation when training two models with accelerate.accumulate
685 # This will be enabled soon in accelerate. For now, we don't allow gradient accumulation when training two models.
686 # TODO (patil-suraj): Remove this check when gradient accumulation with two models is enabled in accelerate.
687 # Make one log on every process with the configuration for debugging.
688 logging.basicConfig(
689 format="%(asctime)s - %(levelname)s - %(name)s - %(message)s",
690 datefmt="%m/%d/%Y %H:%M:%S",
691 level=logging.INFO,
692 )
693 logger.info(accelerator.state, main_process_only=False)
694 if accelerator.is_local_main_process:
695 transformers.utils.logging.set_verbosity_warning()
696 diffusers.utils.logging.set_verbosity_info()
697 else:
698 transformers.utils.logging.set_verbosity_error()
699 diffusers.utils.logging.set_verbosity_error()
700
701 # We need to initialize the trackers we use, and also store our configuration.
702 # The trackers initializes automatically on the main process.
703 if accelerator.is_main_process:
704 accelerator.init_trackers("custom-diffusion", config=vars(args))
705
706 # If passed along, set the training seed now.
707 if args.seed is not None:
708 set_seed(args.seed)
709 if args.concepts_list is None:
710 args.concepts_list = [
711 {
712 "instance_prompt": args.instance_prompt,
713 "class_prompt": args.class_prompt,
714 "instance_data_dir": args.instance_data_dir,
715 "class_data_dir": args.class_data_dir,
716 }
717 ]
718 else:

Callers 1

Calls 15

is_wandb_availableFunction · 0.90
set_seedFunction · 0.90
is_xformers_availableFunction · 0.90
AttnProcsLayersClass · 0.90
get_schedulerFunction · 0.90
text_encoderFunction · 0.85
unetFunction · 0.85
save_new_embedFunction · 0.85
infoMethod · 0.80
load_state_dictMethod · 0.80

Tested by

no test coverage detected