


'''simple docstring'''






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  __magic_name__							(		datasets.BeamBasedBuilder    ):






       def       lowerCAmelCase		(      self)						->  Any:




          '''simple docstring'''
          return datasets.DatasetInfo(
              features=datasets.Features({'content': datasets.Value('string')})  ,							supervised_keys=snake_case  ,							)






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case)						->  Optional[Any]:




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






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case)						->  str:




          '''simple docstring'''
          import apache_beam as beam

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






class  __magic_name__							(		datasets.BeamBasedBuilder    ):






       def       lowerCAmelCase		(      self)						->  Dict:




          '''simple docstring'''
          return datasets.DatasetInfo(
              features=datasets.Features({'a': datasets.Sequence({'b': datasets.Value('string')})})  ,							supervised_keys=snake_case  ,							)






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case)						->  List[str]:




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






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case)						->  Optional[Any]:




          '''simple docstring'''
          import apache_beam as beam

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






def lowerCamelCase__      (						):







   '''simple docstring'''




   return [(i, {"content": content}) for i, content in enumerate(['foo', 'bar', 'foobar']							)]





def lowerCamelCase__      (						):







   '''simple docstring'''




   return [(i, {"a": {"b": [content]}}) for i, content in enumerate(['foo', 'bar', 'foobar']							)]






class  __magic_name__							(		lowerCAmelCase    ):






       @require_beam
       def       lowerCAmelCase		(      self)						->  List[Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =len(get_test_dummy_examples())
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
             _UpperCAmelCase       :       int							   =DummyBeamDataset(cache_dir=snake_case  ,							beam_runner='DirectRunner')
             builder.download_and_prepare()
             self.assertTrue(
                 os.path.exists(
                     os.path.join(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       :       Optional[int]							   =builder.as_dataset()
             self.assertEqual(dset['train'].num_rows  ,							snake_case)
             self.assertEqual(dset['train'].info.splits['train'].num_examples  ,							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(snake_case  ,							builder.name  ,							'default'  ,							'0.0.0'  ,							'dataset_info.json')))
             del dset






       @require_beam
       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          import apache_beam as beam

          _UpperCAmelCase       :       Optional[int]							   =beam.io.parquetio.WriteToParquet

          _UpperCAmelCase       :       str							   =len(get_test_dummy_examples())
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
             _UpperCAmelCase       :       int							   =DummyBeamDataset(cache_dir=snake_case  ,							beam_runner='DirectRunner')
             with patch('apache_beam.io.parquetio.WriteToParquet') as write_parquet_mock:
                _UpperCAmelCase       :       str							   =partial(snake_case  ,							num_shards=2)
                builder.download_and_prepare()
             self.assertTrue(
                 os.path.exists(
                     os.path.join(
                         snake_case  ,							builder.name  ,							'default'  ,							'0.0.0'  ,							f"{builder.name}-train-00000-of-00002.arrow")))
             self.assertTrue(
                 os.path.exists(
                     os.path.join(
                         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[Any]							   =builder.as_dataset()
             self.assertEqual(dset['train'].num_rows  ,							snake_case)
             self.assertEqual(dset['train'].info.splits['train'].num_examples  ,							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(snake_case  ,							builder.name  ,							'default'  ,							'0.0.0'  ,							'dataset_info.json')))
             del dset






       @require_beam
       def       lowerCAmelCase		(      self)						->  Optional[Any]:




          '''simple docstring'''
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
             _UpperCAmelCase       :       List[str]							   =DummyBeamDataset(cache_dir=snake_case)
             self.assertRaises(datasets.builder.MissingBeamOptions  ,							builder.download_and_prepare)






       @require_beam
       def       lowerCAmelCase		(      self)						->  str:




          '''simple docstring'''
          _UpperCAmelCase       :       str							   =len(get_test_nested_examples())
          with tempfile.TemporaryDirectory() as tmp_cache_dir:
             _UpperCAmelCase       :       Union[str, Any]							   =NestedBeamDataset(cache_dir=snake_case  ,							beam_runner='DirectRunner')
             builder.download_and_prepare()
             self.assertTrue(
                 os.path.exists(
                     os.path.join(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  ,							snake_case)
             self.assertEqual(dset['train'].info.splits['train'].num_examples  ,							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(snake_case  ,							builder.name  ,							'default'  ,							'0.0.0'  ,							'dataset_info.json')))
             del dset





'''simple docstring'''






from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowercase							=logging.get_logger(__name__)

lowercase							={
    'facebook/levit-128S': 'https://huggingface.co/facebook/levit-128S/resolve/main/config.json',
    # See all LeViT models at https://huggingface.co/models?filter=levit
}






class  __magic_name__							(		lowerCAmelCase    ):
       UpperCAmelCase										="levit"






       def __init__(      self  ,							snake_case=2_2_4  ,							snake_case=3  ,							snake_case=3  ,							snake_case=2  ,							snake_case=1  ,							snake_case=1_6  ,							snake_case=[1_2_8, 2_5_6, 3_8_4]  ,							snake_case=[4, 8, 1_2]  ,							snake_case=[4, 4, 4]  ,							snake_case=[1_6, 1_6, 1_6]  ,							snake_case=0  ,							snake_case=[2, 2, 2]  ,							snake_case=[2, 2, 2]  ,							snake_case=0.02  ,							**snake_case  ,							)						->  Any:




          '''simple docstring'''
          super().__init__(**snake_case)
          _UpperCAmelCase       :       List[str]							   =image_size
          _UpperCAmelCase       :       str							   =num_channels
          _UpperCAmelCase       :       int							   =kernel_size
          _UpperCAmelCase       :       Any							   =stride
          _UpperCAmelCase       :       Tuple							   =padding
          _UpperCAmelCase       :       Optional[int]							   =hidden_sizes
          _UpperCAmelCase       :       List[str]							   =num_attention_heads
          _UpperCAmelCase       :       List[Any]							   =depths
          _UpperCAmelCase       :       Any							   =key_dim
          _UpperCAmelCase       :       List[Any]							   =drop_path_rate
          _UpperCAmelCase       :       int							   =patch_size
          _UpperCAmelCase       :       Tuple							   =attention_ratio
          _UpperCAmelCase       :       Any							   =mlp_ratio
          _UpperCAmelCase       :       Optional[Any]							   =initializer_range
          _UpperCAmelCase       :       str							   =[
              ['Subsample', key_dim[0], hidden_sizes[0] // key_dim[0], 4, 2, 2],
              ['Subsample', key_dim[0], hidden_sizes[1] // key_dim[0], 4, 2, 2],
          ]






class  __magic_name__							(		lowerCAmelCase    ):
       UpperCAmelCase										=version.parse("1.11"    )






       @property
       def       lowerCAmelCase		(      self)						->  Mapping[str, Mapping[int, str]]:




          '''simple docstring'''
          return OrderedDict(
              [
                  ('pixel_values', {0: 'batch', 1: 'num_channels', 2: 'height', 3: 'width'}),
              ])






       @property
       def       lowerCAmelCase		(      self)						->  float:




          '''simple docstring'''
          return 1E-4

