def       __lowerCamelCase		(						lowerCAmelCase__	,  lowerCAmelCase__	,  lowerCAmelCase__	,  lowerCAmelCase__	):
       if start == end:
              return start if lst[start] > item else start + 1
       if start > end:
              return start

       lowerCAmelCase__     	=					(start + end) // 2
       if lst[mid] < item:
              return binary_search(lowerCAmelCase__	,  lowerCAmelCase__	,  mid + 1	,  lowerCAmelCase__	)
       elif lst[mid] > item:
              return binary_search(lowerCAmelCase__	,  lowerCAmelCase__	,  lowerCAmelCase__	,  mid - 1	)
       else:
              return mid






def       __lowerCamelCase		(						lowerCAmelCase__	):
       lowerCAmelCase__     	=					len(lowerCAmelCase__	)

       for index in range(1	,  lowerCAmelCase__	):
              lowerCAmelCase__     	=					lst[index]
              lowerCAmelCase__     	=					binary_search(lowerCAmelCase__	,  lowerCAmelCase__	,  0	,  index - 1	)
              lowerCAmelCase__     	=					lst[:pos] + [value] + lst[pos:index] + lst[index + 1 :]

       return lst






def       __lowerCamelCase		(						lowerCAmelCase__	,  lowerCAmelCase__	):
       if not left:
              return right

       if not right:
              return left

       if left[0] < right[0]:
              return [left[0], *merge(left[1:]	,  lowerCAmelCase__	)]

       return [right[0], *merge(lowerCAmelCase__	,  right[1:]	)]






def       __lowerCamelCase		(						lowerCAmelCase__	):
       lowerCAmelCase__     	=					len(lowerCAmelCase__	)
       lowerCAmelCase__	,					lowerCAmelCase__     	=					[], []
       lowerCAmelCase__     	=					[lst[0]]
       lowerCAmelCase__     	=					[]
       lowerCAmelCase__     	=					1
       while i < length:
              if lst[i] < lst[i - 1]:
                     runs.append(lowerCAmelCase__	)
                     lowerCAmelCase__     	=					[lst[i]]
              else:
                     new_run.append(lst[i]	)
              i += 1
       runs.append(lowerCAmelCase__	)

       for run in runs:
              sorted_runs.append(insertion_sort(lowerCAmelCase__	)	)
       for run in sorted_runs:
              lowerCAmelCase__     	=					merge(lowerCAmelCase__	,  lowerCAmelCase__	)

       return sorted_array






def       __lowerCamelCase		(						):
       lowerCAmelCase__     	=					[5, 9, 1_0, 3, -4, 5, 1_7_8, 9_2, 4_6, -1_8, 0, 7]
       lowerCAmelCase__     	=					tim_sort(lowerCAmelCase__	)
       print(lowerCAmelCase__	)


if __name__ == "__main__":
    main()

import argparse

import torch
from flax.training.checkpoints import restore_checkpoint

from transformers import FNetConfig, FNetForPreTraining
from transformers.utils import logging


logging.set_verbosity_info()






def       __lowerCamelCase		(						lowerCAmelCase__	,  lowerCAmelCase__	,  lowerCAmelCase__	):
       # Initialise PyTorch model
       lowerCAmelCase__     	=					FNetConfig.from_json_file(lowerCAmelCase__	)
       print(F"""Building PyTorch model from configuration: {config}"""	)
       lowerCAmelCase__     	=					FNetForPreTraining(lowerCAmelCase__	)

       lowerCAmelCase__     	=					restore_checkpoint(lowerCAmelCase__	,  lowerCAmelCase__	)
       lowerCAmelCase__     	=					checkpoint_dict['target']

       # Embeddings
       # Position IDs
       lowerCAmelCase__     	=					fnet_pretraining_model.state_dict()

       lowerCAmelCase__     	=					state_dict['fnet.embeddings.position_ids']
       lowerCAmelCase__     	=					{'fnet.embeddings.position_ids': position_ids}
       # Embedding Layers
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['word']['embedding']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['position']['embedding'][0]	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['type']['embedding']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['hidden_mapping_in']['kernel']	).T
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['hidden_mapping_in']['bias']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['layer_norm']['scale']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['layer_norm']['bias']	)

       # Encoder Layers
       for layer in range(config.num_hidden_layers	):
              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""encoder_{layer}"""]['mixing_layer_norm']['scale']	)
              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""encoder_{layer}"""]['mixing_layer_norm']['bias']	)

              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""feed_forward_{layer}"""]['intermediate']['kernel']	).T
              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""feed_forward_{layer}"""]['intermediate']['bias']	)

              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""feed_forward_{layer}"""]['output']['kernel']	).T
              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""feed_forward_{layer}"""]['output']['bias']	)

              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""encoder_{layer}"""]['output_layer_norm']['scale']	)
              lowerCAmelCase__     	=					torch.tensor(
                  pretrained_model_params['encoder'][F"""encoder_{layer}"""]['output_layer_norm']['bias']	)

       # Pooler Layers
       lowerCAmelCase__     	=					torch.tensor(pretrained_model_params['encoder']['pooler']['kernel']	).T
       lowerCAmelCase__     	=					torch.tensor(pretrained_model_params['encoder']['pooler']['bias']	)

       # Masked LM Layers
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['predictions_dense']['kernel']	).T
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['predictions_dense']['bias']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['predictions_layer_norm']['scale']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['predictions_layer_norm']['bias']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['encoder']['embedder']['word']['embedding']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['predictions_output']['output_bias']	)
       lowerCAmelCase__     	=					torch.tensor(pretrained_model_params['predictions_output']['output_bias']	)

       # Seq Relationship Layers
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['classification']['output_kernel']	)
       lowerCAmelCase__     	=					torch.tensor(
           pretrained_model_params['classification']['output_bias']	)

       # Load State Dict
       fnet_pretraining_model.load_state_dict(lowerCAmelCase__	)

       # Save PreTrained
       print(F"""Saving pretrained model to {save_path}"""	)
       fnet_pretraining_model.save_pretrained(lowerCAmelCase__	)


if __name__ == "__main__":
    lowerCAmelCase__							= argparse.ArgumentParser()
    # Required parameters
    parser.add_argument(
        '--flax_checkpoint_path', default=None, type=str, required=True, help='Path to the TensorFlow checkpoint path.'
    )
    parser.add_argument(
        '--fnet_config_file',
        default=None,
        type=str,
        required=True,
        help=(
            'The config json file corresponding to the pre-trained FNet model. \n'
            'This specifies the model architecture.'
        ),
    )
    parser.add_argument('--save_path', default=None, type=str, required=True, help='Path to the output model.')
    lowerCAmelCase__							= parser.parse_args()
    convert_flax_checkpoint_to_pytorch(args.flax_checkpoint_path, args.fnet_config_file, args.save_path)
