






"""simple docstring"""





import enum
import warnings

from ..tokenization_utils import TruncationStrategy
from ..utils import add_end_docstrings, is_tf_available, is_torch_available, logging
from .base import PIPELINE_INIT_ARGS, Pipeline


if is_tf_available():
						import tensorflow as tf

						from ..models.auto.modeling_tf_auto import TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

if is_torch_available():
						from ..models.auto.modeling_auto import MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING

lowerCAmelCase__     			=			logging.get_logger(__name__)





class        _lowerCamelCase      (       enum.Enum ):
						UpperCAmelCase_ =			0
						UpperCAmelCase_ =			1





@add_end_docstrings(_lowercase )
class        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			"generated"


						def __init__(self   ,							*__a   ,							**__a		) ->   Dict:
								super().__init__(*__a   ,							**__a		)

								self.check_model_type(
								    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
								    if self.framework == "tf"
								    else MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING		)


						def     snake_case_   (self   ,							__a=None   ,							__a=None   ,							__a=None   ,							__a=None   ,							__a=None   ,							__a=None   ,							**__a   ,							) ->   List[str]:
								UpperCamelCase   =	{}
								if truncation is not None:
										UpperCamelCase   =	truncation

								UpperCamelCase   =	generate_kwargs

								UpperCamelCase   =	{}
								if return_tensors is not None and return_type is None:
										UpperCamelCase   =	ReturnType.TENSORS if return_tensors else ReturnType.TEXT
								if return_type is not None:
										UpperCamelCase   =	return_type

								if clean_up_tokenization_spaces is not None:
										UpperCamelCase   =	clean_up_tokenization_spaces

								if stop_sequence is not None:
										UpperCamelCase   =	self.tokenizer.encode(__a   ,							add_special_tokens=__a		)
										if len(__a		) > 1:
												warnings.warn(
												    "Stopping on a multiple token sequence is not yet supported on transformers. The first token of"
												    " the stop sequence will be used as the stop sequence string in the interim."		)
										UpperCamelCase   =	stop_sequence_ids[0]

								return preprocess_params, forward_params, postprocess_params


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a		) ->   Dict:
								return True


						def     snake_case_   (self   ,							*__a   ,							__a		) ->   Tuple:
								UpperCamelCase   =	self.model.config.prefix if self.model.config.prefix is not None else ""
								if isinstance(args[0]   ,							__a		):
										if self.tokenizer.pad_token_id is None:
												raise ValueError("Please make sure that the tokenizer has a pad_token_id when using a batch input"		)
										UpperCamelCase   =	([prefix + arg for arg in args[0]],)
										UpperCamelCase   =	True

								elif isinstance(args[0]   ,							__a		):
										UpperCamelCase   =	(prefix + args[0],)
										UpperCamelCase   =	False
								else:
										raise ValueError(
										    F" `args[0]`: {args[0]} have the wrong format. The should be either of type `str` or type `list`"		)
								UpperCamelCase   =	self.tokenizer(*__a   ,							padding=__a   ,							truncation=__a   ,							return_tensors=self.framework		)
								# This is produced by tokenizers but is an invalid generate kwargs
								if "token_type_ids" in inputs:
										del inputs["token_type_ids"]
								return inputs


						def __call__(self   ,							*__a   ,							**__a		) ->   Optional[Any]:
								UpperCamelCase   =	super().__call__(*__a   ,							**__a		)
								if (
								    isinstance(args[0]   ,							__a		)
								    and all(isinstance(__a   ,							__a		) for el in args[0]		)
								    and all(len(__a		) == 1 for res in result		)
								):
										return [res[0] for res in result]
								return result


						def     snake_case_   (self   ,							__a   ,							__a=TruncationStrategy.DO_NOT_TRUNCATE   ,							**__a		) ->   int:
								UpperCamelCase   =	self._parse_and_tokenize(__a   ,							truncation=__a   ,							**__a		)
								return inputs


						def     snake_case_   (self   ,							__a   ,							**__a		) ->   Union[str, Any]:
								if self.framework == "pt":
										UpperCamelCase   ,				UpperCamelCase   =	model_inputs["input_ids"].shape
								elif self.framework == "tf":
										UpperCamelCase   ,				UpperCamelCase   =	tf.shape(model_inputs["input_ids"]		).numpy()

								UpperCamelCase   =	generate_kwargs.get("min_length"   ,							self.model.config.min_length		)
								UpperCamelCase   =	generate_kwargs.get("max_length"   ,							self.model.config.max_length		)
								self.check_inputs(__a   ,							generate_kwargs["min_length"]   ,							generate_kwargs["max_length"]		)
								UpperCamelCase   =	self.model.generate(**__a   ,							**__a		)
								UpperCamelCase   =	output_ids.shape[0]
								if self.framework == "pt":
										UpperCamelCase   =	output_ids.reshape(__a   ,							out_b // in_b   ,							*output_ids.shape[1:]		)
								elif self.framework == "tf":
										UpperCamelCase   =	tf.reshape(__a   ,							(in_b, out_b // in_b, *output_ids.shape[1:])		)
								return {"output_ids": output_ids}




						def     snake_case_   (self   ,							__a   ,							__a=ReturnType.TEXT   ,							__a=False		) ->   Tuple:
								UpperCamelCase   =	[]
								for output_ids in model_outputs["output_ids"][0]:
										if return_type == ReturnType.TENSORS:
												UpperCamelCase   =	{F"{self.return_name}_token_ids": output_ids}
										elif return_type == ReturnType.TEXT:
												UpperCamelCase   =	{
												    F"{self.return_name}_text": self.tokenizer.decode(
												        __a   ,							skip_special_tokens=__a   ,							clean_up_tokenization_spaces=__a   ,							)
												}
										records.append(__a		)
								return records





@add_end_docstrings(_lowercase )
class        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			"summary"


						def __call__(self   ,							*__a   ,							**__a		) ->   Optional[int]:
								return super().__call__(*__a   ,							**__a		)




						def     snake_case_   (self   ,							__a   ,							__a   ,							__a		) ->   bool:
								if max_length < min_length:
										logger.warning(F"Your min_length={min_length} must be inferior than your max_length={max_length}."		)

								if input_length < max_length:
										logger.warning(
										    F"Your max_length is set to {max_length}, but your input_length is only {input_length}. Since this is "
										    "a summarization task, where outputs shorter than the input are typically wanted, you might "
										    F"consider decreasing max_length manually, e.g. summarizer('...', max_length={input_length//2})"		)





@add_end_docstrings(_lowercase )
class        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			"translation"


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a		) ->   str:
								if input_length > 0.9 * max_length:
										logger.warning(
										    F"Your input_length: {input_length} is bigger than 0.9 * max_length: {max_length}. You might consider "
										    "increasing your max_length manually, e.g. translator('...', max_length=400)"		)
								return True


						def     snake_case_   (self   ,							*__a   ,							__a=TruncationStrategy.DO_NOT_TRUNCATE   ,							__a=None   ,							__a=None		) ->   Optional[int]:
								if getattr(self.tokenizer   ,							"_build_translation_inputs"   ,							__a		):
										return self.tokenizer._build_translation_inputs(
										    *__a   ,							return_tensors=self.framework   ,							truncation=__a   ,							src_lang=__a   ,							tgt_lang=__a		)
								else:
										return super()._parse_and_tokenize(*__a   ,							truncation=__a		)


						def     snake_case_   (self   ,							__a=None   ,							__a=None   ,							**__a		) ->   int:
								UpperCamelCase   ,				UpperCamelCase   ,				UpperCamelCase   =	super()._sanitize_parameters(**__a		)
								if src_lang is not None:
										UpperCamelCase   =	src_lang
								if tgt_lang is not None:
										UpperCamelCase   =	tgt_lang
								if src_lang is None and tgt_lang is None:
										# Backward compatibility, direct arguments use is preferred.
										UpperCamelCase   =	kwargs.get("task"   ,							self.task		)
										UpperCamelCase   =	task.split("_"		)
										if task and len(__a		) == 4:
												# translation, XX, to YY
												UpperCamelCase   =	items[1]
												UpperCamelCase   =	items[3]
								return preprocess_params, forward_params, postprocess_params




						def __call__(self   ,							*__a   ,							**__a		) ->   str:
								return super().__call__(*__a   ,							**__a		)













"""simple docstring"""





def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		return number & 1 == 0


if __name__ == "__main__":
						import doctest

						doctest.testmod()






