





'''simple docstring'''

import unittest

import pytest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    MBartaaTokenizerFast,
    MBartConfig,
    MBartForConditionalGeneration,
    TranslationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch, slow

from .test_pipelines_common import ANY


@is_pipeline_test
class 			SCREAMING_SNAKE_CASE__	(					unittest.TestCase						):







					"""simple docstring"""






					SCREAMING_SNAKE_CASE				=     MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
					SCREAMING_SNAKE_CASE				=     TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
					def 						lowerCamelCase_					(					self    :	int						,     UpperCAmelCase_    :	Tuple						,     UpperCAmelCase_    :	Optional[Any]						,     UpperCAmelCase_    :	Any						):







							"""simple docstring"""


							if isinstance(model.config						,     lowerCAmelCase_						):
									__UpperCAmelCase   ,       __UpperCAmelCase     :				Optional[int]					   =			list(tokenizer.lang_code_to_id.keys()						)[:2]
									__UpperCAmelCase     :				List[Any]					   =			TranslationPipeline(model=lowerCAmelCase_						,     tokenizer=lowerCAmelCase_						,     src_lang=lowerCAmelCase_						,     tgt_lang=lowerCAmelCase_						)
							else:
									__UpperCAmelCase     :				List[str]					   =			TranslationPipeline(model=lowerCAmelCase_						,     tokenizer=lowerCAmelCase_						)
							return translator, ["Some string", "Some other text"]
					def 						lowerCamelCase_					(					self    :	str						,     UpperCAmelCase_    :	Tuple						,     UpperCAmelCase_    :	Dict						):







							"""simple docstring"""
							__UpperCAmelCase     :				List[str]					   =			translator("Some string"						)
							self.assertEqual(lowerCAmelCase_						,     [{"translation_text": ANY(lowerCAmelCase_						)}]						)

							__UpperCAmelCase     :				int					   =			translator(["Some string"]						)
							self.assertEqual(lowerCAmelCase_						,     [{"translation_text": ANY(lowerCAmelCase_						)}]						)

							__UpperCAmelCase     :				Union[str, Any]					   =			translator(["Some string", "other string"]						)
							self.assertEqual(lowerCAmelCase_						,     [{"translation_text": ANY(lowerCAmelCase_						)}, {"translation_text": ANY(lowerCAmelCase_						)}]						)
					@require_torch
					def 						lowerCamelCase_					(					self    :	List[str]						):







							"""simple docstring"""
							__UpperCAmelCase     :				Tuple					   =			pipeline("translation_en_to_ro"						,     model="patrickvonplaten/t5-tiny-random"						,     framework="pt"						)
							__UpperCAmelCase     :				Optional[Any]					   =			translator("This is a test string"						,     max_length=20						)
							self.assertEqual(
							    lowerCAmelCase_						,     [
							        {
							            "translation_text": (
							                "Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide"
							                " Beide Beide"
							            )
							        }
							    ]						,     )
					@require_tf
					def 						lowerCamelCase_					(					self    :	List[Any]						):







							"""simple docstring"""
							__UpperCAmelCase     :				Union[str, Any]					   =			pipeline("translation_en_to_ro"						,     model="patrickvonplaten/t5-tiny-random"						,     framework="tf"						)
							__UpperCAmelCase     :				Tuple					   =			translator("This is a test string"						,     max_length=20						)
							self.assertEqual(
							    lowerCAmelCase_						,     [
							        {
							            "translation_text": (
							                "Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide Beide"
							                " Beide Beide"
							            )
							        }
							    ]						,     )
					@require_torch
					def 						lowerCamelCase_					(					self    :	int						):







							"""simple docstring"""
							__UpperCAmelCase     :				List[str]					   =			pipeline("translation_en_to_de"						,     model="patrickvonplaten/t5-tiny-random"						,     framework="pt"						)
							__UpperCAmelCase     :				Dict					   =			translator("This is a test string"						,     max_length=20						)
							self.assertEqual(
							    lowerCAmelCase_						,     [
							        {
							            "translation_text": (
							                "monoton monoton monoton monoton monoton monoton monoton monoton monoton monoton urine urine"
							                " urine urine urine urine urine urine urine"
							            )
							        }
							    ]						,     )






					@require_tf
					def 						lowerCamelCase_					(					self    :	List[str]						):







							"""simple docstring"""
							__UpperCAmelCase     :				Any					   =			pipeline("translation_en_to_de"						,     model="patrickvonplaten/t5-tiny-random"						,     framework="tf"						)
							__UpperCAmelCase     :				Optional[int]					   =			translator("This is a test string"						,     max_length=20						)
							self.assertEqual(
							    lowerCAmelCase_						,     [
							        {
							            "translation_text": (
							                "monoton monoton monoton monoton monoton monoton monoton monoton monoton monoton urine urine"
							                " urine urine urine urine urine urine urine"
							            )
							        }
							    ]						,     )






class 			SCREAMING_SNAKE_CASE__	(					unittest.TestCase						):







					"""simple docstring"""






					@require_torch
					@slow
					def 						lowerCamelCase_					(					self    :	List[Any]						):







							"""simple docstring"""


							with self.assertRaises(lowerCAmelCase_						):
									pipeline(task="translation_cn_to_ar"						)

							# but we do for this one
							__UpperCAmelCase     :				Dict					   =			pipeline(task="translation_en_to_de"						)
							self.assertEqual(translator._preprocess_params["src_lang"]						,     "en"						)
							self.assertEqual(translator._preprocess_params["tgt_lang"]						,     "de"						)
					@require_torch
					@slow
					def 						lowerCamelCase_					(					self    :	Dict						):







							"""simple docstring"""
							__UpperCAmelCase     :				str					   =			MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-many-to-many-mmt"						)
							__UpperCAmelCase     :				Union[str, Any]					   =			MBartaaTokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-many-mmt"						)

							__UpperCAmelCase     :				List[str]					   =			pipeline(task="translation"						,     model=lowerCAmelCase_						,     tokenizer=lowerCAmelCase_						)
							# Missing src_lang, tgt_lang
							with self.assertRaises(lowerCAmelCase_						):
									translator("This is a test"						)

							__UpperCAmelCase     :				List[str]					   =			translator("This is a test"						,     src_lang="en_XX"						,     tgt_lang="ar_AR"						)
							self.assertEqual(lowerCAmelCase_						,     [{"translation_text": "هذا إختبار"}]						)

							__UpperCAmelCase     :				str					   =			translator("This is a test"						,     src_lang="en_XX"						,     tgt_lang="hi_IN"						)
							self.assertEqual(lowerCAmelCase_						,     [{"translation_text": "यह एक परीक्षण है"}]						)

							# src_lang, tgt_lang can be defined at pipeline call time
							__UpperCAmelCase     :				Union[str, Any]					   =			pipeline(task="translation"						,     model=lowerCAmelCase_						,     tokenizer=lowerCAmelCase_						,     src_lang="en_XX"						,     tgt_lang="ar_AR"						)
							__UpperCAmelCase     :				Any					   =			translator("This is a test"						)
							self.assertEqual(lowerCAmelCase_						,     [{"translation_text": "هذا إختبار"}]						)
					@require_torch
					def 						lowerCamelCase_					(					self    :	Optional[int]						):







							"""simple docstring"""
							__UpperCAmelCase     :				Optional[Any]					   =			"patrickvonplaten/t5-tiny-random"
							__UpperCAmelCase     :				int					   =			pipeline(task="translation_cn_to_ar"						,     model=lowerCAmelCase_						)
							self.assertEqual(translator._preprocess_params["src_lang"]						,     "cn"						)
							self.assertEqual(translator._preprocess_params["tgt_lang"]						,     "ar"						)
					@require_torch
					def 						lowerCamelCase_					(					self    :	List[Any]						):







							"""simple docstring"""
							__UpperCAmelCase     :				Dict					   =			"patrickvonplaten/t5-tiny-random"
							with pytest.warns(lowerCAmelCase_						,     match=R".*translation_en_to_de.*"						):
									__UpperCAmelCase     :				str					   =			pipeline(task="translation"						,     model=lowerCAmelCase_						)
							self.assertEqual(translator.task						,     "translation_en_to_de"						)
							self.assertEqual(translator._preprocess_params["src_lang"]						,     "en"						)
							self.assertEqual(translator._preprocess_params["tgt_lang"]						,     "de"						)






					@require_torch
					def 						lowerCamelCase_					(					self    :	Any						):







							"""simple docstring"""


							with self.assertRaises(lowerCAmelCase_						):
									pipeline(task="translation"						)










'''simple docstring'''


# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_torch_available,
)


_snake_case      :      Tuple   							=		{
    'configuration_convnextv2': [
        'CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'ConvNextV2Config',
    ]
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				_snake_case      :      Tuple   							=		[
				    'CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST',
				    'ConvNextV2ForImageClassification',
				    'ConvNextV2Model',
				    'ConvNextV2PreTrainedModel',
				    'ConvNextV2Backbone',
				]


if TYPE_CHECKING:
				from .configuration_convnextva import (
				    CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP,
				    ConvNextVaConfig,
				)

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .modeling_convnextva import (
								    CONVNEXTV2_PRETRAINED_MODEL_ARCHIVE_LIST,
								    ConvNextVaBackbone,
								    ConvNextVaForImageClassification,
								    ConvNextVaModel,
								    ConvNextVaPreTrainedModel,
								)

else:
				import sys

				_snake_case      :      Any   							=		_LazyModule(__name__, globals()['__file__'], _import_structure)

