"""simple docstring"""
import flax.linen as nn
import jax
import jax.numpy as jnp



class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""
				_lowerCAmelCase       :      int
				_lowerCAmelCase       :      jnp.dtype     					=  jnp.floataa

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     nn.Conv(
										    self.out_channels						,      kernel_size=(3, 3)						,      strides=(1, 1)						,      padding=((1, 1), (1, 1))						,      dtype=self.dtype						,      )

				def __call__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case   ,snake_case   ,snake_case   ,snake_case        =     hidden_states.shape
										snake_case        =     jax.image.resize(
										    lowerCAmelCase						,      shape=(batch, height * 2, width * 2, channels)						,      method='nearest'						,      )
										snake_case        =     self.conv(lowerCAmelCase      )
										return hidden_states





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""
				_lowerCAmelCase       :      int
				_lowerCAmelCase       :      jnp.dtype     					=  jnp.floataa

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     nn.Conv(
										    self.out_channels						,      kernel_size=(3, 3)						,      strides=(2, 2)						,      padding=((1, 1), (1, 1))						,      dtype=self.dtype						,      )

				def __call__(			self						,      lowerCAmelCase      ):






										"""simple docstring"""

										snake_case        =     self.conv(lowerCAmelCase      )
										return hidden_states





class 					lowerCAmelCase_      (     nn.Module   ):



				"""simple docstring"""
				_lowerCAmelCase       :      int
				_lowerCAmelCase       :      int     					=  None
				_lowerCAmelCase       :      float     					=  0.0
				_lowerCAmelCase       :      bool     					=  None
				_lowerCAmelCase       :      jnp.dtype     					=  jnp.floataa

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     self.in_channels if self.out_channels is None else self.out_channels

										snake_case        =     nn.GroupNorm(num_groups=32						,      epsilon=1E-5      )
										snake_case        =     nn.Conv(
										    lowerCAmelCase						,      kernel_size=(3, 3)						,      strides=(1, 1)						,      padding=((1, 1), (1, 1))						,      dtype=self.dtype						,      )

										snake_case        =     nn.Dense(lowerCAmelCase						,      dtype=self.dtype      )

										snake_case        =     nn.GroupNorm(num_groups=32						,      epsilon=1E-5      )
										snake_case        =     nn.Dropout(self.dropout_prob      )
										snake_case        =     nn.Conv(
										    lowerCAmelCase						,      kernel_size=(3, 3)						,      strides=(1, 1)						,      padding=((1, 1), (1, 1))						,      dtype=self.dtype						,      )

										snake_case        =     self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

										snake_case        =     None
										if use_nin_shortcut:
																snake_case        =     nn.Conv(
																    lowerCAmelCase						,      kernel_size=(1, 1)						,      strides=(1, 1)						,      padding='VALID'						,      dtype=self.dtype						,      )

				def __call__(			self						,      lowerCAmelCase						,      lowerCAmelCase						,      lowerCAmelCase=True      ):






										"""simple docstring"""

										snake_case        =     hidden_states
										snake_case        =     self.norma(lowerCAmelCase      )
										snake_case        =     nn.swish(lowerCAmelCase      )
										snake_case        =     self.conva(lowerCAmelCase      )

										snake_case        =     self.time_emb_proj(nn.swish(lowerCAmelCase      )      )
										snake_case        =     jnp.expand_dims(jnp.expand_dims(lowerCAmelCase						,      1      )						,      1      )
										snake_case        =     hidden_states + temb

										snake_case        =     self.norma(lowerCAmelCase      )
										snake_case        =     nn.swish(lowerCAmelCase      )
										snake_case        =     self.dropout(lowerCAmelCase						,      lowerCAmelCase      )
										snake_case        =     self.conva(lowerCAmelCase      )

										if self.conv_shortcut is not None:
																snake_case        =     self.conv_shortcut(lowerCAmelCase      )

										return hidden_states + residual



"""simple docstring"""
import pickle
import unittest

import torch

from accelerate import Accelerator
from accelerate.state import AcceleratorState
from accelerate.test_utils import require_cpu



@require_cpu
class 					lowerCAmelCase_      (     unittest.TestCase   ):



				"""simple docstring"""

				def 						snake_case	(			self      ):






										"""simple docstring"""

										snake_case        =     torch.nn.Linear(10						,      10      )
										snake_case        =     torch.optim.SGD(model.parameters()						,      0.1      )
										snake_case        =     Accelerator()
										snake_case        =     accelerator.prepare(lowerCAmelCase      )
										try:
																pickle.loads(pickle.dumps(lowerCAmelCase      )      )
										except Exception as e:
																self.fail(F"""Accelerated optimizer pickling failed with {e}"""      )
										AcceleratorState._reset_state()


