




'''simple docstring'''



import flax.linen as nn
import jax
import jax.numpy as jnp






class 							_a				(			nn.Module ):





       '''simple docstring'''






       A						:				int
       A						:				jnp.dtype        =						jnp.floataa







       def        UpperCamelCase_							(      self  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      str    					=						nn.Conv(
                 self.out_channels,							kernel_size=(3, 3),							strides=(1, 1),							padding=((1, 1), (1, 1)),							dtype=self.dtype,							)







       def __call__(      self,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						hidden_states.shape
             SCREAMING_SNAKE_CASE   :      Optional[int]    					=						jax.image.resize(
                 A,							shape=(batch, height * 2, width * 2, channels),							method='nearest',							)
             SCREAMING_SNAKE_CASE   :      Optional[int]    					=						self.conv(A  )
             return hidden_states






class 							_a				(			nn.Module ):





       '''simple docstring'''






       A						:				int
       A						:				jnp.dtype        =						jnp.floataa







       def        UpperCamelCase_							(      self  ):







             '''simple docstring'''







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







       def __call__(      self,							A  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      str    					=						self.conv(A  )
             return hidden_states






class 							_a				(			nn.Module ):





       '''simple docstring'''






       A						:				int
       A						:				int        =						None
       A						:				float        =						0.0
       A						:				bool        =						None
       A						:				jnp.dtype        =						jnp.floataa







       def        UpperCamelCase_							(      self  ):







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      List[str]    					=						self.in_channels if self.out_channels is None else self.out_channels

             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						nn.GroupNorm(num_groups=32,							epsilon=1E-5  )
             SCREAMING_SNAKE_CASE   :      int    					=						nn.Conv(
                 A,							kernel_size=(3, 3),							strides=(1, 1),							padding=((1, 1), (1, 1)),							dtype=self.dtype,							)

             SCREAMING_SNAKE_CASE   :      Tuple    					=						nn.Dense(A,							dtype=self.dtype  )

             SCREAMING_SNAKE_CASE   :      Dict    					=						nn.GroupNorm(num_groups=32,							epsilon=1E-5  )
             SCREAMING_SNAKE_CASE   :      Any    					=						nn.Dropout(self.dropout_prob  )
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						nn.Conv(
                 A,							kernel_size=(3, 3),							strides=(1, 1),							padding=((1, 1), (1, 1)),							dtype=self.dtype,							)

             SCREAMING_SNAKE_CASE   :      List[Any]    					=						self.in_channels != out_channels if self.use_nin_shortcut is None else self.use_nin_shortcut

             SCREAMING_SNAKE_CASE   :      Tuple    					=						None
             if use_nin_shortcut:
                   SCREAMING_SNAKE_CASE   :      str    					=						nn.Conv(
                       A,							kernel_size=(1, 1),							strides=(1, 1),							padding='VALID',							dtype=self.dtype,							)







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







             '''simple docstring'''







             SCREAMING_SNAKE_CASE   :      List[str]    					=						hidden_states
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						self.norma(A  )
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						nn.swish(A  )
             SCREAMING_SNAKE_CASE   :      Tuple    					=						self.conva(A  )

             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						self.time_emb_proj(nn.swish(A  )  )
             SCREAMING_SNAKE_CASE   :      int    					=						jnp.expand_dims(jnp.expand_dims(A,							1  ),							1  )
             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						hidden_states + temb

             SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						self.norma(A  )
             SCREAMING_SNAKE_CASE   :      List[str]    					=						nn.swish(A  )
             SCREAMING_SNAKE_CASE   :      Optional[int]    					=						self.dropout(A,							A  )
             SCREAMING_SNAKE_CASE   :      Any    					=						self.conva(A  )

             if self.conv_shortcut is not None:
                   SCREAMING_SNAKE_CASE   :      str    					=						self.conv_shortcut(A  )

             return hidden_states + residual








'''simple docstring'''



from typing import List, Optional, TypeVar

from .arrow_dataset import Dataset, _concatenate_map_style_datasets, _interleave_map_style_datasets
from .dataset_dict import DatasetDict, IterableDatasetDict
from .info import DatasetInfo
from .iterable_dataset import IterableDataset, _concatenate_iterable_datasets, _interleave_iterable_datasets
from .splits import NamedSplit
from .utils import logging
from .utils.py_utils import Literal


UpperCamelCase_    	=				logging.get_logger(__name__)


UpperCamelCase_    	=				TypeVar("DatasetType", Dataset, IterableDataset)




def   lowercase__(			__UpperCamelCase:					List[DatasetType]      ,__UpperCamelCase:					Optional[List[float]] = None      ,__UpperCamelCase:					Optional[int] = None      ,__UpperCamelCase:					Optional[DatasetInfo] = None      ,__UpperCamelCase:					Optional[NamedSplit] = None      ,__UpperCamelCase:					Literal["first_exhausted", "all_exhausted"] = "first_exhausted"      ,):

      """simple docstring"""






      from .arrow_dataset import Dataset
      from .iterable_dataset import IterableDataset

      if not datasets:
            raise ValueError('Unable to interleave an empty list of datasets.'    )
      for i, dataset in enumerate(__UpperCamelCase    ):
            if not isinstance(__UpperCamelCase      ,(Dataset, IterableDataset)    ):
                  if isinstance(__UpperCamelCase      ,(DatasetDict, IterableDatasetDict)    ):
                        if not dataset:
                              raise ValueError(
                                  f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
                                  'is an empty dataset dictionary.'    )
                        raise ValueError(
                            f"Dataset at position {i} has at least one split: {list(__UpperCamelCase    )}\n"
                            f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase    )    )}']"    )
                  raise ValueError(
                      f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase    ).__name__}."    )
            if i == 0:
                  SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      Optional[Any]    					=						(
                      (Dataset, IterableDataset) if isinstance(__UpperCamelCase      ,__UpperCamelCase    ) else (IterableDataset, Dataset)
                  )
            elif not isinstance(__UpperCamelCase      ,__UpperCamelCase    ):
                  raise ValueError(
                      f"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."    )
      if stopping_strategy not in ["first_exhausted", "all_exhausted"]:
            raise ValueError(f"{stopping_strategy} is not supported. Please enter a valid stopping_strategy."    )
      if dataset_type is Dataset:
            return _interleave_map_style_datasets(
                __UpperCamelCase      ,__UpperCamelCase      ,__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,stopping_strategy=__UpperCamelCase    )
      else:
            return _interleave_iterable_datasets(
                __UpperCamelCase      ,__UpperCamelCase      ,__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,stopping_strategy=__UpperCamelCase    )





def   lowercase__(			__UpperCamelCase:					List[DatasetType]      ,__UpperCamelCase:					Optional[DatasetInfo] = None      ,__UpperCamelCase:					Optional[NamedSplit] = None      ,__UpperCamelCase:					int = 0      ,):

      """simple docstring"""






      if not dsets:
            raise ValueError('Unable to concatenate an empty list of datasets.'    )
      for i, dataset in enumerate(__UpperCamelCase    ):
            if not isinstance(__UpperCamelCase      ,(Dataset, IterableDataset)    ):
                  if isinstance(__UpperCamelCase      ,(DatasetDict, IterableDatasetDict)    ):
                        if not dataset:
                              raise ValueError(
                                  f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} "
                                  'is an empty dataset dictionary.'    )
                        raise ValueError(
                            f"Dataset at position {i} has at least one split: {list(__UpperCamelCase    )}\n"
                            f"Please pick one to interleave with the other datasets, for example: dataset['{next(iter(__UpperCamelCase    )    )}']"    )
                  raise ValueError(
                      f"Expected a list of Dataset objects or a list of IterableDataset objects, but element at position {i} is a {type(__UpperCamelCase    ).__name__}."    )
            if i == 0:
                  SCREAMING_SNAKE_CASE					,    SCREAMING_SNAKE_CASE   :      int    					=						(
                      (Dataset, IterableDataset) if isinstance(__UpperCamelCase      ,__UpperCamelCase    ) else (IterableDataset, Dataset)
                  )
            elif not isinstance(__UpperCamelCase      ,__UpperCamelCase    ):
                  raise ValueError(
                      f"Unable to interleave a {dataset_type.__name__} (at position 0) with a {other_type.__name__} (at position {i}). Expected a list of Dataset objects or a list of IterableDataset objects."    )
      if dataset_type is Dataset:
            return _concatenate_map_style_datasets(__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,axis=__UpperCamelCase    )
      else:
            return _concatenate_iterable_datasets(__UpperCamelCase      ,info=__UpperCamelCase      ,split=__UpperCamelCase      ,axis=__UpperCamelCase    )


