





"""simple docstring"""






import unittest

from transformers import is_flax_available
from transformers.testing_utils import require_flax, require_sentencepiece, require_tokenizers, require_torch, slow


if is_flax_available():
    import optax
    from flax.training.common_utils import onehot

    from transformers import AutoTokenizer, FlaxMTaForConditionalGeneration
    from transformers.models.ta.modeling_flax_ta import shift_tokens_right



@require_torch
@require_sentencepiece
@require_tokenizers
@require_flax
class 	lowerCAmelCase					(      unittest.TestCase							):

       '''simple docstring'''





       @slow
       def 							__A (   self     ):
              _UpperCAmelCase     =     FlaxMTaForConditionalGeneration.from_pretrained('google/mt5-small'     )
              _UpperCAmelCase     =     AutoTokenizer.from_pretrained('google/mt5-small'     )

              _UpperCAmelCase     =     tokenizer('Hello there'    ,  return_tensors='np'     ).input_ids
              _UpperCAmelCase     =     tokenizer('Hi I am'    ,  return_tensors='np'     ).input_ids

              _UpperCAmelCase     =     shift_tokens_right(a__    ,  model.config.pad_token_id    ,  model.config.decoder_start_token_id     )

              _UpperCAmelCase     =     model(a__    ,  decoder_input_ids=a__     ).logits
              _UpperCAmelCase     =     optax.softmax_cross_entropy(a__    ,  onehot(a__    ,  logits.shape[-1]     )     ).mean()

              _UpperCAmelCase     =     -(labels.shape[-1] * loss.item())

              _UpperCAmelCase     =     -84.9_127
              self.assertTrue(abs(mtf_score - EXPECTED_SCORE     ) < 1E-4     )













"""simple docstring"""






from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import PIL

from ...utils import BaseOutput, OptionalDependencyNotAvailable, is_torch_available, is_transformers_available
from .timesteps import (
    fastaa_timesteps,
    smartaa_timesteps,
    smartaa_timesteps,
    smartaaa_timesteps,
    smartaaa_timesteps,
    superaa_timesteps,
    superaa_timesteps,
    superaaa_timesteps,
)



@dataclass
class 	lowerCAmelCase					(      snake_case							):
       lowerCAmelCase__						 =  42
       lowerCAmelCase__						 =  42
       lowerCAmelCase__						 =  42


try:
    if not (is_transformers_available() and is_torch_available()):
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
    from .pipeline_if import IFPipeline
    from .pipeline_if_imgaimg import IFImgaImgPipeline
    from .pipeline_if_imgaimg_superresolution import IFImgaImgSuperResolutionPipeline
    from .pipeline_if_inpainting import IFInpaintingPipeline
    from .pipeline_if_inpainting_superresolution import IFInpaintingSuperResolutionPipeline
    from .pipeline_if_superresolution import IFSuperResolutionPipeline
    from .safety_checker import IFSafetyChecker
    from .watermark import IFWatermarker






