






import os
import tempfile
from functools import partial
from unittest import TestCase
from unittest.mock import patch

import datasets
import datasets.config

from .utils import require_beam





class       __a  (   datasets.BeamBasedBuilder	):







 def  __lowercase (		self :       Union[str, Any]						):


      '''simple docstring'''






      return datasets.DatasetInfo(
          features=datasets.Features({"content": datasets.Value("string"						)}						)							,       supervised_keys=SCREAMING_SNAKE_CASE							,       )







 def  __lowercase (		self :       Any							,       SCREAMING_SNAKE_CASE :       Any							,       SCREAMING_SNAKE_CASE :       Any						):


      '''simple docstring'''






      return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,       gen_kwargs={"examples": get_test_dummy_examples()}						)]







 def  __lowercase (		self :       List[Any]							,       SCREAMING_SNAKE_CASE :       int							,       SCREAMING_SNAKE_CASE :       Optional[Any]						):


      '''simple docstring'''






      import apache_beam as beam

      return pipeline | "Load Examples" >> beam.Create(SCREAMING_SNAKE_CASE						)







class       __a  (   datasets.BeamBasedBuilder	):







 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      return datasets.DatasetInfo(
          features=datasets.Features({"a": datasets.Sequence({"b": datasets.Value("string"						)}						)}						)							,       supervised_keys=SCREAMING_SNAKE_CASE							,       )







 def  __lowercase (		self :       str							,       SCREAMING_SNAKE_CASE :       int							,       SCREAMING_SNAKE_CASE :       Tuple						):


      '''simple docstring'''






      return [
          datasets.SplitGenerator(name=datasets.Split.TRAIN							,       gen_kwargs={"examples": get_test_nested_examples()}						)
      ]







 def  __lowercase (		self :       str							,       SCREAMING_SNAKE_CASE :       str							,       SCREAMING_SNAKE_CASE :       Optional[Any]						):


      '''simple docstring'''






      import apache_beam as beam

      return pipeline | "Load Examples" >> beam.Create(SCREAMING_SNAKE_CASE						)







def 		SCREAMING_SNAKE_CASE							( )			->     int:
     return [(i, {"content": content}) for i, content in enumerate(["foo", "bar", "foobar"]      )]







def 		SCREAMING_SNAKE_CASE							( )			->     List[Any]:
     return [(i, {"a": {"b": [content]}}) for i, content in enumerate(["foo", "bar", "foobar"]      )]





class       __a  (   A__	):







 @require_beam
 def  __lowercase (		self :       List[str]						):


      '''simple docstring'''






      UpperCamelCase__      :       str	    =  len(get_test_dummy_examples()						)
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
           UpperCamelCase__      :       Dict	    =  DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE							,       beam_runner="DirectRunner"						)
           builder.download_and_prepare()
           self.assertTrue(
               os.path.exists(
                   os.path.join(SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       F'{builder.name}-train.arrow'						)						)						)
           self.assertDictEqual(builder.info.features							,       datasets.Features({"content": datasets.Value("string"						)}						)						)
           UpperCamelCase__      :       Union[str, Any]	    =  builder.as_dataset()
           self.assertEqual(dset["train"].num_rows							,       SCREAMING_SNAKE_CASE						)
           self.assertEqual(dset["train"].info.splits["train"].num_examples							,       SCREAMING_SNAKE_CASE						)
           self.assertDictEqual(dset["train"][0]							,       get_test_dummy_examples()[0][1]						)
           self.assertDictEqual(
               dset["train"][expected_num_examples - 1]							,       get_test_dummy_examples()[expected_num_examples - 1][1]						)
           self.assertTrue(
               os.path.exists(os.path.join(SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       "dataset_info.json"						)						)						)
           del dset







 @require_beam
 def  __lowercase (		self :       Tuple						):


      '''simple docstring'''






      import apache_beam as beam

      UpperCamelCase__      :       Tuple	    =  beam.io.parquetio.WriteToParquet

      UpperCamelCase__      :       Optional[Any]	    =  len(get_test_dummy_examples()						)
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
           UpperCamelCase__      :       Dict	    =  DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE							,       beam_runner="DirectRunner"						)
           with patch("apache_beam.io.parquetio.WriteToParquet"						) as write_parquet_mock:
                UpperCamelCase__      :       Dict	    =  partial(SCREAMING_SNAKE_CASE							,       num_shards=2						)
                builder.download_and_prepare()
           self.assertTrue(
               os.path.exists(
                   os.path.join(
                       SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       F'{builder.name}-train-00000-of-00002.arrow'						)						)						)
           self.assertTrue(
               os.path.exists(
                   os.path.join(
                       SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       F'{builder.name}-train-00000-of-00002.arrow'						)						)						)
           self.assertDictEqual(builder.info.features							,       datasets.Features({"content": datasets.Value("string"						)}						)						)
           UpperCamelCase__      :       Optional[int]	    =  builder.as_dataset()
           self.assertEqual(dset["train"].num_rows							,       SCREAMING_SNAKE_CASE						)
           self.assertEqual(dset["train"].info.splits["train"].num_examples							,       SCREAMING_SNAKE_CASE						)
           # Order is not preserved when sharding, so we just check that all the elements are there
           self.assertListEqual(sorted(dset["train"]["content"]						)							,       sorted(["foo", "bar", "foobar"]						)						)
           self.assertTrue(
               os.path.exists(os.path.join(SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       "dataset_info.json"						)						)						)
           del dset







 @require_beam
 def  __lowercase (		self :       List[str]						):


      '''simple docstring'''






      with tempfile.TemporaryDirectory() as tmp_cache_dir:
           UpperCamelCase__      :       Tuple	    =  DummyBeamDataset(cache_dir=SCREAMING_SNAKE_CASE						)
           self.assertRaises(datasets.builder.MissingBeamOptions							,       builder.download_and_prepare						)







 @require_beam
 def  __lowercase (		self :       Optional[Any]						):


      '''simple docstring'''






      UpperCamelCase__      :       Tuple	    =  len(get_test_nested_examples()						)
      with tempfile.TemporaryDirectory() as tmp_cache_dir:
           UpperCamelCase__      :       Tuple	    =  NestedBeamDataset(cache_dir=SCREAMING_SNAKE_CASE							,       beam_runner="DirectRunner"						)
           builder.download_and_prepare()
           self.assertTrue(
               os.path.exists(
                   os.path.join(SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       F'{builder.name}-train.arrow'						)						)						)
           self.assertDictEqual(
               builder.info.features							,       datasets.Features({"a": datasets.Sequence({"b": datasets.Value("string"						)}						)}						)						)
           UpperCamelCase__      :       Dict	    =  builder.as_dataset()
           self.assertEqual(dset["train"].num_rows							,       SCREAMING_SNAKE_CASE						)
           self.assertEqual(dset["train"].info.splits["train"].num_examples							,       SCREAMING_SNAKE_CASE						)
           self.assertDictEqual(dset["train"][0]							,       get_test_nested_examples()[0][1]						)
           self.assertDictEqual(
               dset["train"][expected_num_examples - 1]							,       get_test_nested_examples()[expected_num_examples - 1][1]						)
           self.assertTrue(
               os.path.exists(os.path.join(SCREAMING_SNAKE_CASE							,       builder.name							,       "default"							,       "0.0.0"							,       "dataset_info.json"						)						)						)
           del dset







from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


lowerCamelCase     :							List[Any]    =logging.get_logger(__name__)

lowerCamelCase     :							Optional[Any]    ={
    '''google/bit-50''': '''https://huggingface.co/google/bit-50/resolve/main/config.json''',
}





class       __a  (   A__	,       A__	):
 _lowerCAmelCase	:	Union[str, Any]				=			'''bit'''
 _lowerCAmelCase	:	List[str]				=			['''preactivation''', '''bottleneck''']
 _lowerCAmelCase	:	Any				=			['''SAME''', '''VALID''']







 def __init__(		self :       str							,       SCREAMING_SNAKE_CASE :       Tuple=3							,       SCREAMING_SNAKE_CASE :       str=64							,       SCREAMING_SNAKE_CASE :       List[Any]=[2_56, 5_12, 10_24, 20_48]							,       SCREAMING_SNAKE_CASE :       Union[str, Any]=[3, 4, 6, 3]							,       SCREAMING_SNAKE_CASE :       str="preactivation"							,       SCREAMING_SNAKE_CASE :       Any="relu"							,       SCREAMING_SNAKE_CASE :       Dict=None							,       SCREAMING_SNAKE_CASE :       List[Any]=32							,       SCREAMING_SNAKE_CASE :       Tuple=0.0							,       SCREAMING_SNAKE_CASE :       Dict=False							,       SCREAMING_SNAKE_CASE :       int=32							,       SCREAMING_SNAKE_CASE :       str=1							,       SCREAMING_SNAKE_CASE :       List[str]=None							,       SCREAMING_SNAKE_CASE :       Optional[int]=None							,       **SCREAMING_SNAKE_CASE :       int							,       ):


      '''simple docstring'''






      super().__init__(**SCREAMING_SNAKE_CASE						)
      if layer_type not in self.layer_types:
           raise ValueError(F'layer_type={layer_type} is not one of {",".join(self.layer_types						)}'						)
      if global_padding is not None:
           if global_padding.upper() in self.supported_padding:
                UpperCamelCase__      :       Any	    =  global_padding.upper()
           else:
                raise ValueError(F'Padding strategy {global_padding} not supported'						)
      UpperCamelCase__      :       Dict	    =  num_channels
      UpperCamelCase__      :       Dict	    =  embedding_size
      UpperCamelCase__      :       Tuple	    =  hidden_sizes
      UpperCamelCase__      :       Any	    =  depths
      UpperCamelCase__      :       Optional[int]	    =  layer_type
      UpperCamelCase__      :       int	    =  hidden_act
      UpperCamelCase__      :       str	    =  global_padding
      UpperCamelCase__      :       Any	    =  num_groups
      UpperCamelCase__      :       str	    =  drop_path_rate
      UpperCamelCase__      :       Optional[Any]	    =  embedding_dynamic_padding
      UpperCamelCase__      :       Tuple	    =  output_stride
      UpperCamelCase__      :       List[str]	    =  width_factor

      UpperCamelCase__      :       Any	    =  ["stem"] + [F'stage{idx}' for idx in range(1							,       len(SCREAMING_SNAKE_CASE						) + 1						)]
      UpperCamelCase__    ,					UpperCamelCase__      :       Union[str, Any]	    =  get_aligned_output_features_output_indices(
          out_features=SCREAMING_SNAKE_CASE							,       out_indices=SCREAMING_SNAKE_CASE							,       stage_names=self.stage_names						)