






'''simple docstring'''







from typing import Optional, Tuple, Union

import tensorflow as tf

from ...activations_tf import ACTaFN
from ...file_utils import add_code_sample_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward
from ...modeling_tf_outputs import (
    TFBaseModelOutputWithNoAttention,
    TFBaseModelOutputWithPoolingAndNoAttention,
    TFSequenceClassifierOutput,
)
from ...modeling_tf_utils import TFPreTrainedModel, TFSequenceClassificationLoss, keras_serializable, unpack_inputs
from ...tf_utils import shape_list
from ...utils import logging
from .configuration_regnet import RegNetConfig


__lowerCAmelCase        =							logging.get_logger(__name__)

# General docstring
__lowerCAmelCase        =							"RegNetConfig"

# Base docstring
__lowerCAmelCase        =							"facebook/regnet-y-040"
__lowerCAmelCase        =							[1, 10_88, 7, 7]

# Image classification docstring
__lowerCAmelCase        =							"facebook/regnet-y-040"
__lowerCAmelCase        =							"tabby, tabby cat"

__lowerCAmelCase        =							[
    "facebook/regnet-y-040",
    # See all regnet models at https://huggingface.co/models?filter=regnet
]




class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = 3   ,	UpperCamelCase__ = 1   ,	UpperCamelCase__ = 1   ,	UpperCamelCase__ = "relu"   ,	**UpperCamelCase__   ,	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         # The padding and conv has been verified in
         # https://colab.research.google.com/gist/sayakpaul/854bc10eeaf21c9ee2119e0b9f3841a7/scratchpad.ipynb
         a_						     =			tf.keras.layers.ZeroPaddingaD(padding=kernel_size // 2	)
         a_						     =			tf.keras.layers.ConvaD(
             filters=UpperCamelCase__   ,	kernel_size=UpperCamelCase__   ,	strides=UpperCamelCase__   ,	padding='VALID'   ,	groups=UpperCamelCase__   ,	use_bias=UpperCamelCase__   ,	name='convolution'   ,	)
         a_						     =			tf.keras.layers.BatchNormalization(epsilon=1e-5   ,	momentum=0.9   ,	name='normalization'	)
         a_						     =			ACTaFN[activation] if activation is not None else tf.identity







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_						     =			self.convolution(self.padding(UpperCamelCase__	)	)
         a_						     =			self.normalization(UpperCamelCase__	)
         a_						     =			self.activation(UpperCamelCase__	)
         return hidden_state





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			config.num_channels
         a_						     =			TFRegNetConvLayer(
             out_channels=config.embedding_size   ,	kernel_size=3   ,	stride=2   ,	activation=config.hidden_act   ,	name='embedder'   ,	)







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_						     =			shape_list(UpperCamelCase__	)[1]
         if tf.executing_eagerly() and num_channels != self.num_channels:
                raise ValueError(
                    'Make sure that the channel dimension of the pixel values match with the one set in the configuration.'	)

         # When running on CPU, `tf.keras.layers.Conv2D` doesn't support `NCHW` format.
         # So change the input format from `NCHW` to `NHWC`.
         # shape = (batch_size, in_height, in_width, in_channels=num_channels)
         a_						     =			tf.transpose(UpperCamelCase__   ,	perm=(0, 2, 3, 1)	)
         a_						     =			self.embedder(UpperCamelCase__	)
         return hidden_state





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = 2   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			tf.keras.layers.ConvaD(
             filters=UpperCamelCase__   ,	kernel_size=1   ,	strides=UpperCamelCase__   ,	use_bias=UpperCamelCase__   ,	name='convolution'	)
         a_						     =			tf.keras.layers.BatchNormalization(epsilon=1e-5   ,	momentum=0.9   ,	name='normalization'	)







  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = False	):






         """simple docstring"""


         return self.normalization(self.convolution(UpperCamelCase__	)   ,	training=UpperCamelCase__	)





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase__   ,	name='pooler'	)
         a_						     =			[
             tf.keras.layers.ConvaD(filters=UpperCamelCase__   ,	kernel_size=1   ,	activation='relu'   ,	name='attention.0'	),
             tf.keras.layers.ConvaD(filters=UpperCamelCase__   ,	kernel_size=1   ,	activation='sigmoid'   ,	name='attention.2'	),
         ]







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_						     =			self.pooler(UpperCamelCase__	)
         for layer_module in self.attention:
                a_						     =			layer_module(UpperCamelCase__	)
         a_						     =			hidden_state * pooled
         return hidden_state





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__ = 1   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			in_channels != out_channels or stride != 1
         a_						     =			max(1   ,	out_channels // config.groups_width	)
         a_						     =			(
             TFRegNetShortCut(UpperCamelCase__   ,	stride=UpperCamelCase__   ,	name='shortcut'	)
             if should_apply_shortcut
             else tf.keras.layers.Activation('linear'   ,	name='shortcut'	)
         )
         # `self.layers` instead of `self.layer` because that is a reserved argument.
         a_						     =			[
             TFRegNetConvLayer(UpperCamelCase__   ,	kernel_size=1   ,	activation=config.hidden_act   ,	name='layer.0'	),
             TFRegNetConvLayer(
                 UpperCamelCase__   ,	stride=UpperCamelCase__   ,	groups=UpperCamelCase__   ,	activation=config.hidden_act   ,	name='layer.1'	),
             TFRegNetConvLayer(UpperCamelCase__   ,	kernel_size=1   ,	activation=UpperCamelCase__   ,	name='layer.2'	),
         ]
         a_						     =			ACTaFN[config.hidden_act]







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_						     =			hidden_state
         for layer_module in self.layers:
                a_						     =			layer_module(UpperCamelCase__	)
         a_						     =			self.shortcut(UpperCamelCase__	)
         hidden_state += residual
         a_						     =			self.activation(UpperCamelCase__	)
         return hidden_state





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__ = 1   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			in_channels != out_channels or stride != 1
         a_						     =			max(1   ,	out_channels // config.groups_width	)
         a_						     =			(
             TFRegNetShortCut(UpperCamelCase__   ,	stride=UpperCamelCase__   ,	name='shortcut'	)
             if should_apply_shortcut
             else tf.keras.layers.Activation('linear'   ,	name='shortcut'	)
         )
         a_						     =			[
             TFRegNetConvLayer(UpperCamelCase__   ,	kernel_size=1   ,	activation=config.hidden_act   ,	name='layer.0'	),
             TFRegNetConvLayer(
                 UpperCamelCase__   ,	stride=UpperCamelCase__   ,	groups=UpperCamelCase__   ,	activation=config.hidden_act   ,	name='layer.1'	),
             TFRegNetSELayer(UpperCamelCase__   ,	reduced_channels=int(round(in_channels / 4	)	)   ,	name='layer.2'	),
             TFRegNetConvLayer(UpperCamelCase__   ,	kernel_size=1   ,	activation=UpperCamelCase__   ,	name='layer.3'	),
         ]
         a_						     =			ACTaFN[config.hidden_act]







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_						     =			hidden_state
         for layer_module in self.layers:
                a_						     =			layer_module(UpperCamelCase__	)
         a_						     =			self.shortcut(UpperCamelCase__	)
         hidden_state += residual
         a_						     =			self.activation(UpperCamelCase__	)
         return hidden_state





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__ = 2   ,	UpperCamelCase__ = 2   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)

         a_						     =			TFRegNetXLayer if config.layer_type == 'x' else TFRegNetYLayer
         a_						     =			[
             # downsampling is done in the first layer with stride of 2
             layer(UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	stride=UpperCamelCase__   ,	name='layers.0'	),
             *[layer(UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	name=f'layers.{i+1}'	) for i in range(depth - 1	)],
         ]







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         for layer_module in self.layers:
                a_						     =			layer_module(UpperCamelCase__	)
         return hidden_state





class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			[]
         # based on `downsample_in_first_stage`, the first layer of the first stage may or may not downsample the input
         self.stages.append(
             TFRegNetStage(
                 UpperCamelCase__   ,	config.embedding_size   ,	config.hidden_sizes[0]   ,	stride=2 if config.downsample_in_first_stage else 1   ,	depth=config.depths[0]   ,	name='stages.0'   ,	)	)
         a_						     =			zip(config.hidden_sizes   ,	config.hidden_sizes[1:]	)
         for i, ((in_channels, out_channels), depth) in enumerate(zip(UpperCamelCase__   ,	config.depths[1:]	)	):
                self.stages.append(TFRegNetStage(UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	depth=UpperCamelCase__   ,	name=f'stages.{i+1}'	)	)







  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = False   ,	UpperCamelCase__ = True	):






         """simple docstring"""


         a_						     =			() if output_hidden_states else None

         for stage_module in self.stages:
                if output_hidden_states:
                       a_						     =			hidden_states + (hidden_state,)

                a_						     =			stage_module(UpperCamelCase__	)

         if output_hidden_states:
                a_						     =			hidden_states + (hidden_state,)

         if not return_dict:
                return tuple(v for v in [hidden_state, hidden_states] if v is not None	)

         return TFBaseModelOutputWithNoAttention(last_hidden_state=UpperCamelCase__   ,	hidden_states=UpperCamelCase__	)





@keras_serializable
class   __SCREAMING_SNAKE_CASE       (tf.keras.layers.Layer       ):


  """simple docstring"""


  _a  : int      			=     RegNetConfig







  def __init__(			self   ,	UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(**UpperCamelCase__	)
         a_						     =			config
         a_						     =			TFRegNetEmbeddings(UpperCamelCase__   ,	name='embedder'	)
         a_						     =			TFRegNetEncoder(UpperCamelCase__   ,	name='encoder'	)
         a_						     =			tf.keras.layers.GlobalAveragePoolingaD(keepdims=UpperCamelCase__   ,	name='pooler'	)







  @unpack_inputs
  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = False   ,	):






         """simple docstring"""


         a_						     =			(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         a_						     =			return_dict if return_dict is not None else self.config.use_return_dict

         a_						     =			self.embedder(UpperCamelCase__   ,	training=UpperCamelCase__	)

         a_						     =			self.encoder(
             UpperCamelCase__   ,	output_hidden_states=UpperCamelCase__   ,	return_dict=UpperCamelCase__   ,	training=UpperCamelCase__	)

         a_						     =			encoder_outputs[0]
         a_						     =			self.pooler(UpperCamelCase__	)

         # Change to NCHW output format have uniformity in the modules
         a_						     =			tf.transpose(UpperCamelCase__   ,	perm=(0, 3, 1, 2)	)
         a_						     =			tf.transpose(UpperCamelCase__   ,	perm=(0, 3, 1, 2)	)

         # Change the other hidden state outputs to NCHW as well
         if output_hidden_states:
                a_						     =			tuple([tf.transpose(UpperCamelCase__   ,	perm=(0, 3, 1, 2)	) for h in encoder_outputs[1]]	)

         if not return_dict:
                return (last_hidden_state, pooled_output) + encoder_outputs[1:]

         return TFBaseModelOutputWithPoolingAndNoAttention(
             last_hidden_state=UpperCamelCase__   ,	pooler_output=UpperCamelCase__   ,	hidden_states=hidden_states if output_hidden_states else encoder_outputs.hidden_states   ,	)





class   __SCREAMING_SNAKE_CASE       (__A       ):


  """simple docstring"""


  _a  : List[Any]      			=     RegNetConfig
  _a  : Union[str, Any]      			=     '''regnet'''
  _a  : Any      			=     '''pixel_values'''







  @property
  def    _a       (			self	):






         """simple docstring"""


         return {"pixel_values": tf.TensorSpec(shape=(None, self.config.num_channels, 224, 224)   ,	dtype=tf.floataa	)}





__lowerCAmelCase        =							R"\n    Parameters:\n    This model is a Tensorflow\n    [tf.keras.layers.Layer](https://www.tensorflow.org/api_docs/python/tf/keras/layers/Layer) sub-class. Use it as a\n    regular Tensorflow Module and refer to the Tensorflow documentation for all matter related to general usage and\n    behavior.\n        config ([`RegNetConfig`]): Model configuration class with all the parameters of the model.\n            Initializing with a config file does not load the weights associated with the model, only the\n            configuration. Check out the [`~TFPreTrainedModel.from_pretrained`] method to load the model weights.\n"

__lowerCAmelCase        =							R"\n    Args:\n        pixel_values (`tf.Tensor` of shape `(batch_size, num_channels, height, width)`):\n            Pixel values. Pixel values can be obtained using [`AutoImageProcessor`]. See\n            [`ConveNextImageProcessor.__call__`] for details.\n        output_hidden_states (`bool`, *optional*):\n            Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\n            more detail.\n        return_dict (`bool`, *optional*):\n            Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\n"




@add_start_docstrings(
    '''The bare RegNet model outputting raw features without any specific head on top.'''							,       __A							,       )
class   __SCREAMING_SNAKE_CASE       (__A       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	*UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(UpperCamelCase__   ,	*UpperCamelCase__   ,	**UpperCamelCase__	)
         a_						     =			TFRegNetMainLayer(UpperCamelCase__   ,	name='regnet'	)







  @unpack_inputs
  @add_start_docstrings_to_model_forward(UpperCamelCase__	)
  @add_code_sample_docstrings(
      checkpoint=_CHECKPOINT_FOR_DOC   ,	output_type=UpperCamelCase__   ,	config_class=_CONFIG_FOR_DOC   ,	modality='vision'   ,	expected_output=_EXPECTED_OUTPUT_SHAPE   ,	)
  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__=False   ,	):






         """simple docstring"""


         a_						     =			(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         a_						     =			return_dict if return_dict is not None else self.config.use_return_dict

         a_						     =			self.regnet(
             pixel_values=UpperCamelCase__   ,	output_hidden_states=UpperCamelCase__   ,	return_dict=UpperCamelCase__   ,	training=UpperCamelCase__   ,	)
         if not return_dict:
                return (outputs[0],) + outputs[1:]

         return TFBaseModelOutputWithPoolingAndNoAttention(
             last_hidden_state=outputs.last_hidden_state   ,	pooler_output=outputs.pooler_output   ,	hidden_states=outputs.hidden_states   ,	)





@add_start_docstrings(
    '''
    RegNet Model with an image classification head on top (a linear layer on top of the pooled features), e.g. for
    ImageNet.
    '''							,       __A							,       )
class   __SCREAMING_SNAKE_CASE       (__A							,       __A       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	*UpperCamelCase__   ,	**UpperCamelCase__	):






         """simple docstring"""


         super().__init__(UpperCamelCase__   ,	*UpperCamelCase__   ,	**UpperCamelCase__	)
         a_						     =			config.num_labels
         a_						     =			TFRegNetMainLayer(UpperCamelCase__   ,	name='regnet'	)
         # classification head
         a_						     =			[
             tf.keras.layers.Flatten(),
             tf.keras.layers.Dense(config.num_labels   ,	name='classifier.1'	) if config.num_labels > 0 else tf.identity,
         ]







  @unpack_inputs
  @add_start_docstrings_to_model_forward(UpperCamelCase__	)
  @add_code_sample_docstrings(
      checkpoint=_IMAGE_CLASS_CHECKPOINT   ,	output_type=UpperCamelCase__   ,	config_class=_CONFIG_FOR_DOC   ,	expected_output=_IMAGE_CLASS_EXPECTED_OUTPUT   ,	)
  def    _a       (			self   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__=False   ,	):






         """simple docstring"""


         a_						     =			(
             output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
         )
         a_						     =			return_dict if return_dict is not None else self.config.use_return_dict

         a_						     =			self.regnet(
             UpperCamelCase__   ,	output_hidden_states=UpperCamelCase__   ,	return_dict=UpperCamelCase__   ,	training=UpperCamelCase__	)

         a_						     =			outputs.pooler_output if return_dict else outputs[1]

         a_						     =			self.classifier[0](UpperCamelCase__	)
         a_						     =			self.classifier[1](UpperCamelCase__	)

         a_						     =			None if labels is None else self.hf_compute_loss(labels=UpperCamelCase__   ,	logits=UpperCamelCase__	)

         if not return_dict:
                a_						     =			(logits,) + outputs[2:]
                return ((loss,) + output) if loss is not None else output

         return TFSequenceClassifierOutput(loss=UpperCamelCase__   ,	logits=UpperCamelCase__   ,	hidden_states=outputs.hidden_states	)












'''simple docstring'''







import multiprocessing
import os
from typing import BinaryIO, Optional, Union

import fsspec

from .. import Dataset, Features, NamedSplit, config
from ..formatting import query_table
from ..packaged_modules.json.json import Json
from ..utils import logging
from ..utils.typing import NestedDataStructureLike, PathLike
from .abc import AbstractDatasetReader




class   __SCREAMING_SNAKE_CASE       (__A       ):


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = False   ,	UpperCamelCase__ = False   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	**UpperCamelCase__   ,	):






         """simple docstring"""


         super().__init__(
             UpperCamelCase__   ,	split=UpperCamelCase__   ,	features=UpperCamelCase__   ,	cache_dir=UpperCamelCase__   ,	keep_in_memory=UpperCamelCase__   ,	streaming=UpperCamelCase__   ,	num_proc=UpperCamelCase__   ,	**UpperCamelCase__   ,	)
         a_						     =			field
         a_						     =			path_or_paths if isinstance(UpperCamelCase__   ,	UpperCamelCase__	) else {self.split: path_or_paths}
         a_						     =			Json(
             cache_dir=UpperCamelCase__   ,	data_files=UpperCamelCase__   ,	features=UpperCamelCase__   ,	field=UpperCamelCase__   ,	**UpperCamelCase__   ,	)







  def    _a       (			self	):






         """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=UpperCamelCase__   ,	download_mode=UpperCamelCase__   ,	verification_mode=UpperCamelCase__   ,	base_path=UpperCamelCase__   ,	num_proc=self.num_proc   ,	)
                a_						     =			self.builder.as_dataset(
                    split=self.split   ,	verification_mode=UpperCamelCase__   ,	in_memory=self.keep_in_memory	)
         return dataset





class   __SCREAMING_SNAKE_CASE       :


  """simple docstring"""


  def __init__(			self   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__ = None   ,	UpperCamelCase__ = None   ,	**UpperCamelCase__   ,	):






         """simple docstring"""


         if num_proc is not None and num_proc <= 0:
                raise ValueError(f'num_proc {num_proc} must be an integer > 0.'	)

         a_						     =			dataset
         a_						     =			path_or_buf
         a_						     =			batch_size if batch_size else config.DEFAULT_MAX_BATCH_SIZE
         a_						     =			num_proc
         a_						     =			'utf-8'
         a_						     =			to_json_kwargs







  def    _a       (			self	):






         """simple docstring"""


         a_						     =			self.to_json_kwargs.pop('path_or_buf'   ,	UpperCamelCase__	)
         a_						     =			self.to_json_kwargs.pop('orient'   ,	'records'	)
         a_						     =			self.to_json_kwargs.pop('lines'   ,	True if orient == 'records' else False	)
         a_						     =			self.to_json_kwargs.pop('index'   ,	False if orient in ['split', 'table'] else True	)
         a_						     =			self.to_json_kwargs.pop('compression'   ,	UpperCamelCase__	)

         if compression not in [None, "infer", "gzip", "bz2", "xz"]:
                raise NotImplementedError(f'`datasets` currently does not support {compression} compression'	)

         if isinstance(self.path_or_buf   ,	(str, bytes, os.PathLike)	):
                with fsspec.open(self.path_or_buf   ,	'wb'   ,	compression=UpperCamelCase__	) as buffer:
                       a_						     =			self._write(file_obj=UpperCamelCase__   ,	orient=UpperCamelCase__   ,	lines=UpperCamelCase__   ,	index=UpperCamelCase__   ,	**self.to_json_kwargs	)
         else:
                if compression:
                       raise NotImplementedError(
                           f'The compression parameter is not supported when writing to a buffer, but compression={compression}'
                           ' was passed. Please provide a local path instead.'	)
                a_						     =			self._write(
                    file_obj=self.path_or_buf   ,	orient=UpperCamelCase__   ,	lines=UpperCamelCase__   ,	index=UpperCamelCase__   ,	**self.to_json_kwargs	)
         return written







  def    _a       (			self   ,	UpperCamelCase__	):






         """simple docstring"""


         a_     ,	a_     ,	a_     ,	a_     ,	a_						     =			args

         a_						     =			query_table(
             table=self.dataset.data   ,	key=slice(UpperCamelCase__   ,	offset + self.batch_size	)   ,	indices=self.dataset._indices   ,	)
         a_						     =			batch.to_pandas().to_json(
             path_or_buf=UpperCamelCase__   ,	orient=UpperCamelCase__   ,	lines=UpperCamelCase__   ,	index=UpperCamelCase__   ,	**UpperCamelCase__	)
         if not json_str.endswith('\n'	):
                json_str += "\n"
         return json_str.encode(self.encoding	)







  def    _a       (			self   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	UpperCamelCase__   ,	**UpperCamelCase__   ,	):






         """simple docstring"""


         a_						     =			0

         if self.num_proc is None or self.num_proc == 1:
                for offset in logging.tqdm(
                    range(0   ,	len(self.dataset	)   ,	self.batch_size	)   ,	unit='ba'   ,	disable=not logging.is_progress_bar_enabled()   ,	desc='Creating json from Arrow format'   ,	):
                       a_						     =			self._batch_json((offset, orient, lines, index, to_json_kwargs)	)
                       written += file_obj.write(UpperCamelCase__	)
         else:
                a_     ,	a_						     =			len(self.dataset	), self.batch_size
                with multiprocessing.Pool(self.num_proc	) as pool:
                       for json_str in logging.tqdm(
                           pool.imap(
                               self._batch_json   ,	[(offset, orient, lines, index, to_json_kwargs) for offset in range(0   ,	UpperCamelCase__   ,	UpperCamelCase__	)]   ,	)   ,	total=(num_rows // batch_size) + 1 if num_rows % batch_size else num_rows // batch_size   ,	unit='ba'   ,	disable=not logging.is_progress_bar_enabled()   ,	desc='Creating json from Arrow format'   ,	):
                              written += file_obj.write(UpperCamelCase__	)

         return written




