






import itertools
from dataclasses import dataclass
from typing import Any, Callable, Dict, List, Optional, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast
from datasets.utils.py_utils import Literal


a_		:						Any             =    datasets.utils.logging.get_logger(__name__)

a_		:						Union[str, Any]             =    ['names', 'prefix']
a_		:						List[str]             =    ['warn_bad_lines', 'error_bad_lines', 'mangle_dupe_cols']
a_		:						Union[str, Any]             =    ['encoding_errors', 'on_bad_lines']
a_		:						Optional[int]             =    ['date_format']

@dataclass
class 		_snake_case  (  datasets.BuilderConfig					):
			_lowercase		:    Optional[int]			     =							''','''
			_lowercase		:    int			     =							None
			_lowercase		:    Any			     =							'''infer'''
			_lowercase		:    Tuple			     =							None
			_lowercase		:    Optional[int]			     =							None
			_lowercase		:    Optional[int]			     =							None
			_lowercase		:    Optional[int]			     =							None
			_lowercase		:    int			     =							None
			_lowercase		:    str			     =							True
			_lowercase		:    Tuple			     =							None
			_lowercase		:    Tuple			     =							None
			_lowercase		:    Tuple			     =							None
			_lowercase		:    Union[str, Any]			     =							None
			_lowercase		:    Tuple			     =							False
			_lowercase		:    Optional[Any]			     =							None
			_lowercase		:    List[str]			     =							None
			_lowercase		:    int			     =							None
			_lowercase		:    Optional[int]			     =							True
			_lowercase		:    Dict			     =							True
			_lowercase		:    Dict			     =							False
			_lowercase		:    Optional[Any]			     =							True
			_lowercase		:    Optional[Any]			     =							None
			_lowercase		:    Tuple			     =							'''.'''
			_lowercase		:    Union[str, Any]			     =							None
			_lowercase		:    str			     =							'''"'''
			_lowercase		:    Optional[Any]			     =							0
			_lowercase		:    str			     =							None
			_lowercase		:    Optional[Any]			     =							None
			_lowercase		:    str			     =							None
			_lowercase		:    Any			     =							None
			_lowercase		:    Any			     =							True
			_lowercase		:    List[str]			     =							True
			_lowercase		:    Union[str, Any]			     =							0
			_lowercase		:    List[str]			     =							True
			_lowercase		:    str			     =							False
			_lowercase		:    List[str]			     =							None
			_lowercase		:    Optional[int]			     =							1_00_00
			_lowercase		:    Optional[int]			     =							None
			_lowercase		:    Any			     =							'''strict'''
			_lowercase		:    Optional[int]			     =							'''error'''
			_lowercase		:    Any			     =							None






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Tuple:
						if self.delimiter is not None:
									SCREAMING_SNAKE_CASE						= self.delimiter
						if self.column_names is not None:
									SCREAMING_SNAKE_CASE						= self.column_names







			@property
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       List[Any]:
						SCREAMING_SNAKE_CASE						= {
						    'sep': self.sep,
						    'header': self.header,
						    'names': self.names,
						    'index_col': self.index_col,
						    'usecols': self.usecols,
						    'prefix': self.prefix,
						    'mangle_dupe_cols': self.mangle_dupe_cols,
						    'engine': self.engine,
						    'converters': self.converters,
						    'true_values': self.true_values,
						    'false_values': self.false_values,
						    'skipinitialspace': self.skipinitialspace,
						    'skiprows': self.skiprows,
						    'nrows': self.nrows,
						    'na_values': self.na_values,
						    'keep_default_na': self.keep_default_na,
						    'na_filter': self.na_filter,
						    'verbose': self.verbose,
						    'skip_blank_lines': self.skip_blank_lines,
						    'thousands': self.thousands,
						    'decimal': self.decimal,
						    'lineterminator': self.lineterminator,
						    'quotechar': self.quotechar,
						    'quoting': self.quoting,
						    'escapechar': self.escapechar,
						    'comment': self.comment,
						    'encoding': self.encoding,
						    'dialect': self.dialect,
						    'error_bad_lines': self.error_bad_lines,
						    'warn_bad_lines': self.warn_bad_lines,
						    'skipfooter': self.skipfooter,
						    'doublequote': self.doublequote,
						    'memory_map': self.memory_map,
						    'float_precision': self.float_precision,
						    'chunksize': self.chunksize,
						    'encoding_errors': self.encoding_errors,
						    'on_bad_lines': self.on_bad_lines,
						    'date_format': self.date_format,
						}

						# some kwargs must not be passed if they don't have a default value
						# some others are deprecated and we can also not pass them if they are the default value
						for pd_read_csv_parameter in _PANDAS_READ_CSV_NO_DEFAULT_PARAMETERS + _PANDAS_READ_CSV_DEPRECATED_PARAMETERS:
									if pd_read_csv_kwargs[pd_read_csv_parameter] == getattr(CsvConfig()		,					lowerCAmelCase__):
												del pd_read_csv_kwargs[pd_read_csv_parameter]

												 # Remove 2.0 new arguments
						if not (datasets.config.PANDAS_VERSION.major >= 2):
									for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_2_0_0_PARAMETERS:
												del pd_read_csv_kwargs[pd_read_csv_parameter]

												 # Remove 1.3 new arguments
						if not (datasets.config.PANDAS_VERSION.major >= 1 and datasets.config.PANDAS_VERSION.minor >= 3):
									for pd_read_csv_parameter in _PANDAS_READ_CSV_NEW_1_3_0_PARAMETERS:
												del pd_read_csv_kwargs[pd_read_csv_parameter]

						return pd_read_csv_kwargs



class 		_snake_case  (  datasets.ArrowBasedBuilder					):
			_lowercase		:    List[Any]			     =							CsvConfig






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Tuple:
						return datasets.DatasetInfo(features=self.config.features)






			def    SCREAMING_SNAKE_CASE__    (       self		,					a)      ->       List[Any]:
						if not self.config.data_files:
									raise ValueError(f'''At least one data file must be specified, but got data_files={self.config.data_files}''')
						SCREAMING_SNAKE_CASE						= dl_manager.download_and_extract(self.config.data_files)
						if isinstance(lowerCAmelCase__		,					(str, list, tuple)):
									SCREAMING_SNAKE_CASE						= data_files
									if isinstance(lowerCAmelCase__		,					lowerCAmelCase__):
												SCREAMING_SNAKE_CASE						= [files]
									SCREAMING_SNAKE_CASE						= [dl_manager.iter_files(lowerCAmelCase__) for file in files]
									return [datasets.SplitGenerator(name=datasets.Split.TRAIN		,					gen_kwargs={'files': files})]
						SCREAMING_SNAKE_CASE						= []
						for split_name, files in data_files.items():
									if isinstance(lowerCAmelCase__		,					lowerCAmelCase__):
												SCREAMING_SNAKE_CASE						= [files]
									SCREAMING_SNAKE_CASE						= [dl_manager.iter_files(lowerCAmelCase__) for file in files]
									splits.append(datasets.SplitGenerator(name=lowerCAmelCase__		,					gen_kwargs={'files': files}))
						return splits






			def    SCREAMING_SNAKE_CASE__    (       self		,					a)      ->       pa.Table:
						if self.config.features is not None:
									SCREAMING_SNAKE_CASE						= self.config.features.arrow_schema
									if all(not require_storage_cast(lowerCAmelCase__) for feature in self.config.features.values()):
												# cheaper cast
												SCREAMING_SNAKE_CASE						= pa.Table.from_arrays([pa_table[field.name] for field in schema]		,					schema=lowerCAmelCase__)
									else:
												# more expensive cast; allows str <-> int/float or str to Audio for example
												SCREAMING_SNAKE_CASE						= table_cast(lowerCAmelCase__		,					lowerCAmelCase__)
						return pa_table







			def    SCREAMING_SNAKE_CASE__    (       self		,					a)      ->       Optional[Any]:
						SCREAMING_SNAKE_CASE						= self.config.features.arrow_schema if self.config.features else None
						# dtype allows reading an int column as str
						SCREAMING_SNAKE_CASE						= (
						    {
						        name: dtype.to_pandas_dtype() if not require_storage_cast(lowerCAmelCase__) else object
						        for name, dtype, feature in zip(schema.names		,					schema.types		,					self.config.features.values())
						    }
						    if schema is not None
						    else None
						)
						for file_idx, file in enumerate(itertools.chain.from_iterable(lowerCAmelCase__)):
									SCREAMING_SNAKE_CASE						= pd.read_csv(lowerCAmelCase__		,					iterator=lowerCAmelCase__		,					dtype=lowerCAmelCase__		,					**self.config.pd_read_csv_kwargs)
									try:
												for batch_idx, df in enumerate(lowerCAmelCase__):
															SCREAMING_SNAKE_CASE						= pa.Table.from_pandas(lowerCAmelCase__)
															# Uncomment for debugging (will print the Arrow table size and elements)
															# logger.warning(f"pa_table: {pa_table} num rows: {pa_table.num_rows}")
															# logger.warning('\n'.join(str(pa_table.slice(i, 1).to_pydict()) for i in range(pa_table.num_rows)))
															yield (file_idx, batch_idx), self._cast_table(lowerCAmelCase__)
									except ValueError as e:
												logger.error(f'''Failed to read file \'{file}\' with error {type(lowerCAmelCase__)}: {e}''')
												raise












import unittest

from transformers import DebertaVaConfig, 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 (
				    DebertaVaForMaskedLM,
				    DebertaVaForMultipleChoice,
				    DebertaVaForQuestionAnswering,
				    DebertaVaForSequenceClassification,
				    DebertaVaForTokenClassification,
				    DebertaVaModel,
				)
				from transformers.models.deberta_va.modeling_deberta_va import DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST

class 		_snake_case  (  A__					):






			def __init__(       self		,					a		,					a=13		,					a=7		,					a=True		,					a=True		,					a=True		,					a=True		,					a=99		,					a=32		,					a=5		,					a=4		,					a=37		,					a="gelu"		,					a=0.1		,					a=0.1		,					a=512		,					a=16		,					a=2		,					a=0.02		,					a=False		,					a=True		,					a="None"		,					a=3		,					a=4		,					a=None		,					)      ->       int:
						SCREAMING_SNAKE_CASE						= parent
						SCREAMING_SNAKE_CASE						= batch_size
						SCREAMING_SNAKE_CASE						= seq_length
						SCREAMING_SNAKE_CASE						= is_training
						SCREAMING_SNAKE_CASE						= use_input_mask
						SCREAMING_SNAKE_CASE						= use_token_type_ids
						SCREAMING_SNAKE_CASE						= use_labels
						SCREAMING_SNAKE_CASE						= vocab_size
						SCREAMING_SNAKE_CASE						= hidden_size
						SCREAMING_SNAKE_CASE						= num_hidden_layers
						SCREAMING_SNAKE_CASE						= num_attention_heads
						SCREAMING_SNAKE_CASE						= intermediate_size
						SCREAMING_SNAKE_CASE						= hidden_act
						SCREAMING_SNAKE_CASE						= hidden_dropout_prob
						SCREAMING_SNAKE_CASE						= attention_probs_dropout_prob
						SCREAMING_SNAKE_CASE						= max_position_embeddings
						SCREAMING_SNAKE_CASE						= type_vocab_size
						SCREAMING_SNAKE_CASE						= type_sequence_label_size
						SCREAMING_SNAKE_CASE						= initializer_range
						SCREAMING_SNAKE_CASE						= num_labels
						SCREAMING_SNAKE_CASE						= num_choices
						SCREAMING_SNAKE_CASE						= relative_attention
						SCREAMING_SNAKE_CASE						= position_biased_input
						SCREAMING_SNAKE_CASE						= pos_att_type
						SCREAMING_SNAKE_CASE						= scope






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       List[str]:
						SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size, self.seq_length]		,					self.vocab_size)

						SCREAMING_SNAKE_CASE						= None
						if self.use_input_mask:
									SCREAMING_SNAKE_CASE						= ids_tensor([self.batch_size, self.seq_length]		,					vocab_size=2)

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

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

						SCREAMING_SNAKE_CASE						= self.get_config()

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






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       int:
						return DebertaVaConfig(
						    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    SCREAMING_SNAKE_CASE__    (       self		,					a)      ->       int:
						self.parent.assertListEqual(list(result.loss.size())		,					[])






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       int:
						SCREAMING_SNAKE_CASE						= DebertaVaModel(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a)[0]
						SCREAMING_SNAKE_CASE						= model(a		,					token_type_ids=a)[0]
						SCREAMING_SNAKE_CASE						= model(a)[0]

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






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       Dict:
						SCREAMING_SNAKE_CASE						= DebertaVaForMaskedLM(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a		,					labels=a)

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






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       str:
						SCREAMING_SNAKE_CASE						= self.num_labels
						SCREAMING_SNAKE_CASE						= DebertaVaForSequenceClassification(a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a		,					labels=a)
						self.parent.assertListEqual(list(result.logits.size())		,					[self.batch_size, self.num_labels])
						self.check_loss_output(a)






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       int:
						SCREAMING_SNAKE_CASE						= self.num_labels
						SCREAMING_SNAKE_CASE						= DebertaVaForTokenClassification(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a		,					token_type_ids=a		,					labels=a)
						self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.seq_length, self.num_labels))






			def    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       Optional[int]:
						SCREAMING_SNAKE_CASE						= DebertaVaForQuestionAnswering(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= model(
						    a		,					attention_mask=a		,					token_type_ids=a		,					start_positions=a		,					end_positions=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    SCREAMING_SNAKE_CASE__    (       self		,					a		,					a		,					a		,					a		,					a		,					a		,					a)      ->       Any:
						SCREAMING_SNAKE_CASE						= DebertaVaForMultipleChoice(config=a)
						model.to(a)
						model.eval()
						SCREAMING_SNAKE_CASE						= input_ids.unsqueeze(1).expand(-1		,					self.num_choices		,					-1).contiguous()
						SCREAMING_SNAKE_CASE						= token_type_ids.unsqueeze(1).expand(-1		,					self.num_choices		,					-1).contiguous()
						SCREAMING_SNAKE_CASE						= input_mask.unsqueeze(1).expand(-1		,					self.num_choices		,					-1).contiguous()
						SCREAMING_SNAKE_CASE						= model(
						    a		,					attention_mask=a		,					token_type_ids=a		,					labels=a		,					)
						self.parent.assertEqual(result.logits.shape		,					(self.batch_size, self.num_choices))







			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Optional[int]:
						SCREAMING_SNAKE_CASE						= self.prepare_config_and_inputs()
						(
						    (
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						(
						    SCREAMING_SNAKE_CASE
						)				,						
						)						= config_and_inputs
						SCREAMING_SNAKE_CASE						= {'input_ids': input_ids, 'token_type_ids': token_type_ids, 'attention_mask': input_mask}
						return config, inputs_dict



@require_torch
class 		_snake_case  (  A__   ,    A__   ,    unittest.TestCase					):
			_lowercase		:    Dict			     =							(
			    (
			        DebertaVaModel,
			        DebertaVaForMaskedLM,
			        DebertaVaForSequenceClassification,
			        DebertaVaForTokenClassification,
			        DebertaVaForQuestionAnswering,
			        DebertaVaForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			_lowercase		:    Optional[int]			     =							(
			    {
			        '''feature-extraction''': DebertaVaModel,
			        '''fill-mask''': DebertaVaForMaskedLM,
			        '''question-answering''': DebertaVaForQuestionAnswering,
			        '''text-classification''': DebertaVaForSequenceClassification,
			        '''token-classification''': DebertaVaForTokenClassification,
			        '''zero-shot''': DebertaVaForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)

			_lowercase		:    Optional[int]			     =							True
			_lowercase		:    int			     =							False
			_lowercase		:    Dict			     =							False
			_lowercase		:    Optional[int]			     =							False
			_lowercase		:    List[str]			     =							False






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Optional[int]:
						SCREAMING_SNAKE_CASE						= DebertaVaModelTester(self)
						SCREAMING_SNAKE_CASE						= ConfigTester(self		,					config_class=a		,					hidden_size=37)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Dict:
						self.config_tester.run_common_tests()






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Tuple:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_model(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       List[Any]:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_sequence_classification(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Dict:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_masked_lm(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_question_answering(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       int:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_token_classification(*a)






			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						SCREAMING_SNAKE_CASE						= self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_deberta_for_multiple_choice(*a)







			@slow
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       str:
						for model_name in DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
									SCREAMING_SNAKE_CASE						= DebertaVaModel.from_pretrained(a)
									self.assertIsNotNone(a)



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






			@unittest.skip(reason='Model not available yet')
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						pass







			@slow
			def    SCREAMING_SNAKE_CASE__    (       self)      ->       Union[str, Any]:
						SCREAMING_SNAKE_CASE						= DebertaVaModel.from_pretrained('microsoft/deberta-v2-xlarge')

						SCREAMING_SNAKE_CASE						= torch.tensor([[0, 3_1414, 232, 328, 740, 1140, 1_2695, 69, 4_6078, 1588, 2]])
						SCREAMING_SNAKE_CASE						= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])
						with torch.no_grad():
									SCREAMING_SNAKE_CASE						= model(a		,					attention_mask=a)[0]
						# compare the actual values for a slice.
						SCREAMING_SNAKE_CASE						= torch.tensor(
						    [[[0.23_56, 0.19_48, 0.03_69], [-0.10_63, 0.35_86, -0.51_52], [-0.63_99, -0.02_59, -0.25_25]]])
						self.assertTrue(torch.allclose(output[:, 1:4, 1:4]		,					a		,					atol=1E-4)		,					f'''{output[:, 1:4, 1:4]}''')




