






"""simple docstring"""




import copy
import os
from typing import Union

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


UpperCamelCase							       =    logging.get_logger(__name__)

UpperCamelCase							       =    {
    """microsoft/git-base""": """https://huggingface.co/microsoft/git-base/resolve/main/config.json""",
}




class    lowercase_    (_UpperCAmelCase     ):
						A__	:		Union[str, Any]       			=				'''git_vision_model'''






						def __init__(    self     ,     a_=7_6_8     ,     a_=3_0_7_2     ,     a_=1_2     ,     a_=1_2     ,     a_=3     ,     a_=2_2_4     ,     a_=1_6     ,     a_="quick_gelu"     ,     a_=1E-5     ,     a_=0.0     ,     a_=0.02     ,     **a_     ,     )	->Union[str, Any]:







								'''simple docstring'''


								super().__init__(**a_	)

								_a							=	hidden_size
								_a							=	intermediate_size
								_a							=	num_hidden_layers
								_a							=	num_attention_heads
								_a							=	num_channels
								_a							=	patch_size
								_a							=	image_size
								_a							=	initializer_range
								_a							=	attention_dropout
								_a							=	layer_norm_eps
								_a							=	hidden_act






						@classmethod
						def 			lowerCamelCase__    (    cls     ,     a_     ,     **a_	)	->"PretrainedConfig":







								'''simple docstring'''


								cls._set_token_in_kwargs(a_	)

								_a			,	_a							=	cls.get_config_dict(a_     ,     **a_	)

								# get the vision config dict if we are loading from GITConfig
								if config_dict.get("model_type"	) == "git":
										_a							=	config_dict["vision_config"]

								if "model_type" in config_dict and hasattr(cls     ,     "model_type"	) and config_dict["model_type"] != cls.model_type:
										logger.warning(
										    f'''You are using a model of type {config_dict['model_type']} to instantiate a model of type '''
										    f'''{cls.model_type}. This is not supported for all configurations of models and can yield errors.'''	)

								return cls.from_dict(a_     ,     **a_	)







class    lowercase_    (_UpperCAmelCase     ):
						A__	:		List[str]       			=				'''git'''






						def __init__(    self     ,     a_=None     ,     a_=3_0_5_2_2     ,     a_=7_6_8     ,     a_=6     ,     a_=1_2     ,     a_=3_0_7_2     ,     a_="gelu"     ,     a_=0.1     ,     a_=0.1     ,     a_=1_0_2_4     ,     a_=0.02     ,     a_=1E-12     ,     a_=0     ,     a_="absolute"     ,     a_=True     ,     a_=False     ,     a_=1_0_1     ,     a_=1_0_2     ,     a_=None     ,     **a_     ,     )	->List[Any]:







								'''simple docstring'''


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

								if vision_config is None:
										_a							=	{}
										logger.info("vision_config is None. initializing the GitVisionConfig with default values."	)

								_a							=	GitVisionConfig(**a_	)
								_a							=	vocab_size
								_a							=	hidden_size
								_a							=	num_hidden_layers
								_a							=	num_attention_heads
								_a							=	hidden_act
								_a							=	intermediate_size
								_a							=	hidden_dropout_prob
								_a							=	attention_probs_dropout_prob
								_a							=	max_position_embeddings
								_a							=	initializer_range
								_a							=	layer_norm_eps
								_a							=	position_embedding_type
								_a							=	use_cache
								_a							=	tie_word_embeddings
								_a							=	num_image_with_embedding

								_a							=	bos_token_id
								_a							=	eos_token_id






						def 			lowerCamelCase__    (    self	)	->Any:







								'''simple docstring'''


								_a							=	copy.deepcopy(self.__dict__	)
								_a							=	self.vision_config.to_dict()
								_a							=	self.__class__.model_type
								return output










"""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


