






"""simple docstring"""




from ...configuration_utils import PretrainedConfig
from ...utils import logging


UpperCamelCase							       =    logging.get_logger(__name__)

UpperCamelCase							       =    {
    """tanreinama/GPTSAN-2.8B-spout_is_uniform""": (
        """https://huggingface.co/tanreinama/GPTSAN-2.8B-spout_is_uniform/resolve/main/config.json"""
    ),
}




class    lowercase_    (_UpperCAmelCase     ):
						A__	:		Any       			=				'''gptsan-japanese'''
						A__	:		Union[str, Any]       			=				[
						    '''past_key_values''',
						]
						A__	:		Dict       			=				{
						    '''hidden_size''': '''d_model''',
						    '''num_attention_heads''': '''num_heads''',
						    '''num_hidden_layers''': '''num_layers''',
						}






						def __init__(    self     ,     a_=3_6_0_0_0     ,     a_=1_2_8_0     ,     a_=1_0_2_4     ,     a_=8_1_9_2     ,     a_=4_0_9_6     ,     a_=1_2_8     ,     a_=1_0     ,     a_=0     ,     a_=1_6     ,     a_=1_6     ,     a_=1_2_8     ,     a_=0.0     ,     a_=1E-5     ,     a_=False     ,     a_=0.0     ,     a_="float32"     ,     a_=False     ,     a_=False     ,     a_=False     ,     a_=0.002     ,     a_=False     ,     a_=True     ,     a_=3_5_9_9_8     ,     a_=3_5_9_9_5     ,     a_=3_5_9_9_9     ,     **a_     ,     )	->Dict:







								'''simple docstring'''


								_a							=	vocab_size
								_a							=	max_position_embeddings
								_a							=	d_model
								_a							=	d_ff
								_a							=	d_ext
								_a							=	d_spout
								_a							=	num_switch_layers
								_a							=	num_ext_layers
								_a							=	num_switch_layers + num_ext_layers
								_a							=	num_heads
								_a							=	num_experts
								_a							=	expert_capacity
								_a							=	dropout_rate
								_a							=	layer_norm_epsilon
								_a							=	router_bias
								_a							=	router_jitter_noise
								_a							=	router_dtype
								_a							=	router_ignore_padding_tokens
								_a							=	output_hidden_states
								_a							=	output_attentions
								_a							=	initializer_factor
								_a							=	output_router_logits
								_a							=	use_cache

								super().__init__(
								    separator_token_id=a_     ,     pad_token_id=a_     ,     eos_token_id=a_     ,     **a_     ,     )










"""simple docstring"""




import os
from typing import BinaryIO, Optional, Union

import numpy as np
import pyarrow.parquet as pq

from .. import Audio, Dataset, Features, Image, NamedSplit, Value, config
from ..features.features import FeatureType, _visit
from ..formatting import query_table
from ..packaged_modules import _PACKAGED_DATASETS_MODULES
from ..packaged_modules.parquet.parquet import Parquet
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader






def        lowerCAmelCase (      UpperCamelCase_:							Features					)       ->							Optional[int]:







  '''simple docstring'''







  _a							=	np.inf

  def set_batch_size(UpperCamelCase_:							FeatureType					) -> None:
    nonlocal batch_size
    if isinstance(UpperCamelCase_     , UpperCamelCase_					):
      _a							=	min(UpperCamelCase_     , config.PARQUET_ROW_GROUP_SIZE_FOR_IMAGE_DATASETS					)
    elif isinstance(UpperCamelCase_     , UpperCamelCase_					):
      _a							=	min(UpperCamelCase_     , config.PARQUET_ROW_GROUP_SIZE_FOR_AUDIO_DATASETS					)
    elif isinstance(UpperCamelCase_     , UpperCamelCase_					) and feature.dtype == "binary":
      _a							=	min(UpperCamelCase_     , config.PARQUET_ROW_GROUP_SIZE_FOR_BINARY_DATASETS					)

  _visit(UpperCamelCase_     , UpperCamelCase_					)

  return None if batch_size is np.inf else batch_size




class    lowercase_    (_UpperCAmelCase     ):






      def __init__(    self     ,     a_     ,     a_ = None     ,     a_ = None     ,     a_ = None     ,     a_ = False     ,     a_ = False     ,     a_ = None     ,     **a_     ,     )	->Optional[int]:







        '''simple docstring'''


        super().__init__(
            a_     ,     split=a_     ,     features=a_     ,     cache_dir=a_     ,     keep_in_memory=a_     ,     streaming=a_     ,     num_proc=a_     ,     **a_     ,     )
        _a							=	path_or_paths if isinstance(a_     ,     a_	) else {self.split: path_or_paths}
        _a							=	_PACKAGED_DATASETS_MODULES["parquet"][1]
        _a							=	Parquet(
            cache_dir=a_     ,     data_files=a_     ,     features=a_     ,     hash=a_     ,     **a_     ,     )






      def 			lowerCamelCase__    (    self	)	->str:







        '''simple docstring'''


        if self.streaming:
          _a							=	self.builder.as_streaming_dataset(split=self.split	)
        # Build regular (map-style) dataset
        else:
          _a							=	None
          _a							=	None
          _a							=	None
          _a							=	None

          self.builder.download_and_prepare(
              download_config=a_     ,     download_mode=a_     ,     verification_mode=a_     ,     base_path=a_     ,     num_proc=self.num_proc     ,     )
          _a							=	self.builder.as_dataset(
              split=self.split     ,     verification_mode=a_     ,     in_memory=self.keep_in_memory	)
        return dataset







class    lowercase_    :






      def __init__(    self     ,     a_     ,     a_     ,     a_ = None     ,     **a_     ,     )	->int:







        '''simple docstring'''


        _a							=	dataset
        _a							=	path_or_buf
        _a							=	batch_size or get_writer_batch_size(dataset.features	)
        _a							=	parquet_writer_kwargs






      def 			lowerCamelCase__    (    self	)	->int:







        '''simple docstring'''


        _a							=	self.batch_size if self.batch_size else config.DEFAULT_MAX_BATCH_SIZE

        if isinstance(self.path_or_buf     ,     (str, bytes, os.PathLike)	):
          with open(self.path_or_buf     ,     "wb+"	) as buffer:
            _a							=	self._write(file_obj=a_     ,     batch_size=a_     ,     **self.parquet_writer_kwargs	)
        else:
          _a							=	self._write(file_obj=self.path_or_buf     ,     batch_size=a_     ,     **self.parquet_writer_kwargs	)
        return written






      def 			lowerCamelCase__    (    self     ,     a_     ,     a_     ,     **a_	)	->int:







        '''simple docstring'''


        _a							=	0
        _a							=	parquet_writer_kwargs.pop("path_or_buf"     ,     a_	)
        _a							=	self.dataset.features.arrow_schema

        _a							=	pq.ParquetWriter(a_     ,     schema=a_     ,     **a_	)

        for offset in logging.tqdm(
            range(0     ,     len(self.dataset	)     ,     a_	)     ,     unit="ba"     ,     disable=not logging.is_progress_bar_enabled()     ,     desc="Creating parquet from Arrow format"     ,     ):
          _a							=	query_table(
              table=self.dataset._data     ,     key=slice(a_     ,     offset + batch_size	)     ,     indices=self.dataset._indices if self.dataset._indices is not None else None     ,     )
          writer.write_table(a_	)
          written += batch.nbytes
        writer.close()
        return written


