




"""simple docstring"""






# We ignore warnings about stepping the scheduler since we step it ourselves during gradient accumulation

import warnings

from .state import AcceleratorState, GradientState


warnings.filterwarnings("""ignore""", category=UserWarning, module="""torch.optim.lr_scheduler""")






class lowerCAmelCase__      :






			'''simple docstring'''



			def __init__(    self    , lowercase    , lowercase    , lowercase = True    , lowercase = False    ):
							_lowerCamelCase	:     Union[str, Any]       =       scheduler
							_lowerCamelCase	:     List[str]       =       optimizers if isinstance(lowercase    , (list, tuple)    ) else [optimizers]
							_lowerCamelCase	:     Optional[int]       =       split_batches
							_lowerCamelCase	:     Optional[Any]       =       step_with_optimizer
							_lowerCamelCase	:     Dict       =       GradientState()
			def    A_       (    self    , *lowercase    , **lowercase    ):
							if not self.step_with_optimizer:
											# No link between scheduler and optimizer -> just step
											self.scheduler.step(*lowercase    , **lowercase    )
											return

							# Otherwise, first make sure the optimizer was stepped.
							if not self.gradient_state.sync_gradients:
											if self.gradient_state.adjust_scheduler:
															self.scheduler._step_count += 1
											return

							for opt in self.optimizers:
											if opt.step_was_skipped:
															return
							if self.split_batches:
											# Split batches -> the training dataloader batch size is not changed so one step per training step
											self.scheduler.step(*lowercase    , **lowercase    )
							else:
											# Otherwise the training dataloader batch size was multiplied by `num_processes`, so we need to do
											# num_processes steps per training step
											_lowerCamelCase	:     Dict       =       AcceleratorState().num_processes
											for _ in range(lowercase    ):
															# Special case when using OneCycle and `drop_last` was not used
															if hasattr(self.scheduler    , 'total_steps'    ):
																			if self.scheduler._step_count <= self.scheduler.total_steps:
																							self.scheduler.step(*lowercase    , **lowercase    )
															else:
																			self.scheduler.step(*lowercase    , **lowercase    )
			def    A_       (    self    ):
							return self.scheduler.get_last_lr()
			def    A_       (    self    ):
							return self.scheduler.state_dict()
			def    A_       (    self    , lowercase    ):
							self.scheduler.load_state_dict(lowercase    )
			def    A_       (    self    ):
							return self.scheduler.get_lr()






			def    A_       (    self    , *lowercase    , **lowercase    ):
							return self.scheduler.print_lr(*lowercase    , **lowercase    )





"""simple docstring"""






from diffusers.utils.testing_utils import require_onnxruntime






@require_onnxruntime
class lowerCAmelCase__      :






			'''simple docstring'''



			pass