





#
# Sort large text files in a minimum amount of memory
#
import argparse
import os



class 				__snake_case  :


    '''simple docstring'''







    lowerCamelCase__						:		Union[str, Any]							=  """block_{0}.dat"""



    def __init__(					self      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= filename
        SCREAMING_SNAKE_CASE__       							= []



    def    lowercase_				(					self      ,							A_      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= self.BLOCK_FILENAME_FORMAT.format(A_    )
        with open(A_      ,							'''w'''    ) as file:
            file.write(A_    )
        self.block_filenames.append(A_    )



    def    lowercase_				(					self    ):





        '''simple docstring'''

        return self.block_filenames



    def    lowercase_				(					self      ,							A_      ,							A_=None    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= 0
        with open(self.filename    ) as file:
            while True:
                SCREAMING_SNAKE_CASE__       							= file.readlines(A_    )

                if lines == []:
                    break

                if sort_key is None:
                    lines.sort()
                else:
                    lines.sort(key=A_    )

                self.write_block(''''''.join(A_    )      ,							A_    )
                i += 1




    def    lowercase_				(					self    ):





        '''simple docstring'''

        map(os.remove      ,							self.block_filenames    )





class 				__snake_case  :


    '''simple docstring'''







    def    lowercase_				(					self      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= -1
        SCREAMING_SNAKE_CASE__       							= None

        for i in range(len(A_    )    ):
            if min_str is None or choices[i] < min_str:
                SCREAMING_SNAKE_CASE__       							= i

        return min_index





class 				__snake_case  :


    '''simple docstring'''







    def __init__(					self      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= files
        SCREAMING_SNAKE_CASE__       							= set()
        SCREAMING_SNAKE_CASE__       							= len(A_    )
        SCREAMING_SNAKE_CASE__       							= {i: None for i in range(self.num_buffers    )}



    def    lowercase_				(					self    ):





        '''simple docstring'''

        return {
            i: self.buffers[i] for i in range(self.num_buffers    ) if i not in self.empty
        }



    def    lowercase_				(					self    ):





        '''simple docstring'''

        for i in range(self.num_buffers    ):
            if self.buffers[i] is None and i not in self.empty:
                SCREAMING_SNAKE_CASE__       							= self.files[i].readline()

                if self.buffers[i] == "":
                    self.empty.add(A_    )
                    self.files[i].close()

        if len(self.empty    ) == self.num_buffers:
            return False

        return True




    def    lowercase_				(					self      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= self.buffers[index]
        SCREAMING_SNAKE_CASE__       							= None

        return value





class 				__snake_case  :


    '''simple docstring'''







    def __init__(					self      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= merge_strategy



    def    lowercase_				(					self      ,							A_      ,							A_      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= FilesArray(self.get_file_handles(A_      ,							A_    )    )
        with open(A_      ,							'''w'''      ,							A_    ) as outfile:
            while buffers.refresh():
                SCREAMING_SNAKE_CASE__       							= self.merge_strategy.select(buffers.get_dict()    )
                outfile.write(buffers.unshift(A_    )    )




    def    lowercase_				(					self      ,							A_      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= {}

        for i in range(len(A_    )    ):
            SCREAMING_SNAKE_CASE__       							= open(filenames[i]      ,							'''r'''      ,							A_    )  # noqa: UP015

        return files





class 				__snake_case  :


    '''simple docstring'''







    def __init__(					self      ,							A_    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= block_size



    def    lowercase_				(					self      ,							A_      ,							A_=None    ):





        '''simple docstring'''

        SCREAMING_SNAKE_CASE__       							= self.get_number_blocks(A_      ,							self.block_size    )
        SCREAMING_SNAKE_CASE__       							= FileSplitter(A_    )
        splitter.split(self.block_size      ,							A_    )

        SCREAMING_SNAKE_CASE__       							= FileMerger(NWayMerge()    )
        SCREAMING_SNAKE_CASE__       							= self.block_size / (num_blocks + 1)
        merger.merge(splitter.get_block_filenames()      ,							filename + '''.out'''      ,							A_    )

        splitter.cleanup()




    def    lowercase_				(					self      ,							A_      ,							A_    ):





        '''simple docstring'''

        return (os.stat(A_    ).st_size / block_size) + 1





def        __snake_case       (						lowerCAmelCase_  )							->	Any:
    if string[-1].lower() == "k":
        return int(string[:-1]  ) * 1_0_2_4
    elif string[-1].lower() == "m":
        return int(string[:-1]  ) * 1_0_2_4 * 1_0_2_4
    elif string[-1].lower() == "g":
        return int(string[:-1]  ) * 1_0_2_4 * 1_0_2_4 * 1_0_2_4
    else:
        return int(lowerCAmelCase_  )


def        __snake_case       (						)							->	List[str]:
    SCREAMING_SNAKE_CASE__       							= argparse.ArgumentParser()
    parser.add_argument(
        '''-m'''   ,       '''--mem'''   ,       help='''amount of memory to use for sorting'''   ,       default='''100M'''  )
    parser.add_argument(
        '''filename'''   ,       metavar='''<filename>'''   ,       nargs=1   ,       help='''name of file to sort'''  )
    SCREAMING_SNAKE_CASE__       							= parser.parse_args()

    SCREAMING_SNAKE_CASE__       							= ExternalSort(parse_memory(args.mem  )  )
    sorter.sort(args.filename[0]  )


if __name__ == "__main__":
  main()







import functools
import operator

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


_A				:							Any							= logging.get_logger(__name__)

_A				:							Any							= {
    """facebook/hubert-base-ls960""": """https://huggingface.co/facebook/hubert-base-ls960/resolve/main/config.json""",
    # See all Hubert models at https://huggingface.co/models?filter=hubert
}



class 				__snake_case  (     __SCREAMING_SNAKE_CASE						):


    '''simple docstring'''







    lowerCamelCase__						:		int							=  """hubert"""



    def __init__(					self      ,							A_=32      ,							A_=7_68      ,							A_=12      ,							A_=12      ,							A_=30_72      ,							A_="gelu"      ,							A_=0.1      ,							A_=0.1      ,							A_=0.1      ,							A_=True      ,							A_=0.0      ,							A_=0.1      ,							A_=0.1      ,							A_=0.02      ,							A_=1E-5      ,							A_="group"      ,							A_="gelu"      ,							A_=(5_12, 5_12, 5_12, 5_12, 5_12, 5_12, 5_12)      ,							A_=(5, 2, 2, 2, 2, 2, 2)      ,							A_=(10, 3, 3, 3, 3, 2, 2)      ,							A_=False      ,							A_=1_28      ,							A_=16      ,							A_=False      ,							A_=True      ,							A_=0.05      ,							A_=10      ,							A_=2      ,							A_=0.0      ,							A_=10      ,							A_=0      ,							A_="sum"      ,							A_=False      ,							A_=False      ,							A_=2_56      ,							A_=0      ,							A_=1      ,							A_=2      ,							**A_      ,							):





        '''simple docstring'''

        super().__init__(**A_      ,							pad_token_id=A_      ,							bos_token_id=A_      ,							eos_token_id=A_    )
        SCREAMING_SNAKE_CASE__       							= hidden_size
        SCREAMING_SNAKE_CASE__       							= feat_extract_norm
        SCREAMING_SNAKE_CASE__       							= feat_extract_activation
        SCREAMING_SNAKE_CASE__       							= list(A_    )
        SCREAMING_SNAKE_CASE__       							= list(A_    )
        SCREAMING_SNAKE_CASE__       							= list(A_    )
        SCREAMING_SNAKE_CASE__       							= conv_bias
        SCREAMING_SNAKE_CASE__       							= num_conv_pos_embeddings
        SCREAMING_SNAKE_CASE__       							= num_conv_pos_embedding_groups
        SCREAMING_SNAKE_CASE__       							= len(self.conv_dim    )
        SCREAMING_SNAKE_CASE__       							= num_hidden_layers
        SCREAMING_SNAKE_CASE__       							= intermediate_size
        SCREAMING_SNAKE_CASE__       							= hidden_act
        SCREAMING_SNAKE_CASE__       							= num_attention_heads
        SCREAMING_SNAKE_CASE__       							= hidden_dropout
        SCREAMING_SNAKE_CASE__       							= attention_dropout
        SCREAMING_SNAKE_CASE__       							= activation_dropout
        SCREAMING_SNAKE_CASE__       							= feat_proj_layer_norm
        SCREAMING_SNAKE_CASE__       							= feat_proj_dropout
        SCREAMING_SNAKE_CASE__       							= final_dropout
        SCREAMING_SNAKE_CASE__       							= layerdrop
        SCREAMING_SNAKE_CASE__       							= layer_norm_eps
        SCREAMING_SNAKE_CASE__       							= initializer_range
        SCREAMING_SNAKE_CASE__       							= vocab_size
        SCREAMING_SNAKE_CASE__       							= do_stable_layer_norm
        SCREAMING_SNAKE_CASE__       							= use_weighted_layer_sum
        SCREAMING_SNAKE_CASE__       							= classifier_proj_size

        if (
            (len(self.conv_stride    ) != self.num_feat_extract_layers)
            or (len(self.conv_kernel    ) != self.num_feat_extract_layers)
            or (len(self.conv_dim    ) != self.num_feat_extract_layers)
        ):
            raise ValueError(
                '''Configuration for convolutional layers is incorrect. It is required that `len(config.conv_dim)` =='''
                ''' `len(config.conv_stride)` == `len(config.conv_kernel)`, but is `len(config.conv_dim) ='''
                f''' {len(self.conv_dim    )}`, `len(config.conv_stride) = {len(self.conv_stride    )}`,'''
                f''' `len(config.conv_kernel) = {len(self.conv_kernel    )}`.'''    )

        # fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
        SCREAMING_SNAKE_CASE__       							= apply_spec_augment
        SCREAMING_SNAKE_CASE__       							= mask_time_prob
        SCREAMING_SNAKE_CASE__       							= mask_time_length
        SCREAMING_SNAKE_CASE__       							= mask_time_min_masks
        SCREAMING_SNAKE_CASE__       							= mask_feature_prob
        SCREAMING_SNAKE_CASE__       							= mask_feature_length
        SCREAMING_SNAKE_CASE__       							= mask_feature_min_masks

        # ctc loss
        SCREAMING_SNAKE_CASE__       							= ctc_loss_reduction
        SCREAMING_SNAKE_CASE__       							= ctc_zero_infinity




    @property
    def    lowercase_				(					self    ):





        '''simple docstring'''

        return functools.reduce(operator.mul      ,							self.conv_stride      ,							1    )
