'''simple docstring'''


import argparse
import json
import os
from pathlib import Path

import requests
import torch

from transformers import JukeboxConfig, JukeboxModel
from transformers.utils import logging


logging.set_verbosity_info()
__lowerCAmelCase	:       int						       =	logging.get_logger(__name__)


__lowerCAmelCase	:       Any						       =	"https://openaipublic.azureedge.net/jukebox/models/"
__lowerCAmelCase	:       Optional[Any]						       =	{
    "jukebox-1b-lyrics": [
        "5b/vqvae.pth.tar",
        "5b/prior_level_0.pth.tar",
        "5b/prior_level_1.pth.tar",
        "1b_lyrics/prior_level_2.pth.tar",
    ],
    "jukebox-5b-lyrics": [
        "5b/vqvae.pth.tar",
        "5b/prior_level_0.pth.tar",
        "5b/prior_level_1.pth.tar",
        "5b_lyrics/prior_level_2.pth.tar",
    ],
}





def       lowerCAmelCase					(		UpperCamelCase__				:   int       ):


	"""simple docstring"""
	if key.endswith('''.model.1.bias'''       ) and len(key.split('''.'''       )       ) > 1_0:
		__UpperCAmelCase							=			key.replace('''.model.1.bias'''    ,					'''.conv1d_1.bias'''       )
	elif key.endswith('''.model.1.weight'''       ) and len(key.split('''.'''       )       ) > 1_0:
		__UpperCAmelCase							=			key.replace('''.model.1.weight'''    ,					'''.conv1d_1.weight'''       )
	elif key.endswith('''.model.3.bias'''       ) and len(key.split('''.'''       )       ) > 1_0:
		__UpperCAmelCase							=			key.replace('''.model.3.bias'''    ,					'''.conv1d_2.bias'''       )
	elif key.endswith('''.model.3.weight'''       ) and len(key.split('''.'''       )       ) > 1_0:
		__UpperCAmelCase							=			key.replace('''.model.3.weight'''    ,					'''.conv1d_2.weight'''       )

	if "conditioner_blocks.0." in key:
		__UpperCAmelCase							=			key.replace('''conditioner_blocks.0'''    ,					'''conditioner_blocks'''       )

	if "prime_prior" in key:
		__UpperCAmelCase							=			key.replace('''prime_prior'''    ,					'''encoder'''       )

	if ".emb." in key and "total" not in key and "absolute" not in key and "relative" not in key:
		__UpperCAmelCase							=			key.replace('''.emb.'''    ,					'''.'''       )

	if key.endswith('''k'''       ):  # replace vqvae.X.k with vqvae.X.codebook
		return key.replace('''.k'''    ,					'''.codebook'''       )
	if "y_emb." in key:
		return key.replace('''y_emb.'''    ,					'''metadata_embedding.'''       )

	if "x_emb.emb." in key:
		__UpperCAmelCase							=			key.replace('''0.x_emb.emb'''    ,					'''embed_tokens'''       )

	if "prime_state_ln" in key:
		return key.replace('''prime_state_ln'''    ,					'''encoder.final_layer_norm'''       )
	if ".ln" in key:
		return key.replace('''.ln'''    ,					'''.layer_norm'''       )
	if "_ln" in key:
		return key.replace('''_ln'''    ,					'''_layer_norm'''       )

	if "prime_state_proj" in key:
		return key.replace('''prime_state_proj'''    ,					'''encoder.proj_in'''       )
	if "prime_x_out" in key:
		return key.replace('''prime_x_out'''    ,					'''encoder.lm_head'''       )
	if "prior.x_out" in key:
		return key.replace('''x_out'''    ,					'''fc_proj_out'''       )
	if "x_emb" in key:
		return key.replace('''x_emb'''    ,					'''embed_tokens'''       )

	return key





def       lowerCAmelCase					(		UpperCamelCase__				:   str    ,					UpperCamelCase__				:   Optional[Any]    ,					UpperCamelCase__				:   List[Any]    ,					UpperCamelCase__				:   List[str]       ):


	"""simple docstring"""
	__UpperCAmelCase							=			{}
	import re

	__UpperCAmelCase							=			re.compile(R'''encoders.(\d*).level_blocks.(\d*).model.(\d*).(\d).(bias|weight)'''       )
	__UpperCAmelCase							=			re.compile(
	    R'''encoders.(\d*).level_blocks.(\d*).model.(\d*).(\d).model.(\d*).model.(\d*).(bias|weight)'''       )
	__UpperCAmelCase							=			re.compile(R'''encoders.(\d*).level_blocks.(\d*).model.(\d*).(bias|weight)'''       )

	__UpperCAmelCase							=			re.compile(R'''decoders.(\d*).level_blocks.(\d*).model.(\d*).(\d).(bias|weight)'''       )
	__UpperCAmelCase							=			re.compile(
	    R'''decoders.(\d*).level_blocks.(\d*).model.(\d*).(\d).model.(\d*).model.(\d*).(bias|weight)'''       )
	__UpperCAmelCase							=			re.compile(R'''decoders.(\d*).level_blocks.(\d*).model.(\d*).(bias|weight)'''       )

	__UpperCAmelCase							=			re.compile(R'''conditioner_blocks.(\d*).cond.model.(\d*).(\d).(bias|weight)'''       )
	__UpperCAmelCase							=			re.compile(
	    R'''conditioner_blocks.(\d*).cond.model.(\d*).(\d).model.(\d*).model.(\d*).(bias|weight)'''       )
	__UpperCAmelCase							=			re.compile(R'''conditioner_blocks.(\d*).cond.model.(\d*).(bias|weight)'''       )

	for original_key, value in state_dict.items():
		# rename vqvae.encoder keys
		if re_encoder_block_conv_in.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_encoder_block_conv_in.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			int(groups[2]       ) * 2 + int(groups[3]       )
			__UpperCAmelCase							=			f"""encoders.{groups[0]}.level_blocks.{groups[1]}.downsample_block.{block_index}.{groups[-1]}"""
			__UpperCAmelCase							=			re_encoder_block_conv_in.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		elif re_encoder_block_resnet.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_encoder_block_resnet.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			int(groups[2]       ) * 2 + int(groups[3]       )
			__UpperCAmelCase							=			{'''1''': 1, '''3''': 2}[groups[-2]]
			__UpperCAmelCase							=			f"""encoders.{groups[0]}.level_blocks.{groups[1]}.downsample_block.{block_index}."""
			__UpperCAmelCase							=			f"""resnet_block.{groups[-3]}.conv1d_{conv_index}.{groups[-1]}"""
			__UpperCAmelCase							=			prefix + resnet_block
			__UpperCAmelCase							=			re_encoder_block_resnet.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		elif re_encoder_block_proj_out.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_encoder_block_proj_out.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			f"""encoders.{groups[0]}.level_blocks.{groups[1]}.proj_out.{groups[-1]}"""
			__UpperCAmelCase							=			re_encoder_block_proj_out.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		# rename vqvae.decoder keys
		elif re_decoder_block_conv_out.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_decoder_block_conv_out.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			int(groups[2]       ) * 2 + int(groups[3]       ) - 2
			__UpperCAmelCase							=			f"""decoders.{groups[0]}.level_blocks.{groups[1]}.upsample_block.{block_index}.{groups[-1]}"""
			__UpperCAmelCase							=			re_decoder_block_conv_out.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		elif re_decoder_block_resnet.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_decoder_block_resnet.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			int(groups[2]       ) * 2 + int(groups[3]       ) - 2
			__UpperCAmelCase							=			{'''1''': 1, '''3''': 2}[groups[-2]]
			__UpperCAmelCase							=			f"""decoders.{groups[0]}.level_blocks.{groups[1]}.upsample_block.{block_index}."""
			__UpperCAmelCase							=			f"""resnet_block.{groups[-3]}.conv1d_{conv_index}.{groups[-1]}"""
			__UpperCAmelCase							=			prefix + resnet_block
			__UpperCAmelCase							=			re_decoder_block_resnet.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		elif re_decoder_block_proj_in.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_decoder_block_proj_in.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			f"""decoders.{groups[0]}.level_blocks.{groups[1]}.proj_in.{groups[-1]}"""
			__UpperCAmelCase							=			re_decoder_block_proj_in.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		# rename prior cond.model to upsampler.upsample_block and resnet
		elif re_prior_cond_conv_out.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_prior_cond_conv_out.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			int(groups[1]       ) * 2 + int(groups[2]       ) - 2
			__UpperCAmelCase							=			f"""conditioner_blocks.upsampler.upsample_block.{block_index}.{groups[-1]}"""
			__UpperCAmelCase							=			re_prior_cond_conv_out.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		elif re_prior_cond_resnet.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_prior_cond_resnet.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			int(groups[1]       ) * 2 + int(groups[2]       ) - 2
			__UpperCAmelCase							=			{'''1''': 1, '''3''': 2}[groups[-2]]
			__UpperCAmelCase							=			f"""conditioner_blocks.upsampler.upsample_block.{block_index}."""
			__UpperCAmelCase							=			f"""resnet_block.{groups[-3]}.conv1d_{conv_index}.{groups[-1]}"""
			__UpperCAmelCase							=			prefix + resnet_block
			__UpperCAmelCase							=			re_prior_cond_resnet.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		elif re_prior_cond_proj_in.fullmatch(UpperCamelCase__       ):
			__UpperCAmelCase							=			re_prior_cond_proj_in.match(UpperCamelCase__       )
			__UpperCAmelCase							=			regex_match.groups()
			__UpperCAmelCase							=			f"""conditioner_blocks.upsampler.proj_in.{groups[-1]}"""
			__UpperCAmelCase							=			re_prior_cond_proj_in.sub(UpperCamelCase__    ,					UpperCamelCase__       )

		# keep original key
		else:
			__UpperCAmelCase							=			original_key

		__UpperCAmelCase							=			replace_key(UpperCamelCase__       )

		if f"""{key_prefix}.{key}""" not in model_state_dict or key is None:
			print(f"""failed converting {original_key} to {key}, does not match"""       )

		# handle missmatched shape
		elif value.shape != model_state_dict[f"""{key_prefix}.{key}"""].shape:
			__UpperCAmelCase							=			model_state_dict[f"""{key_prefix}.{key}"""]
			print(f"""{original_key}-> {key} : \nshape {val.shape} and { value.shape}, do not match"""       )
			__UpperCAmelCase							=			original_key

		__UpperCAmelCase							=			original_key
		__UpperCAmelCase							=			value

	return new_dict





@torch.no_grad()
def       lowerCAmelCase					(		UpperCamelCase__				:   Tuple=None    ,					UpperCamelCase__				:   List[Any]=None       ):


	"""simple docstring"""
	for file in MODEL_MAPPING[model_name]:
		if not os.path.isfile(f"""{pytorch_dump_folder_path}/{file.split('/'       )[-1]}"""       ):
			__UpperCAmelCase							=			requests.get(f"""{PREFIX}{file}"""    ,					allow_redirects=UpperCamelCase__       )
			os.makedirs(f"""{pytorch_dump_folder_path}/"""    ,					exist_ok=UpperCamelCase__       )
			open(f"""{pytorch_dump_folder_path}/{file.split('/'       )[-1]}"""    ,					'''wb'''       ).write(r.content       )

	__UpperCAmelCase							=			MODEL_MAPPING[model_name.split('''/'''       )[-1]]

	__UpperCAmelCase							=			JukeboxConfig.from_pretrained(UpperCamelCase__       )
	__UpperCAmelCase							=			JukeboxModel(UpperCamelCase__       )

	__UpperCAmelCase							=			[]
	__UpperCAmelCase							=			{}
	for i, dict_name in enumerate(UpperCamelCase__       ):
		__UpperCAmelCase							=			torch.load(f"""{pytorch_dump_folder_path}/{dict_name.split('/'       )[-1]}"""       )['''model''']

		__UpperCAmelCase							=			{}
		for k in old_dic.keys():
			if k.endswith('''.b'''       ):
				__UpperCAmelCase							=			old_dic[k]
			elif k.endswith('''.w'''       ):
				__UpperCAmelCase							=			old_dic[k]
			elif "level_2" not in dict_name and "cond.model." in k:
				__UpperCAmelCase							=			old_dic[k]
			else:
				__UpperCAmelCase							=			old_dic[k]

		__UpperCAmelCase							=			'''vqvae''' if i == 0 else f"""priors.{3 - i}"""
		__UpperCAmelCase							=			fix_jukebox_keys(UpperCamelCase__    ,					model.state_dict()    ,					UpperCamelCase__    ,					UpperCamelCase__       )
		weight_dict.append(UpperCamelCase__       )

	__UpperCAmelCase							=			weight_dict.pop(0       )
	model.vqvae.load_state_dict(UpperCamelCase__       )
	for i in range(len(UpperCamelCase__       )       ):
		model.priors[i].load_state_dict(weight_dict[2 - i]       )

	Path(UpperCamelCase__       ).mkdir(exist_ok=UpperCamelCase__       )
	with open(f"""{pytorch_dump_folder_path}/mapping.json"""    ,					'''w'''       ) as txtfile:
		json.dump(UpperCamelCase__    ,					UpperCamelCase__       )

	print(f"""Saving model {model_name} to {pytorch_dump_folder_path}"""       )
	model.save_pretrained(UpperCamelCase__       )

	return weight_dict


if __name__ == "__main__":
					__lowerCAmelCase	:       Union[str, Any]						       =	argparse.ArgumentParser()
					# Required parameters
					parser.add_argument(
					    "--model_name",
					    default="jukebox-5b-lyrics",
					    type=str,
					    help="Name of the model you'd like to convert.",
					)
					parser.add_argument(
					    "--pytorch_dump_folder_path",
					    default="jukebox-5b-lyrics-converted",
					    type=str,
					    help="Path to the output PyTorch model directory.",
					)
					__lowerCAmelCase	:       Any						       =	parser.parse_args()
					convert_openai_checkpoint(args.model_name, args.pytorch_dump_folder_path)

'''simple docstring'''


from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

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


if is_tf_available():
					import tensorflow as tf

					from transformers.models.distilbert.modeling_tf_distilbert import (
					    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
					    TFDistilBertForMaskedLM,
					    TFDistilBertForMultipleChoice,
					    TFDistilBertForQuestionAnswering,
					    TFDistilBertForSequenceClassification,
					    TFDistilBertForTokenClassification,
					    TFDistilBertModel,
					)






class 						A   :





							def __init__(      self				:							List[Any]     ,		__a				:							Any     ,		)							->	Dict:
								__UpperCAmelCase							=			parent
								__UpperCAmelCase							=			1_3
								__UpperCAmelCase							=			7
								__UpperCAmelCase							=			True
								__UpperCAmelCase							=			True
								__UpperCAmelCase							=			False
								__UpperCAmelCase							=			True
								__UpperCAmelCase							=			9_9
								__UpperCAmelCase							=			3_2
								__UpperCAmelCase							=			2
								__UpperCAmelCase							=			4
								__UpperCAmelCase							=			3_7
								__UpperCAmelCase							=			'''gelu'''
								__UpperCAmelCase							=			0.1
								__UpperCAmelCase							=			0.1
								__UpperCAmelCase							=			5_1_2
								__UpperCAmelCase							=			1_6
								__UpperCAmelCase							=			2
								__UpperCAmelCase							=			0.0_2
								__UpperCAmelCase							=			3
								__UpperCAmelCase							=			4
								__UpperCAmelCase							=			None





							def       snake_case__						(      self				:							Optional[int]	)							->	Dict:
								__UpperCAmelCase							=			ids_tensor([self.batch_size, self.seq_length]     ,		self.vocab_size	)

								__UpperCAmelCase							=			None
								if self.use_input_mask:
									__UpperCAmelCase							=			random_attention_mask([self.batch_size, self.seq_length]	)

								__UpperCAmelCase							=			None
								__UpperCAmelCase							=			None
								__UpperCAmelCase							=			None
								if self.use_labels:
									__UpperCAmelCase							=			ids_tensor([self.batch_size]     ,		self.type_sequence_label_size	)
									__UpperCAmelCase							=			ids_tensor([self.batch_size, self.seq_length]     ,		self.num_labels	)
									__UpperCAmelCase							=			ids_tensor([self.batch_size]     ,		self.num_choices	)

								__UpperCAmelCase							=			DistilBertConfig(
								    vocab_size=self.vocab_size     ,		dim=self.hidden_size     ,		n_layers=self.num_hidden_layers     ,		n_heads=self.num_attention_heads     ,		hidden_dim=self.intermediate_size     ,		hidden_act=self.hidden_act     ,		dropout=self.hidden_dropout_prob     ,		attention_dropout=self.attention_probs_dropout_prob     ,		max_position_embeddings=self.max_position_embeddings     ,		initializer_range=self.initializer_range     ,		)

								return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels





							def       snake_case__						(      self				:							Union[str, Any]     ,		__a				:							List[str]     ,		__a				:							int     ,		__a				:							Union[str, Any]     ,		__a				:							Union[str, Any]     ,		__a				:							List[Any]     ,		__a				:							int	)							->	Any:
								__UpperCAmelCase							=			TFDistilBertModel(config=__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}

								__UpperCAmelCase							=			model(__a	)

								__UpperCAmelCase							=			[input_ids, input_mask]

								__UpperCAmelCase							=			model(__a	)

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





							def       snake_case__						(      self				:							Tuple     ,		__a				:							List[Any]     ,		__a				:							int     ,		__a				:							Tuple     ,		__a				:							List[Any]     ,		__a				:							Union[str, Any]     ,		__a				:							List[Any]	)							->	int:
								__UpperCAmelCase							=			TFDistilBertForMaskedLM(config=__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.vocab_size)	)





							def       snake_case__						(      self				:							Optional[int]     ,		__a				:							Any     ,		__a				:							Union[str, Any]     ,		__a				:							Optional[int]     ,		__a				:							int     ,		__a				:							Optional[Any]     ,		__a				:							Optional[int]	)							->	Dict:
								__UpperCAmelCase							=			TFDistilBertForQuestionAnswering(config=__a	)
								__UpperCAmelCase							=			{
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.start_logits.shape     ,		(self.batch_size, self.seq_length)	)
								self.parent.assertEqual(result.end_logits.shape     ,		(self.batch_size, self.seq_length)	)





							def       snake_case__						(      self				:							Any     ,		__a				:							Optional[Any]     ,		__a				:							List[str]     ,		__a				:							Dict     ,		__a				:							Dict     ,		__a				:							int     ,		__a				:							List[Any]	)							->	Dict:
								__UpperCAmelCase							=			self.num_labels
								__UpperCAmelCase							=			TFDistilBertForSequenceClassification(__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_labels)	)





							def       snake_case__						(      self				:							Union[str, Any]     ,		__a				:							int     ,		__a				:							str     ,		__a				:							Union[str, Any]     ,		__a				:							Optional[int]     ,		__a				:							List[str]     ,		__a				:							Dict	)							->	str:
								__UpperCAmelCase							=			self.num_choices
								__UpperCAmelCase							=			TFDistilBertForMultipleChoice(__a	)
								__UpperCAmelCase							=			tf.tile(tf.expand_dims(__a     ,		1	)     ,		(1, self.num_choices, 1)	)
								__UpperCAmelCase							=			tf.tile(tf.expand_dims(__a     ,		1	)     ,		(1, self.num_choices, 1)	)
								__UpperCAmelCase							=			{
								    '''input_ids''': multiple_choice_inputs_ids,
								    '''attention_mask''': multiple_choice_input_mask,
								}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.num_choices)	)





							def       snake_case__						(      self				:							int     ,		__a				:							Optional[Any]     ,		__a				:							int     ,		__a				:							Tuple     ,		__a				:							int     ,		__a				:							Optional[int]     ,		__a				:							Optional[int]	)							->	int:
								__UpperCAmelCase							=			self.num_labels
								__UpperCAmelCase							=			TFDistilBertForTokenClassification(__a	)
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								__UpperCAmelCase							=			model(__a	)
								self.parent.assertEqual(result.logits.shape     ,		(self.batch_size, self.seq_length, self.num_labels)	)






							def       snake_case__						(      self				:							str	)							->	Any:
								__UpperCAmelCase							=			self.prepare_config_and_inputs()
								((__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase)				,			(__UpperCAmelCase))							=			config_and_inputs
								__UpperCAmelCase							=			{'''input_ids''': input_ids, '''attention_mask''': input_mask}
								return config, inputs_dict






@require_tf
class 						A   (   UpperCAmelCase       ,	UpperCAmelCase       ,	unittest.TestCase   ):
							a_        =      (
							    (
							        TFDistilBertModel,
							        TFDistilBertForMaskedLM,
							        TFDistilBertForQuestionAnswering,
							        TFDistilBertForSequenceClassification,
							        TFDistilBertForTokenClassification,
							        TFDistilBertForMultipleChoice,
							    )
							    if is_tf_available()
							    else None
							)
							a_        =      (
							    {
							        '''feature-extraction''': TFDistilBertModel,
							        '''fill-mask''': TFDistilBertForMaskedLM,
							        '''question-answering''': TFDistilBertForQuestionAnswering,
							        '''text-classification''': TFDistilBertForSequenceClassification,
							        '''token-classification''': TFDistilBertForTokenClassification,
							        '''zero-shot''': TFDistilBertForSequenceClassification,
							    }
							    if is_tf_available()
							    else {}
							)
							a_        =      False
							a_        =      False





							def       snake_case__						(      self				:							Any	)							->	Any:
								__UpperCAmelCase							=			TFDistilBertModelTester(self	)
								__UpperCAmelCase							=			ConfigTester(self     ,		config_class=__a     ,		dim=3_7	)





							def       snake_case__						(      self				:							List[Any]	)							->	Optional[int]:
								self.config_tester.run_common_tests()





							def       snake_case__						(      self				:							Any	)							->	str:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_model(*__a	)





							def       snake_case__						(      self				:							Tuple	)							->	Dict:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_masked_lm(*__a	)





							def       snake_case__						(      self				:							Union[str, Any]	)							->	Any:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_question_answering(*__a	)





							def       snake_case__						(      self				:							Optional[Any]	)							->	Dict:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_sequence_classification(*__a	)





							def       snake_case__						(      self				:							Any	)							->	int:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_multiple_choice(*__a	)





							def       snake_case__						(      self				:							List[str]	)							->	List[Any]:
								__UpperCAmelCase							=			self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_token_classification(*__a	)






							@slow
							def       snake_case__						(      self				:							Dict	)							->	Tuple:
								for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]	):
									__UpperCAmelCase							=			TFDistilBertModel.from_pretrained(__a	)
									self.assertIsNotNone(__a	)






@require_tf
class 						A   (   unittest.TestCase   ):





							@slow
							def       snake_case__						(      self				:							int	)							->	Dict:
								__UpperCAmelCase							=			TFDistilBertModel.from_pretrained('''distilbert-base-uncased'''	)
								__UpperCAmelCase							=			tf.constant([[0, 1, 2, 3, 4, 5]]	)
								__UpperCAmelCase							=			model(__a	)[0]

								__UpperCAmelCase							=			[1, 6, 7_6_8]
								self.assertEqual(output.shape     ,		__a	)

								__UpperCAmelCase							=			tf.constant(
								    [
								        [
								            [0.1_9_2_6_1_8_8_5, -0.1_3_7_3_2_9_5_5, 0.4_1_1_9_7_9_9],
								            [0.2_2_1_5_0_1_5_6, -0.0_7_4_2_2_6_6_1, 0.3_9_0_3_7_2_0_4],
								            [0.2_2_7_5_6_0_1_8, -0.0_8_9_6_4_1_4, 0.3_7_0_1_4_6_7],
								        ]
								    ]	)
								tf.debugging.assert_near(output[:, :3, :3]     ,		__a     ,		atol=1e-4	)
