
"""simple docstring"""





import os
import posixpath
import uuid
from dataclasses import dataclass
from typing import TYPE_CHECKING, Iterable, List, Optional, Tuple, Union

import numpy as np
import pyarrow as pa

import datasets
from datasets.arrow_writer import ArrowWriter, ParquetWriter
from datasets.config import MAX_SHARD_SIZE
from datasets.filesystems import (
    is_remote_filesystem,
    rename,
)
from datasets.iterable_dataset import _BaseExamplesIterable
from datasets.utils.py_utils import convert_file_size_to_int


UpperCamelCase_       :    Dict						      =			datasets.utils.logging.get_logger(__name__)

if TYPE_CHECKING:
		import pyspark



@dataclass
class __lowerCAmelCase					(       datasets.BuilderConfig   ):




			"""simple docstring"""







			snake_case						   =					None





def 				A_  (__a					, __a					, ):

					'''simple docstring'''





					import pyspark

					def generate_fn():
										A_								=    df.select("*"					, pyspark.sql.functions.spark_partition_id().alias("part_id"					)					)
										for partition_id in partition_order:
															A_								=    df_with_partition_id.select("*"					).where(f'part_id = {partition_id}'					).drop("part_id"					)
															A_								=    partition_df.collect()
															A_								=    0
															for row in rows:
																				yield f'{partition_id}_{row_id}', row.asDict()
																				row_id += 1

					return generate_fn



class __lowerCAmelCase					(       _BaseExamplesIterable   ):




			"""simple docstring"""







			def __init__(					self    :       Dict							, _snake_case    :       "pyspark.sql.DataFrame"							, _snake_case    :       str=None							, )   ->			List[str]:







								"""simple docstring"""
								A_								=    df
								A_								=    partition_order or range(self.df.rdd.getNumPartitions()						)
								A_								=    _generate_iterable_examples(self.df							, self.partition_order						)




			def __iter__(					self    :       Optional[int]						)   ->			int:







								"""simple docstring"""
								yield from self.generate_examples_fn()




			def   lowerCamelCase__  (					self    :       int							, _snake_case    :       np.random.Generator						)   ->			Optional[int]:







								"""simple docstring"""
								A_								=    list(range(self.df.rdd.getNumPartitions()						)						)
								generator.shuffle(_snake_case						)
								return SparkExamplesIterable(self.df							, partition_order=_snake_case						)




			def   lowerCamelCase__  (					self    :       Any							, _snake_case    :       int							, _snake_case    :       int						)   ->			Optional[Any]:







								"""simple docstring"""
								A_								=    self.split_shard_indices_by_worker(_snake_case							, _snake_case						)
								return SparkExamplesIterable(self.df							, partition_order=_snake_case						)






			@property
			def   lowerCamelCase__  (					self    :       Any						)   ->			Any:







								"""simple docstring"""
								return len(self.partition_order						)





class __lowerCAmelCase					(       datasets.DatasetBuilder   ):




			"""simple docstring"""







			snake_case						   =					SparkConfig




			def __init__(					self    :       List[Any]							, _snake_case    :       "pyspark.sql.DataFrame"							, _snake_case    :       str = None							, _snake_case    :       str = None							, **_snake_case    :       Union[str, Any]							, )   ->			List[str]:







								"""simple docstring"""
								import pyspark

								A_								=    pyspark.sql.SparkSession.builder.getOrCreate()
								A_								=    df
								A_								=    working_dir

								super().__init__(
								    cache_dir=_snake_case							, config_name=str(self.df.semanticHash()						)							, **_snake_case							, )




			def   lowerCamelCase__  (					self    :       Union[str, Any]						)   ->			int:







								"""simple docstring"""
								# Returns the path of the created file.
								def create_cache_and_write_probe(_snake_case    :       Any						):
													# makedirs with exist_ok will recursively create the directory. It will not throw an error if directories
													# already exist.
													os.makedirs(self._cache_dir							, exist_ok=_snake_case						)
													A_								=    os.path.join(self._cache_dir							, "fs_test" + uuid.uuida().hex						)
													# Opening the file in append mode will create a new file unless it already exists, in which case it will not
													# change the file contents.
													open(_snake_case							, "a"						)
													return [probe_file]

								if self._spark.conf.get("spark.master"							, ""						).startswith("local"						):
													return

								# If the cluster is multi-node, make sure that the user provided a cache_dir and that it is on an NFS
								# accessible to the driver.
								# TODO: Stream batches to the driver using ArrowCollectSerializer instead of throwing an error.
								if self._cache_dir:
													A_								=    (
													    self._spark.sparkContext.parallelize(range(1						)							, 1						).mapPartitions(_snake_case						).collect()
													)
													if os.path.isfile(probe[0]						):
																		return

								raise ValueError(
								    "When using Dataset.from_spark on a multi-node cluster, the driver and all workers should be able to access cache_dir"						)




			def   lowerCamelCase__  (					self    :       Optional[int]						)   ->			Any:







								"""simple docstring"""
								return datasets.DatasetInfo(features=self.config.features						)




			def   lowerCamelCase__  (					self    :       Dict							, _snake_case    :       datasets.download.download_manager.DownloadManager						)   ->			Optional[Any]:







								"""simple docstring"""
								return [datasets.SplitGenerator(name=datasets.Split.TRAIN						)]




			def   lowerCamelCase__  (					self    :       Tuple							, _snake_case    :       Dict						)   ->			Any:







								"""simple docstring"""
								import pyspark

								def get_arrow_batch_size(_snake_case    :       Tuple						):
													for batch in it:
																		yield pa.RecordBatch.from_pydict({"batch_bytes": [batch.nbytes]}						)

								A_								=    self.df.count()
								A_								=    df_num_rows if df_num_rows <= 100 else 100
								# Approximate the size of each row (in Arrow format) by averaging over a max-100-row sample.
								A_								=    (
								    self.df.limit(_snake_case						)
								    .repartition(1						)
								    .mapInArrow(_snake_case							, "batch_bytes: long"						)
								    .agg(pyspark.sql.functions.sum("batch_bytes"						).alias("sample_bytes"						)						)
								    .collect()[0]
								    .sample_bytes
								    / sample_num_rows
								)
								A_								=    approx_bytes_per_row * df_num_rows
								if approx_total_size > max_shard_size:
													# Make sure there is at least one row per partition.
													A_								=    min(_snake_case							, int(approx_total_size / max_shard_size						)						)
													A_								=    self.df.repartition(_snake_case						)




			def   lowerCamelCase__  (					self    :       Union[str, Any]							, _snake_case    :       str							, _snake_case    :       str							, _snake_case    :       int							, )   ->			Union[str, Any]:







								"""simple docstring"""
								import pyspark

								A_								=    ParquetWriter if file_format == 'parquet' else ArrowWriter
								A_								=    os.path.join(self._working_dir							, os.path.basename(_snake_case						)						) if self._working_dir else fpath
								A_								=    file_format == 'parquet'

								# Define these so that we don't reference self in write_arrow, which will result in a pickling error due to
								# pickling the SparkContext.
								A_								=    self.config.features
								A_								=    self._writer_batch_size
								A_								=    self._fs.storage_options

								def write_arrow(_snake_case    :       int						):
													# Within the same SparkContext, no two task attempts will share the same attempt ID.
													A_								=    pyspark.TaskContext().taskAttemptId()
													A_								=    next(_snake_case							, _snake_case						)
													if first_batch is None:
																		# Some partitions might not receive any data.
																		return pa.RecordBatch.from_arrays(
																		    [[task_id], [0], [0]]							, names=["task_id", "num_examples", "num_bytes"]							, )
													A_								=    0
													A_								=    writer_class(
													    features=_snake_case							, path=working_fpath.replace("SSSSS"							, F'{shard_id:05d}'						).replace("TTTTT"							, F'{task_id:05d}'						)							, writer_batch_size=_snake_case							, storage_options=_snake_case							, embed_local_files=_snake_case							, )
													A_								=    pa.Table.from_batches([first_batch]						)
													writer.write_table(_snake_case						)
													for batch in it:
																		if max_shard_size is not None and writer._num_bytes >= max_shard_size:
																							A_								=    writer.finalize()
																							writer.close()
																							yield pa.RecordBatch.from_arrays(
																							    [[task_id], [num_examples], [num_bytes]]							, names=["task_id", "num_examples", "num_bytes"]							, )
																							shard_id += 1
																							A_								=    writer_class(
																							    features=writer._features							, path=working_fpath.replace("SSSSS"							, F'{shard_id:05d}'						).replace("TTTTT"							, F'{task_id:05d}'						)							, writer_batch_size=_snake_case							, storage_options=_snake_case							, embed_local_files=_snake_case							, )
																		A_								=    pa.Table.from_batches([batch]						)
																		writer.write_table(_snake_case						)

													if writer._num_bytes > 0:
																		A_								=    writer.finalize()
																		writer.close()
																		yield pa.RecordBatch.from_arrays(
																		    [[task_id], [num_examples], [num_bytes]]							, names=["task_id", "num_examples", "num_bytes"]							, )

													if working_fpath != fpath:
																		for file in os.listdir(os.path.dirname(_snake_case						)						):
																							A_								=    os.path.join(os.path.dirname(_snake_case						)							, os.path.basename(_snake_case						)						)
																							shutil.move(_snake_case							, _snake_case						)

								A_								=    (
								    self.df.mapInArrow(_snake_case							, "task_id: long, num_examples: long, num_bytes: long"						)
								    .groupBy("task_id"						)
								    .agg(
								        pyspark.sql.functions.sum("num_examples"						).alias("total_num_examples"						)							, pyspark.sql.functions.sum("num_bytes"						).alias("total_num_bytes"						)							, pyspark.sql.functions.count("num_bytes"						).alias("num_shards"						)							, pyspark.sql.functions.collect_list("num_examples"						).alias("shard_lengths"						)							, )
								    .collect()
								)
								for row in stats:
													yield row.task_id, (row.total_num_examples, row.total_num_bytes, row.num_shards, row.shard_lengths)




			def   lowerCamelCase__  (					self    :       Optional[Any]							, _snake_case    :       "datasets.SplitGenerator"							, _snake_case    :       str = "arrow"							, _snake_case    :       Optional[Union[str, int]] = None							, _snake_case    :       Optional[int] = None							, **_snake_case    :       Union[str, Any]							, )   ->			Union[str, Any]:







								"""simple docstring"""
								self._validate_cache_dir()

								A_								=    convert_file_size_to_int(max_shard_size or MAX_SHARD_SIZE						)
								self._repartition_df_if_needed(_snake_case						)
								A_								=    not is_remote_filesystem(self._fs						)
								A_								=    os.path.join if is_local else posixpath.join

								A_								=    '-TTTTT-SSSSS-of-NNNNN'
								A_								=    F'{self.name}-{split_generator.name}{SUFFIX}.{file_format}'
								A_								=    path_join(self._output_dir							, _snake_case						)

								A_								=    0
								A_								=    0
								A_								=    0
								A_								=    []
								A_								=    []

								for task_id, content in self._prepare_split_single(_snake_case							, _snake_case							, _snake_case						):
													(
													    A_      
													)								=    content
													if num_bytes > 0:
																		total_num_examples += num_examples
																		total_num_bytes += num_bytes
																		total_shards += num_shards
																		task_id_and_num_shards.append((task_id, num_shards)						)
																		all_shard_lengths.extend(_snake_case						)

								A_								=    total_num_examples
								A_								=    total_num_bytes

								# should rename everything at the end
								logger.debug(F'Renaming {total_shards} shards.'						)
								if total_shards > 1:
													A_								=    all_shard_lengths

													# Define fs outside of _rename_shard so that we don't reference self in the function, which will result in a
													# pickling error due to pickling the SparkContext.
													A_								=    self._fs

													# use the -SSSSS-of-NNNNN pattern
													def _rename_shard(
													    _snake_case    :       int							, _snake_case    :       int							, _snake_case    :       int							, ):
																		rename(
																		    _snake_case							, fpath.replace("SSSSS"							, F'{shard_id:05d}'						).replace("TTTTT"							, F'{task_id:05d}'						)							, fpath.replace("TTTTT-SSSSS"							, F'{global_shard_id:05d}'						).replace("NNNNN"							, F'{total_shards:05d}'						)							, )

													A_								=    []
													A_								=    0
													for i in range(len(_snake_case						)						):
																		A_								=    task_id_and_num_shards[i]
																		for shard_id in range(_snake_case						):
																							args.append([task_id, shard_id, global_shard_id]						)
																							global_shard_id += 1
													self._spark.sparkContext.parallelize(_snake_case							, len(_snake_case						)						).map(lambda _snake_case						: _rename_shard(*_snake_case						)						).collect()
								else:
													# don't use any pattern
													A_								=    0
													A_								=    task_id_and_num_shards[0][0]
													self._rename(
													    fpath.replace("SSSSS"							, F'{shard_id:05d}'						).replace("TTTTT"							, F'{task_id:05d}'						)							, fpath.replace(_snake_case							, ""						)							, )






			def   lowerCamelCase__  (					self    :       Optional[int]							, _snake_case    :       "datasets.SplitGenerator"							, )   ->			List[Any]:







								"""simple docstring"""
								return SparkExamplesIterable(self.df						)











import unittest

from transformers import DebertaConfig, is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    DebertaForMaskedLM,
		    DebertaForQuestionAnswering,
		    DebertaForSequenceClassification,
		    DebertaForTokenClassification,
		    DebertaModel,
		)
		from transformers.models.deberta.modeling_deberta import DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST






class 						UpperCamelCase_  (  snake_case__							):



					def __init__(		self     :     str       ,      lowerCamelCase     :     Optional[int]       ,      lowerCamelCase     :     str=13       ,      lowerCamelCase     :     Optional[Any]=7       ,      lowerCamelCase     :     List[Any]=True       ,      lowerCamelCase     :     Dict=True       ,      lowerCamelCase     :     List[Any]=True       ,      lowerCamelCase     :     Any=True       ,      lowerCamelCase     :     Optional[Any]=99       ,      lowerCamelCase     :     Union[str, Any]=32       ,      lowerCamelCase     :     Any=5       ,      lowerCamelCase     :     Tuple=4       ,      lowerCamelCase     :     Optional[int]=37       ,      lowerCamelCase     :     Optional[Any]="gelu"       ,      lowerCamelCase     :     Optional[Any]=0.1       ,      lowerCamelCase     :     str=0.1       ,      lowerCamelCase     :     Tuple=5_12       ,      lowerCamelCase     :     Union[str, Any]=16       ,      lowerCamelCase     :     Union[str, Any]=2       ,      lowerCamelCase     :     Dict=0.02       ,      lowerCamelCase     :     Any=False       ,      lowerCamelCase     :     int=True       ,      lowerCamelCase     :     Optional[Any]="None"       ,      lowerCamelCase     :     Optional[int]=3       ,      lowerCamelCase     :     List[Any]=4       ,      lowerCamelCase     :     int=None       ,      ):
							lowerCamelCase_	:     int 						=      parent
							lowerCamelCase_	:     List[Any] 						=      batch_size
							lowerCamelCase_	:     Dict 						=      seq_length
							lowerCamelCase_	:     Union[str, Any] 						=      is_training
							lowerCamelCase_	:     str 						=      use_input_mask
							lowerCamelCase_	:     int 						=      use_token_type_ids
							lowerCamelCase_	:     Tuple 						=      use_labels
							lowerCamelCase_	:     str 						=      vocab_size
							lowerCamelCase_	:     int 						=      hidden_size
							lowerCamelCase_	:     Optional[int] 						=      num_hidden_layers
							lowerCamelCase_	:     Optional[Any] 						=      num_attention_heads
							lowerCamelCase_	:     Any 						=      intermediate_size
							lowerCamelCase_	:     List[Any] 						=      hidden_act
							lowerCamelCase_	:     List[Any] 						=      hidden_dropout_prob
							lowerCamelCase_	:     List[Any] 						=      attention_probs_dropout_prob
							lowerCamelCase_	:     List[str] 						=      max_position_embeddings
							lowerCamelCase_	:     Tuple 						=      type_vocab_size
							lowerCamelCase_	:     str 						=      type_sequence_label_size
							lowerCamelCase_	:     Optional[int] 						=      initializer_range
							lowerCamelCase_	:     List[Any] 						=      num_labels
							lowerCamelCase_	:     str 						=      num_choices
							lowerCamelCase_	:     Dict 						=      relative_attention
							lowerCamelCase_	:     Optional[int] 						=      position_biased_input
							lowerCamelCase_	:     List[Any] 						=      pos_att_type
							lowerCamelCase_	:     Optional[int] 						=      scope



					def   __a     (		self     :     List[Any]						):
							lowerCamelCase_	:     Tuple 						=      ids_tensor([self.batch_size, self.seq_length]       ,      self.vocab_size						)

							lowerCamelCase_	:     Dict 						=      None
							if self.use_input_mask:
									lowerCamelCase_	:     Optional[int] 						=      ids_tensor([self.batch_size, self.seq_length]       ,      vocab_size=2						)

							lowerCamelCase_	:     str 						=      None
							if self.use_token_type_ids:
									lowerCamelCase_	:     Dict 						=      ids_tensor([self.batch_size, self.seq_length]       ,      self.type_vocab_size						)

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

							lowerCamelCase_	:     Optional[Any] 						=      self.get_config()

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



					def   __a     (		self     :     Tuple						):
							return DebertaConfig(
							    vocab_size=self.vocab_size       ,      hidden_size=self.hidden_size       ,      num_hidden_layers=self.num_hidden_layers       ,      num_attention_heads=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       ,      max_position_embeddings=self.max_position_embeddings       ,      type_vocab_size=self.type_vocab_size       ,      initializer_range=self.initializer_range       ,      relative_attention=self.relative_attention       ,      position_biased_input=self.position_biased_input       ,      pos_att_type=self.pos_att_type       ,      )



					def   __a     (		self     :     int						):
							lowerCamelCase_	:     int 						=      self.get_config()
							lowerCamelCase_	:     Any 						=      3_00
							return config



					def   __a     (		self     :     Optional[int]       ,      lowerCamelCase     :     Dict						):
							self.parent.assertListEqual(list(result.loss.size()						)       ,      []						)



					def   __a     (		self     :     Dict       ,      lowerCamelCase     :     Tuple       ,      lowerCamelCase     :     List[Any]       ,      lowerCamelCase     :     Tuple       ,      lowerCamelCase     :     Any       ,      lowerCamelCase     :     Tuple       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     List[str]						):
							lowerCamelCase_	:     str 						=      DebertaModel(config=lowerCamelCase						)
							model.to(lowerCamelCase						)
							model.eval()
							lowerCamelCase_	:     Optional[int] 						=      model(lowerCamelCase       ,      attention_mask=lowerCamelCase       ,      token_type_ids=lowerCamelCase						)[0]
							lowerCamelCase_	:     Union[str, Any] 						=      model(lowerCamelCase       ,      token_type_ids=lowerCamelCase						)[0]
							lowerCamelCase_	:     List[Any] 						=      model(lowerCamelCase						)[0]

							self.parent.assertListEqual(list(sequence_output.size()						)       ,      [self.batch_size, self.seq_length, self.hidden_size]						)



					def   __a     (		self     :     Optional[Any]       ,      lowerCamelCase     :     Tuple       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     Any						):
							lowerCamelCase_	:     Any 						=      DebertaForMaskedLM(config=lowerCamelCase						)
							model.to(lowerCamelCase						)
							model.eval()
							lowerCamelCase_	:     Any 						=      model(lowerCamelCase       ,      attention_mask=lowerCamelCase       ,      token_type_ids=lowerCamelCase       ,      labels=lowerCamelCase						)

							self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.seq_length, self.vocab_size)						)



					def   __a     (		self     :     Tuple       ,      lowerCamelCase     :     Any       ,      lowerCamelCase     :     Any       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     Optional[int]       ,      lowerCamelCase     :     Optional[int]       ,      lowerCamelCase     :     Tuple						):
							lowerCamelCase_	:     List[str] 						=      self.num_labels
							lowerCamelCase_	:     str 						=      DebertaForSequenceClassification(lowerCamelCase						)
							model.to(lowerCamelCase						)
							model.eval()
							lowerCamelCase_	:     List[str] 						=      model(lowerCamelCase       ,      attention_mask=lowerCamelCase       ,      token_type_ids=lowerCamelCase       ,      labels=lowerCamelCase						)
							self.parent.assertListEqual(list(result.logits.size()						)       ,      [self.batch_size, self.num_labels]						)
							self.check_loss_output(lowerCamelCase						)



					def   __a     (		self     :     List[str]       ,      lowerCamelCase     :     Dict       ,      lowerCamelCase     :     Tuple       ,      lowerCamelCase     :     str       ,      lowerCamelCase     :     Optional[int]       ,      lowerCamelCase     :     Tuple       ,      lowerCamelCase     :     List[str]       ,      lowerCamelCase     :     Optional[int]						):
							lowerCamelCase_	:     List[Any] 						=      self.num_labels
							lowerCamelCase_	:     str 						=      DebertaForTokenClassification(config=lowerCamelCase						)
							model.to(lowerCamelCase						)
							model.eval()
							lowerCamelCase_	:     List[str] 						=      model(lowerCamelCase       ,      attention_mask=lowerCamelCase       ,      token_type_ids=lowerCamelCase       ,      labels=lowerCamelCase						)
							self.parent.assertEqual(result.logits.shape       ,      (self.batch_size, self.seq_length, self.num_labels)						)



					def   __a     (		self     :     List[str]       ,      lowerCamelCase     :     Union[str, Any]       ,      lowerCamelCase     :     List[Any]       ,      lowerCamelCase     :     int       ,      lowerCamelCase     :     Union[str, Any]       ,      lowerCamelCase     :     List[Any]       ,      lowerCamelCase     :     List[str]       ,      lowerCamelCase     :     str						):
							lowerCamelCase_	:     int 						=      DebertaForQuestionAnswering(config=lowerCamelCase						)
							model.to(lowerCamelCase						)
							model.eval()
							lowerCamelCase_	:     List[Any] 						=      model(
							    lowerCamelCase       ,      attention_mask=lowerCamelCase       ,      token_type_ids=lowerCamelCase       ,      start_positions=lowerCamelCase       ,      end_positions=lowerCamelCase       ,      )
							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   __a     (		self     :     int						):
							lowerCamelCase_	:     Any 						=      self.prepare_config_and_inputs()
							(
							    (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      (
							    lowerCamelCase_
							)						,      
							)	:     Dict 						=      config_and_inputs
							lowerCamelCase_	:     str 						=      {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_torch
class 						UpperCamelCase_  (  snake_case__  ,     snake_case__  ,     unittest.TestCase							):
					_a      :						str						    =					(
					    (
					        DebertaModel,
					        DebertaForMaskedLM,
					        DebertaForSequenceClassification,
					        DebertaForTokenClassification,
					        DebertaForQuestionAnswering,
					    )
					    if is_torch_available()
					    else ()
					)
					_a      :						Any						    =					(
					    {
					        'feature-extraction': DebertaModel,
					        'fill-mask': DebertaForMaskedLM,
					        'question-answering': DebertaForQuestionAnswering,
					        'text-classification': DebertaForSequenceClassification,
					        'token-classification': DebertaForTokenClassification,
					        'zero-shot': DebertaForSequenceClassification,
					    }
					    if is_torch_available()
					    else {}
					)

					_a      :						Optional[int]						    =					True
					_a      :						List[str]						    =					False
					_a      :						List[str]						    =					False
					_a      :						List[str]						    =					False
					_a      :						List[Any]						    =					False



					def   __a     (		self     :     List[str]						):
							lowerCamelCase_	:     List[Any] 						=      DebertaModelTester(self						)
							lowerCamelCase_	:     Any 						=      ConfigTester(self       ,      config_class=lowerCamelCase       ,      hidden_size=37						)



					def   __a     (		self     :     Any						):
							self.config_tester.run_common_tests()



					def   __a     (		self     :     List[str]						):
							lowerCamelCase_	:     int 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_model(*lowerCamelCase						)



					def   __a     (		self     :     int						):
							lowerCamelCase_	:     str 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_sequence_classification(*lowerCamelCase						)



					def   __a     (		self     :     Optional[int]						):
							lowerCamelCase_	:     Optional[Any] 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_masked_lm(*lowerCamelCase						)



					def   __a     (		self     :     str						):
							lowerCamelCase_	:     List[Any] 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_question_answering(*lowerCamelCase						)



					def   __a     (		self     :     Union[str, Any]						):
							lowerCamelCase_	:     List[Any] 						=      self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_deberta_for_token_classification(*lowerCamelCase						)





					@slow
					def   __a     (		self     :     Optional[int]						):
							for model_name in DEBERTA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									lowerCamelCase_	:     Optional[int] 						=      DebertaModel.from_pretrained(lowerCamelCase						)
									self.assertIsNotNone(lowerCamelCase						)






@require_torch
@require_sentencepiece
@require_tokenizers
class 						UpperCamelCase_  (  unittest.TestCase							):



					@unittest.skip(reason='Model not available yet'						)
					def   __a     (		self     :     str						):
							pass





					@slow
					def   __a     (		self     :     Dict						):
							lowerCamelCase_	:     List[str] 						=      DebertaModel.from_pretrained('microsoft/deberta-base'						)

							lowerCamelCase_	:     Optional[Any] 						=      torch.tensor([[0, 3_14_14, 2_32, 3_28, 7_40, 11_40, 1_26_95, 69, 4_60_78, 15_88, 2]]						)
							lowerCamelCase_	:     List[str] 						=      torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]						)
							with torch.no_grad():
									lowerCamelCase_	:     Dict 						=      model(lowerCamelCase       ,      attention_mask=lowerCamelCase						)[0]
							# compare the actual values for a slice.
							lowerCamelCase_	:     str 						=      torch.tensor(
							    [[[-0.5_986, -0.8_055, -0.8_462], [1.4_484, -0.9_348, -0.8_059], [0.3_123, 0.0_032, -1.4_131]]]						)
							self.assertTrue(torch.allclose(output[:, 1:4, 1:4]       ,      lowerCamelCase       ,      atol=1E-4						)       ,      F"{output[:, 1:4, 1:4]}"						)
