



"""simple docstring"""
from __future__ import annotations

import unittest

from transformers import AutoTokenizer, GPTJConfig, is_tf_available
from transformers.testing_utils import require_tf, slow, tooslow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin
from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin


if is_tf_available():
						import tensorflow as tf

						from transformers.models.gptj.modeling_tf_gptj import (
						    TFGPTJForCausalLM,
						    TFGPTJForQuestionAnswering,
						    TFGPTJForSequenceClassification,
						    TFGPTJModel,
						    shape_list,
						)
class     lowerCamelCase  :






					'''simple docstring'''





					def __init__(	self:							Union[str, Any]						,					snake_case:							Tuple						)       ->     str:
											snake_case_			:Any						=      parent
											snake_case_			:str						=      13
											snake_case_			:Optional[Any]						=      7
											snake_case_			:str						=      True
											snake_case_			:str						=      True
											snake_case_			:Any						=      True
											snake_case_			:str						=      True
											snake_case_			:Dict						=      True
											snake_case_			:List[str]						=      99
											snake_case_			:Dict						=      32
											snake_case_			:List[str]						=      4
											snake_case_			:Dict						=      2
											snake_case_			:Union[str, Any]						=      4
											snake_case_			:Any						=      37
											snake_case_			:Tuple						=      """gelu"""
											snake_case_			:Dict						=      0.1
											snake_case_			:Optional[Any]						=      0.1
											snake_case_			:Optional[Any]						=      512
											snake_case_			:str						=      16
											snake_case_			:Optional[Any]						=      2
											snake_case_			:Union[str, Any]						=      0.0_2
											snake_case_			:List[Any]						=      3
											snake_case_			:int						=      4
											snake_case_			:Any						=      None
											snake_case_			:int						=      self.vocab_size - 1
											snake_case_			:Tuple						=      self.vocab_size - 1
											snake_case_			:Optional[int]						=      self.vocab_size - 1






					def        lowerCAmelCase_    (	self:							Optional[int]						)       ->     Any:
											snake_case_			:Union[str, Any]						=      ids_tensor([self.batch_size, self.seq_length]						,					self.vocab_size						)

											snake_case_			:Optional[int]						=      None
											if self.use_input_mask:
																	snake_case_			:List[Any]						=      random_attention_mask([self.batch_size, self.seq_length]						)

											snake_case_			:Optional[int]						=      None
											if self.use_token_type_ids:
																	snake_case_			:Dict						=      ids_tensor([self.batch_size, self.seq_length]						,					self.type_vocab_size						)

											snake_case_			:List[Any]						=      None
											if self.use_mc_token_ids:
																	snake_case_			:Optional[int]						=      ids_tensor([self.batch_size, self.num_choices]						,					self.seq_length						)

											snake_case_			:Any						=      None
											snake_case_			:int						=      None
											snake_case_			:int						=      None
											if self.use_labels:
																	snake_case_			:Union[str, Any]						=      ids_tensor([self.batch_size]						,					self.type_sequence_label_size						)
																	snake_case_			:str						=      ids_tensor([self.batch_size, self.seq_length]						,					self.num_labels						)
																	snake_case_			:Union[str, Any]						=      ids_tensor([self.batch_size]						,					self.num_choices						)

											snake_case_			:Tuple						=      GPTJConfig(
											    vocab_size=self.vocab_size						,					n_embd=self.hidden_size						,					n_layer=self.num_hidden_layers						,					n_head=self.num_attention_heads						,					intermediate_size=self.intermediate_size						,					hidden_act=self.hidden_act						,					hidden_dropout_prob=self.hidden_dropout_prob						,					attention_probs_dropout_prob=self.attention_probs_dropout_prob						,					n_positions=self.max_position_embeddings						,					type_vocab_size=self.type_vocab_size						,					initializer_range=self.initializer_range						,					bos_token_id=self.bos_token_id						,					eos_token_id=self.eos_token_id						,					pad_token_id=self.pad_token_id						,					rotary_dim=self.rotary_dim						,					return_dict=snake_case						,					)

											snake_case_			:List[Any]						=      ids_tensor([self.num_hidden_layers, self.num_attention_heads]						,					2						)

											return (
											    config,
											    input_ids,
											    input_mask,
											    head_mask,
											    token_type_ids,
											    mc_token_ids,
											    sequence_labels,
											    token_labels,
											    choice_labels,
											)






					def        lowerCAmelCase_    (	self:							Union[str, Any]						,					snake_case:							List[Any]						,					snake_case:							List[Any]						,					snake_case:							Union[str, Any]						,					snake_case:							str						,					snake_case:							Union[str, Any]						,					*snake_case:							Dict						)       ->     Tuple:
											snake_case_			:List[str]						=      TFGPTJModel(config=snake_case						)
											snake_case_			:Union[str, Any]						=      {
											    """input_ids""": input_ids,
											    """attention_mask""": input_mask,
											    """token_type_ids""": token_type_ids,
											}
											snake_case_			:Optional[Any]						=      model(snake_case						)

											snake_case_			:str						=      [input_ids, None, input_mask]  # None is the input for 'past'
											snake_case_			:str						=      model(snake_case						)

											snake_case_			:Any						=      model(snake_case						)

											self.parent.assertEqual(result.last_hidden_state.shape						,					(self.batch_size, self.seq_length, self.hidden_size)						)






					def        lowerCAmelCase_    (	self:							Optional[int]						,					snake_case:							Optional[Any]						,					snake_case:							Any						,					snake_case:							Optional[Any]						,					snake_case:							Optional[int]						,					snake_case:							Optional[Any]						,					*snake_case:							Optional[Any]						)       ->     int:
											snake_case_			:Any						=      TFGPTJModel(config=snake_case						)

											# first forward pass
											snake_case_			:Optional[int]						=      model(snake_case						,					token_type_ids=snake_case						,					use_cache=snake_case						)
											snake_case_			:Optional[int]						=      model(snake_case						,					token_type_ids=snake_case						)
											snake_case_			:List[Any]						=      model(snake_case						,					token_type_ids=snake_case						,					use_cache=snake_case						)

											self.parent.assertTrue(len(snake_case						) == len(snake_case						)						)
											self.parent.assertTrue(len(snake_case						) == len(snake_case						) + 1						)

											snake_case_,	snake_case_			:Any						=      outputs.to_tuple()

											# create hypothetical next token and extent to next_input_ids
											snake_case_			:Optional[Any]						=      ids_tensor((self.batch_size, 1)						,					config.vocab_size						)
											snake_case_			:Tuple						=      ids_tensor([self.batch_size, 1]						,					self.type_vocab_size						)

											# append to next input_ids and token_type_ids
											snake_case_			:Tuple						=      tf.concat([input_ids, next_tokens]						,					axis=-1						)
											snake_case_			:Dict						=      tf.concat([token_type_ids, next_token_types]						,					axis=-1						)

											snake_case_			:List[str]						=      model(snake_case						,					token_type_ids=snake_case						)["""last_hidden_state"""]
											snake_case_			:Any						=      model(snake_case						,					token_type_ids=snake_case						,					past_key_values=snake_case						)[
											    """last_hidden_state"""
											]

											# select random slice
											snake_case_			:str						=      int(ids_tensor((1,)						,					shape_list(snake_case						)[-1]						)						)
											snake_case_			:Tuple						=      output_from_no_past[:, -1, random_slice_idx]
											snake_case_			:Dict						=      output_from_past[:, 0, random_slice_idx]

											# test that outputs are equal for slice
											tf.debugging.assert_near(snake_case						,					snake_case						,					rtol=1E-6						)






					def        lowerCAmelCase_    (	self:							int						,					snake_case:							Any						,					snake_case:							Union[str, Any]						,					snake_case:							List[str]						,					snake_case:							List[str]						,					snake_case:							List[str]						,					*snake_case:							Union[str, Any]						)       ->     Union[str, Any]:
											snake_case_			:List[str]						=      TFGPTJModel(config=snake_case						)

											# create attention mask
											snake_case_			:Dict						=      self.seq_length // 2
											snake_case_			:Optional[int]						=      tf.ones((self.batch_size, half_seq_length)						,					dtype=tf.intaa						)
											snake_case_			:Optional[Any]						=      tf.zeros((self.batch_size, self.seq_length - half_seq_length)						,					dtype=tf.intaa						)
											snake_case_			:Union[str, Any]						=      tf.concat([attn_mask_begin, attn_mask_end]						,					axis=1						)

											# first forward pass
											snake_case_,	snake_case_			:Dict						=      model(snake_case						,					attention_mask=snake_case						).to_tuple()

											# create hypothetical next token and extent to next_input_ids
											snake_case_			:Optional[Any]						=      ids_tensor((self.batch_size, 1)						,					config.vocab_size						)

											# change a random masked slice from input_ids
											snake_case_			:Optional[Any]						=      ids_tensor((1,)						,					snake_case						).numpy() + 1
											snake_case_			:Optional[Any]						=      ids_tensor((self.batch_size, self.seq_length)						,					config.vocab_size						)
											snake_case_			:Union[str, Any]						=      tf.range(self.seq_length						) == (self.seq_length - random_seq_idx_to_change)
											snake_case_			:str						=      tf.transpose(
											    tf.broadcast_to(tf.expand_dims(snake_case						,					-1						)						,					(self.seq_length, self.batch_size)						)						)
											snake_case_			:Dict						=      tf.where(snake_case						,					snake_case						,					snake_case						)

											# append to next input_ids and attn_mask
											snake_case_			:List[str]						=      tf.concat([input_ids, next_tokens]						,					axis=-1						)
											snake_case_			:Union[str, Any]						=      tf.concat([attn_mask, tf.ones((shape_list(snake_case						)[0], 1)						,					dtype=tf.intaa						)]						,					axis=1						)

											# get two different outputs
											snake_case_			:Tuple						=      model(snake_case						,					attention_mask=snake_case						)["""last_hidden_state"""]
											snake_case_			:str						=      model(snake_case						,					past_key_values=snake_case						,					attention_mask=snake_case						)[
											    """last_hidden_state"""
											]

											# select random slice
											snake_case_			:List[Any]						=      int(ids_tensor((1,)						,					shape_list(snake_case						)[-1]						)						)
											snake_case_			:Dict						=      output_from_no_past[:, -1, random_slice_idx]
											snake_case_			:Optional[int]						=      output_from_past[:, 0, random_slice_idx]

											# test that outputs are equal for slice
											tf.debugging.assert_near(snake_case						,					snake_case						,					rtol=1E-12						)






					def        lowerCAmelCase_    (	self:							Optional[Any]						,					snake_case:							List[str]						,					snake_case:							Any						,					snake_case:							int						,					snake_case:							Optional[int]						,					snake_case:							str						,					*snake_case:							Optional[int]						)       ->     Any:
											snake_case_			:Optional[int]						=      TFGPTJModel(config=snake_case						)

											snake_case_			:Optional[Any]						=      input_ids[:1, :]
											snake_case_			:List[str]						=      input_mask[:1, :]
											snake_case_			:Union[str, Any]						=      token_type_ids[:1, :]
											snake_case_			:List[str]						=      1

											# first forward pass
											snake_case_			:Optional[int]						=      model(snake_case						,					attention_mask=snake_case						,					token_type_ids=snake_case						,					use_cache=snake_case						)

											snake_case_,	snake_case_			:int						=      outputs.to_tuple()

											# create hypothetical next token and extent to next_input_ids
											snake_case_			:Optional[Any]						=      ids_tensor((self.batch_size, 3)						,					config.vocab_size						)
											snake_case_			:List[str]						=      ids_tensor((self.batch_size, 3)						,					2						)
											snake_case_			:List[Any]						=      ids_tensor((self.batch_size, 3)						,					self.type_vocab_size						)

											# append to next input_ids and token_type_ids
											snake_case_			:Dict						=      tf.concat([input_ids, next_tokens]						,					axis=-1						)
											snake_case_			:Dict						=      tf.concat([input_mask, next_attn_mask]						,					axis=-1						)
											snake_case_			:Any						=      tf.concat([token_type_ids, next_token_types]						,					axis=-1						)

											snake_case_			:int						=      model(
											    snake_case						,					token_type_ids=snake_case						,					attention_mask=snake_case						)["""last_hidden_state"""]
											snake_case_			:int						=      model(
											    snake_case						,					token_type_ids=snake_case						,					attention_mask=snake_case						,					past_key_values=snake_case						,					)["""last_hidden_state"""]
											self.parent.assertTrue(output_from_past.shape[1] == next_tokens.shape[1]						)

											# select random slice
											snake_case_			:Dict						=      int(ids_tensor((1,)						,					shape_list(snake_case						)[-1]						)						)
											snake_case_			:Optional[Any]						=      output_from_no_past[:, -3:, random_slice_idx]
											snake_case_			:int						=      output_from_past[:, :, random_slice_idx]

											# test that outputs are equal for slice
											tf.debugging.assert_near(snake_case						,					snake_case						,					rtol=1E-3						)






					def        lowerCAmelCase_    (	self:							Union[str, Any]						,					snake_case:							List[str]						,					snake_case:							List[Any]						,					snake_case:							Optional[int]						,					snake_case:							Dict						,					snake_case:							Union[str, Any]						,					*snake_case:							Any						)       ->     Tuple:
											snake_case_			:Union[str, Any]						=      TFGPTJForCausalLM(config=snake_case						)
											snake_case_			:List[str]						=      {
											    """input_ids""": input_ids,
											    """attention_mask""": input_mask,
											    """token_type_ids""": token_type_ids,
											}
											snake_case_			:Any						=      model(snake_case						)
											self.parent.assertEqual(result.logits.shape						,					(self.batch_size, self.seq_length, self.vocab_size)						)






					def        lowerCAmelCase_    (	self:							List[str]						)       ->     int:
											snake_case_			:List[Any]						=      self.prepare_config_and_inputs()

											(
											    (
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	(
											    snake_case_
											),	
											)			:Tuple						=      config_and_inputs

											snake_case_			:Tuple						=      {
											    """input_ids""": input_ids,
											    """token_type_ids""": token_type_ids,
											    """attention_mask""": input_mask,
											}
											return config, inputs_dict

@require_tf
class     lowerCamelCase  (      _lowerCAmelCase   ,						_lowerCAmelCase   ,						_lowerCAmelCase   ,						unittest.TestCase    ):






					'''simple docstring'''





					_A		:      str						=					(
					    (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel)
					    if is_tf_available()
					    else ()
					)

					_A		:      Union[str, Any]						=					(TFGPTJForCausalLM,) if is_tf_available() else ()
					_A		:      List[str]						=					(
					    {
					        """feature-extraction""": TFGPTJModel,
					        """question-answering""": TFGPTJForQuestionAnswering,
					        """text-classification""": TFGPTJForSequenceClassification,
					        """text-generation""": TFGPTJForCausalLM,
					        """zero-shot""": TFGPTJForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					_A		:      Optional[int]						=					False
					_A		:      Dict						=					False
					_A		:      Dict						=					False
					_A		:      str						=					False






					def        lowerCAmelCase_    (	self:							Dict						,					snake_case:							Optional[Any]						,					snake_case:							Union[str, Any]						,					snake_case:							Union[str, Any]						,					snake_case:							Dict						,					snake_case:							Dict						)       ->     Dict:
											if (
											    pipeline_test_casse_name == "QAPipelineTests"
											    and tokenizer_name is not None
											    and not tokenizer_name.endswith("""Fast"""						)
											):
																	# `QAPipelineTests` fails for a few models when the slower tokenizer are used.
																	# (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
																	# TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
																	return True

											return False






					def        lowerCAmelCase_    (	self:							List[Any]						)       ->     Dict:
											snake_case_			:Dict						=      TFGPTJModelTester(self						)
											snake_case_			:int						=      ConfigTester(self						,					config_class=snake_case						,					n_embd=37						)






					def        lowerCAmelCase_    (	self:							str						)       ->     Optional[int]:
											self.config_tester.run_common_tests()






					def        lowerCAmelCase_    (	self:							Any						)       ->     Any:
											snake_case_			:List[str]						=      self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_gptj_model(*snake_case						)






					def        lowerCAmelCase_    (	self:							Any						)       ->     Union[str, Any]:
											snake_case_			:List[Any]						=      self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_gptj_model_past(*snake_case						)






					def        lowerCAmelCase_    (	self:							Any						)       ->     Tuple:
											snake_case_			:Any						=      self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_gptj_model_attention_mask_past(*snake_case						)






					def        lowerCAmelCase_    (	self:							int						)       ->     Dict:
											snake_case_			:Dict						=      self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_gptj_model_past_large_inputs(*snake_case						)






					def        lowerCAmelCase_    (	self:							Optional[Any]						)       ->     List[Any]:
											snake_case_			:str						=      self.model_tester.prepare_config_and_inputs()
											self.model_tester.create_and_check_gptj_lm_head_model(*snake_case						)






					@slow
					@unittest.skipIf(
					    not is_tf_available() or len(tf.config.list_physical_devices("""GPU"""						)						) > 0						,					"""skip testing on GPU for now to avoid GPU OOM."""						,					)
					def        lowerCAmelCase_    (	self:							Dict						)       ->     Union[str, Any]:
											snake_case_			:Dict						=      TFGPTJModel.from_pretrained("""EleutherAI/gpt-j-6B"""						,					from_pt=snake_case						)
											self.assertIsNotNone(snake_case						)






					@unittest.skip(reason="""Currently, model embeddings are going to undergo a major refactor."""						)
					def        lowerCAmelCase_    (	self:							Optional[int]						)       ->     Union[str, Any]:
											super().test_resize_token_embeddings()

@require_tf
@tooslow
# Marked as @tooslow due to GPU OOM -- but still useful to run locally. Requires ~39GB of RAM.
class     lowerCamelCase  (      unittest.TestCase    ):






					'''simple docstring'''





					def        lowerCAmelCase_    (	self:							List[Any]						)       ->     Optional[Any]:
											snake_case_			:Optional[int]						=      TFGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""						,					from_pt=snake_case						)
											snake_case_			:List[Any]						=      tf.convert_to_tensor([[464, 3_290]]						,					dtype=tf.intaa						)  # The dog
											# fmt: off
											# The dog is a man's best friend. It is a loyal companion, and it is a friend
											snake_case_			:str						=      [464, 3_290, 318, 257, 582, 338, 1_266, 1_545, 13, 632, 318, 257, 9_112, 15_185, 11, 290, 340, 318, 257, 1_545]
											# fmt: on
											snake_case_			:str						=      model.generate(snake_case						,					do_sample=snake_case						)
											self.assertListEqual(output_ids[0].numpy().tolist()						,					snake_case						)






					def        lowerCAmelCase_    (	self:							List[str]						)       ->     str:
											snake_case_			:Dict						=      AutoTokenizer.from_pretrained("""EleutherAI/gpt-j-6B"""						,					revision="""float16"""						)
											snake_case_			:Optional[int]						=      TFGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""						,					revision="""float16"""						,					from_pt=snake_case						)

											snake_case_			:Optional[Any]						=      tokenizer("""Today is a nice day and"""						,					return_tensors="""tf"""						)
											# forces the generation to happen on CPU, to avoid GPU-related quirks
											with tf.device(""":/CPU:0"""						):
																	snake_case_			:Optional[int]						=      model.generate(**snake_case						,					do_sample=snake_case						,					seed=[42, 0]						)
											snake_case_			:int						=      tokenizer.decode(output_ids[0]						,					skip_special_tokens=snake_case						)

											snake_case_			:Dict						=      """Today is a nice day and I’m going to go for a walk. I’"""
											self.assertEqual(snake_case						,					snake_case						)






					def        lowerCAmelCase_    (	self:							Tuple						)       ->     List[Any]:
											snake_case_			:Dict						=      TFGPTJForCausalLM.from_pretrained("""EleutherAI/gpt-j-6B"""						,					revision="""float16"""						,					from_pt=snake_case						)
											snake_case_			:Dict						=      AutoTokenizer.from_pretrained("""EleutherAI/gpt-j-6B"""						,					revision="""float16"""						)

											snake_case_			:Tuple						=      """left"""

											# Define PAD Token = EOS Token = 50256
											snake_case_			:List[Any]						=      tokenizer.eos_token
											snake_case_			:List[Any]						=      model.config.eos_token_id

											# use different length sentences to test batching
											snake_case_			:List[str]						=      [
											    """Hello, my dog is a little""",
											    """Today, I""",
											]
											snake_case_			:Any						=      [
											    """Hello, my dog is a little over a year old and has been diagnosed with hip dysplasia""",
											    """Today, I’m going to be talking about a topic that’""",
											]
											return model, tokenizer, sentences, expected_output_sentences






					def        lowerCAmelCase_    (	self:							Union[str, Any]						)       ->     Optional[int]:
											# Confirms that we get the expected results with left-padded beam search
											snake_case_,	snake_case_,	snake_case_,	snake_case_			:Optional[Any]						=      self._get_beam_search_test_objects()

											snake_case_			:List[str]						=      tokenizer(snake_case						,					return_tensors="""tf"""						,					padding=snake_case						)
											snake_case_			:Any						=      model.generate(**snake_case						,					do_sample=snake_case						,					num_beams=2						)
											snake_case_			:List[Any]						=      tokenizer.batch_decode(snake_case						,					skip_special_tokens=snake_case						)
											self.assertListEqual(snake_case						,					snake_case						)






					def        lowerCAmelCase_    (	self:							Tuple						)       ->     List[str]:
											# Confirms that left-padding is working properly
											snake_case_,	snake_case_,	snake_case_,	snake_case_			:Dict						=      self._get_beam_search_test_objects()

											snake_case_			:Optional[int]						=      tokenizer(snake_case						,					return_tensors="""tf"""						,					padding=snake_case						)
											snake_case_			:Tuple						=      tokenizer(sentences[0]						,					return_tensors="""tf"""						)
											snake_case_			:Tuple						=      model.generate(**snake_case						,					do_sample=snake_case						,					num_beams=2						)
											snake_case_			:Dict						=      (
											    shape_list(inputs_non_padded["""input_ids"""]						)[-1]
											    - tf.reduce_sum(tf.cast(inputs["""attention_mask"""][-1]						,					tf.intaa						)						).numpy()
											)
											snake_case_			:Any						=      tokenizer(sentences[1]						,					return_tensors="""tf"""						)
											snake_case_			:List[Any]						=      model.generate(
											    **snake_case						,					do_sample=snake_case						,					num_beams=2						,					max_length=model.config.max_length - num_paddings						)
											snake_case_			:Optional[Any]						=      tokenizer.decode(output_non_padded[0]						,					skip_special_tokens=snake_case						)
											snake_case_			:List[Any]						=      tokenizer.decode(output_padded[0]						,					skip_special_tokens=snake_case						)
											self.assertListEqual(snake_case						,					[non_padded_sentence, padded_sentence]						)






					def        lowerCAmelCase_    (	self:							Union[str, Any]						)       ->     str:
											# Confirms that XLA is working properly
											snake_case_,	snake_case_,	snake_case_,	snake_case_			:Dict						=      self._get_beam_search_test_objects()

											snake_case_			:Dict						=      tokenizer(snake_case						,					return_tensors="""tf"""						,					padding=snake_case						)
											snake_case_			:Union[str, Any]						=      tf.function(model.generate						,					jit_compile=snake_case						)
											snake_case_			:Optional[int]						=      xla_generate(**snake_case						,					do_sample=snake_case						,					num_beams=2						)
											snake_case_			:List[Any]						=      tokenizer.batch_decode(snake_case						,					skip_special_tokens=snake_case						)
											self.assertListEqual(snake_case						,					snake_case						)





"""simple docstring"""
from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_sentencepiece_available, is_torch_available


__a     =    {
    "configuration_xlm_prophetnet": ["XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP", "XLMProphetNetConfig"],
}

try:
						if not is_sentencepiece_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a     =    ["XLMProphetNetTokenizer"]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a     =    [
						    "XLM_PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST",
						    "XLMProphetNetDecoder",
						    "XLMProphetNetEncoder",
						    "XLMProphetNetForCausalLM",
						    "XLMProphetNetForConditionalGeneration",
						    "XLMProphetNetModel",
						    "XLMProphetNetPreTrainedModel",
						]


if TYPE_CHECKING:
						from .configuration_xlm_prophetnet import XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMProphetNetConfig

						try:
												if not is_sentencepiece_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_xlm_prophetnet import XLMProphetNetTokenizer

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_xlm_prophetnet import (
												    XLM_PROPHETNET_PRETRAINED_MODEL_ARCHIVE_LIST,
												    XLMProphetNetDecoder,
												    XLMProphetNetEncoder,
												    XLMProphetNetForCausalLM,
												    XLMProphetNetForConditionalGeneration,
												    XLMProphetNetModel,
												    XLMProphetNetPreTrainedModel,
												)

else:
						import sys

						__a     =    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
