
"""simple docstring"""






import inspect
import logging
import os
import random
import shutil
import tempfile
import unittest

import pytest
import torch
from torch import nn
from torch.utils.data import DataLoader, TensorDataset

from accelerate import Accelerator
from accelerate.test_utils import execute_subprocess_async, require_cuda
from accelerate.utils import ProjectConfiguration, set_seed


__SCREAMING_SNAKE_CASE							=     logging.getLogger(__name__)




def       A_  (				__lowercase=2						,	__lowercase=3						,	__lowercase=16						,	__lowercase = 10						,	__lowercase = 2	):

 def get_dataset(__lowercase	):
  UpperCamelCase_     :					int   	=torch.randn(batch_size * n_batches						,	1	)
  return TensorDataset(__lowercase						,	a * x + b + 0.1 * torch.randn(batch_size * n_batches						,	1	)	)

 UpperCamelCase_     :					str   	=get_dataset(__lowercase	)
 UpperCamelCase_     :					Optional[int]   	=get_dataset(__lowercase	)
 UpperCamelCase_     :					List[str]   	=DataLoader(__lowercase						,	shuffle=__lowercase						,	batch_size=__lowercase						,	num_workers=4	)
 UpperCamelCase_     :					Optional[int]   	=DataLoader(__lowercase						,	shuffle=__lowercase						,	batch_size=__lowercase						,	num_workers=4	)
 return (train_dataloader, valid_dataloader)




def       A_  (				__lowercase						,	__lowercase						,	__lowercase						,	__lowercase						,	__lowercase						,	__lowercase=None	):
 UpperCamelCase_     :					List[Any]   	=[]
 for epoch in range(__lowercase	):
  # Train quickly
  model.train()
  for batch in dataloader:
   UpperCamelCase_	,     UpperCamelCase_     :					Dict   	=batch
   UpperCamelCase_     :					Tuple   	=model(__lowercase	)
   UpperCamelCase_     :					Optional[Any]   	=torch.nn.functional.mse_loss(__lowercase						,	__lowercase	)
   accelerator.backward(__lowercase	)
   optimizer.step()
   optimizer.zero_grad()
  rands.append(random.random()	)  # Introduce some randomness
  if scheduler is not None:
   scheduler.step()
 return rands





class 				a__					(						nn.Module       ):



     def __init__(							self :Tuple   ):







      '''simple docstring'''



      super().__init__()
      UpperCamelCase_     :					List[str]   	=nn.Parameter(torch.randn(1   )   )
      UpperCamelCase_     :					Dict   	=nn.Parameter(torch.randn(1   )   )




     def  lowerCamelCase_						(							self :Optional[Any]      ,  _lowerCamelCase :Dict   ):







      '''simple docstring'''



      return x * self.a + self.b





class 				a__					(						unittest.TestCase       ):



     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      with tempfile.TemporaryDirectory() as tmpdir:
       set_seed(42   )
       UpperCamelCase_     :					Optional[int]   	=DummyModel()
       UpperCamelCase_     :					int   	=torch.optim.Adam(params=model.parameters()      ,  lr=1E-3   )
       UpperCamelCase_	,     UpperCamelCase_     :					Dict   	=dummy_dataloaders()
       UpperCamelCase_     :					Union[str, Any]   	=ProjectConfiguration(total_limit=1      ,  project_dir=_lowerCamelCase      ,  automatic_checkpoint_naming=_lowerCamelCase   )
       # Train baseline
       UpperCamelCase_     :					Any   	=Accelerator(project_config=_lowerCamelCase   )
       UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_     :					str   	=accelerator.prepare(
           _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       # Save initial
       accelerator.save_state()

       # Save second state
       accelerator.save_state()
       self.assertEqual(len(os.listdir(accelerator.project_dir   )   )      ,  1   )



     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      with tempfile.TemporaryDirectory() as tmpdir:
       set_seed(42   )
       UpperCamelCase_     :					int   	=DummyModel()
       UpperCamelCase_     :					str   	=torch.optim.Adam(params=model.parameters()      ,  lr=1E-3   )
       UpperCamelCase_	,     UpperCamelCase_     :					Dict   	=dummy_dataloaders()
       # Train baseline
       UpperCamelCase_     :					List[Any]   	=Accelerator()
       UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_     :					List[str]   	=accelerator.prepare(
           _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       # Save initial
       UpperCamelCase_     :					int   	=os.path.join(_lowerCamelCase      ,  'initial'   )
       accelerator.save_state(_lowerCamelCase   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					int   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					str   	=optimizer.state_dict()
       UpperCamelCase_     :					Any   	=train(3      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					Tuple   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Any   	=optimizer.state_dict()

       # Train partially
       set_seed(42   )
       UpperCamelCase_     :					List[str]   	=DummyModel()
       UpperCamelCase_     :					List[Any]   	=torch.optim.Adam(params=model.parameters()      ,  lr=1E-3   )
       UpperCamelCase_	,     UpperCamelCase_     :					Union[str, Any]   	=dummy_dataloaders()
       UpperCamelCase_     :					Optional[Any]   	=Accelerator()
       UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_     :					Union[str, Any]   	=accelerator.prepare(
           _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       accelerator.load_state(_lowerCamelCase   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					str   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Tuple   	=optimizer.state_dict()
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )

       UpperCamelCase_     :					List[str]   	=train(2      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       # Save everything
       UpperCamelCase_     :					List[str]   	=os.path.join(_lowerCamelCase      ,  'checkpoint'   )
       accelerator.save_state(_lowerCamelCase   )

       # Load everything back in and make sure all states work
       accelerator.load_state(_lowerCamelCase   )
       test_rands += train(1      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					Optional[Any]   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Optional[Any]   	=optimizer.state_dict()
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )



     def  lowerCamelCase_						(							self :List[str]   ):







      '''simple docstring'''



      with tempfile.TemporaryDirectory() as tmpdir:
       set_seed(42   )
       UpperCamelCase_     :					Tuple   	=DummyModel()
       UpperCamelCase_     :					int   	=torch.optim.Adam(params=model.parameters()      ,  lr=1E-3   )
       UpperCamelCase_	,     UpperCamelCase_     :					Optional[Any]   	=dummy_dataloaders()
       UpperCamelCase_     :					str   	=ProjectConfiguration(automatic_checkpoint_naming=_lowerCamelCase   )

       # Train baseline
       UpperCamelCase_     :					int   	=Accelerator(project_dir=_lowerCamelCase      ,  project_config=_lowerCamelCase   )
       UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_     :					List[str]   	=accelerator.prepare(
           _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       # Save initial
       accelerator.save_state()
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					Optional[int]   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Tuple   	=optimizer.state_dict()
       UpperCamelCase_     :					List[str]   	=train(3      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					Any   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Dict   	=optimizer.state_dict()

       # Train partially
       set_seed(42   )
       UpperCamelCase_     :					Any   	=DummyModel()
       UpperCamelCase_     :					str   	=torch.optim.Adam(params=model.parameters()      ,  lr=1E-3   )
       UpperCamelCase_	,     UpperCamelCase_     :					str   	=dummy_dataloaders()
       UpperCamelCase_     :					Dict   	=ProjectConfiguration(iteration=1      ,  automatic_checkpoint_naming=_lowerCamelCase   )
       UpperCamelCase_     :					int   	=Accelerator(project_dir=_lowerCamelCase      ,  project_config=_lowerCamelCase   )
       UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_     :					Any   	=accelerator.prepare(
           _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       accelerator.load_state(os.path.join(_lowerCamelCase      ,  'checkpoints'      ,  'checkpoint_0'   )   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					Tuple   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Any   	=optimizer.state_dict()
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )

       UpperCamelCase_     :					int   	=train(2      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       # Save everything
       accelerator.save_state()

       # Load everything back in and make sure all states work
       accelerator.load_state(os.path.join(_lowerCamelCase      ,  'checkpoints'      ,  'checkpoint_1'   )   )
       test_rands += train(1      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       ((UpperCamelCase_)	,     (UpperCamelCase_))     :					int   	=model.a.item(), model.b.item()
       UpperCamelCase_     :					Dict   	=optimizer.state_dict()
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )
       self.assertEqual(_lowerCamelCase      ,  _lowerCamelCase   )



     def  lowerCamelCase_						(							self :Dict   ):







      '''simple docstring'''



      UpperCamelCase_     :					Union[str, Any]   	=torch.tensor([1, 2, 3]   )
      UpperCamelCase_     :					List[str]   	=torch.tensor([2, 3, 4]   )
      UpperCamelCase_     :					Dict   	=DummyModel()
      UpperCamelCase_     :					Dict   	=torch.optim.Adam(net.parameters()   )
      UpperCamelCase_     :					Tuple   	=Accelerator()
      with self.assertRaises(_lowerCamelCase   ) as ve:
       accelerator.register_for_checkpointing(_lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
      UpperCamelCase_     :					Tuple   	=str(ve.exception   )
      self.assertTrue('Item at index 0' in message   )
      self.assertTrue('Item at index 1' in message   )
      self.assertFalse('Item at index 2' in message   )
      self.assertFalse('Item at index 3' in message   )



     def  lowerCamelCase_						(							self :Any   ):







      '''simple docstring'''



      with tempfile.TemporaryDirectory() as tmpdir:
       set_seed(42   )
       UpperCamelCase_     :					List[Any]   	=DummyModel()
       UpperCamelCase_     :					int   	=torch.optim.Adam(params=model.parameters()      ,  lr=1E-3   )
       UpperCamelCase_     :					Optional[Any]   	=torch.optim.lr_scheduler.StepLR(_lowerCamelCase      ,  step_size=1      ,  gamma=0.99   )
       UpperCamelCase_	,     UpperCamelCase_     :					Optional[int]   	=dummy_dataloaders()
       UpperCamelCase_     :					Optional[Any]   	=ProjectConfiguration(automatic_checkpoint_naming=_lowerCamelCase   )
       # Train baseline
       UpperCamelCase_     :					Tuple   	=Accelerator(project_dir=_lowerCamelCase      ,  project_config=_lowerCamelCase   )
       UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_	,     UpperCamelCase_     :					List[Any]   	=accelerator.prepare(
           _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       # Save initial
       accelerator.save_state()
       UpperCamelCase_     :					Union[str, Any]   	=scheduler.state_dict()
       train(3      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase      ,  _lowerCamelCase   )
       self.assertNotEqual(_lowerCamelCase      ,  scheduler.state_dict()   )

       # Load everything back in and make sure all states work
       accelerator.load_state(os.path.join(_lowerCamelCase      ,  'checkpoints'      ,  'checkpoint_0'   )   )
       self.assertEqual(_lowerCamelCase      ,  scheduler.state_dict()   )



     def  lowerCamelCase_						(							self :Optional[Any]   ):







      '''simple docstring'''



      with tempfile.TemporaryDirectory() as tmpdir:
       set_seed(42   )
       UpperCamelCase_     :					Union[str, Any]   	=DummyModel()
       UpperCamelCase_     :					str   	=ProjectConfiguration(automatic_checkpoint_naming=_lowerCamelCase      ,  total_limit=2   )
       # Train baseline
       UpperCamelCase_     :					Optional[Any]   	=Accelerator(project_dir=_lowerCamelCase      ,  project_config=_lowerCamelCase   )
       UpperCamelCase_     :					List[Any]   	=accelerator.prepare(_lowerCamelCase   )
       # Save 3 states:
       for _ in range(11   ):
        accelerator.save_state()
       self.assertTrue(not os.path.exists(os.path.join(_lowerCamelCase      ,  'checkpoints'      ,  'checkpoint_0'   )   )   )
       self.assertTrue(os.path.exists(os.path.join(_lowerCamelCase      ,  'checkpoints'      ,  'checkpoint_9'   )   )   )
       self.assertTrue(os.path.exists(os.path.join(_lowerCamelCase      ,  'checkpoints'      ,  'checkpoint_10'   )   )   )




     @require_cuda
     def  lowerCamelCase_						(							self :Union[str, Any]   ):







      '''simple docstring'''



      UpperCamelCase_     :					List[Any]   	=['torchrun', f'''--nproc_per_node={torch.cuda.device_count()}''', inspect.getfile(self.__class__   )]
      execute_subprocess_async(_lowerCamelCase      ,  env=os.environ.copy()   )


if __name__ == "__main__":
 __SCREAMING_SNAKE_CASE							=     '/tmp/accelerate/state_checkpointing'
 __SCREAMING_SNAKE_CASE							=     DummyModel()
 __SCREAMING_SNAKE_CASE							=     torch.optim.Adam(params=model.parameters(), lr=1e-3)
 __SCREAMING_SNAKE_CASE							=     torch.optim.lr_scheduler.StepLR(optimizer, step_size=1, gamma=0.99)
 __SCREAMING_SNAKE_CASE				, __SCREAMING_SNAKE_CASE							=     dummy_dataloaders()
 __SCREAMING_SNAKE_CASE							=     ProjectConfiguration(automatic_checkpoint_naming=True)
 # Train baseline
 __SCREAMING_SNAKE_CASE							=     Accelerator(project_dir=savedir, project_config=project_config, mixed_precision='no')
 if accelerator.process_index == 0:
  if os.path.exists(savedir):
   shutil.rmtree(savedir)
  os.makedirs(savedir)
 __SCREAMING_SNAKE_CASE				, __SCREAMING_SNAKE_CASE				, __SCREAMING_SNAKE_CASE				, __SCREAMING_SNAKE_CASE				, __SCREAMING_SNAKE_CASE							=     accelerator.prepare(
     model, optimizer, train_dataloader, valid_dataloader, scheduler
 )
 __SCREAMING_SNAKE_CASE				, __SCREAMING_SNAKE_CASE							=     accelerator.prepare(model, optimizer)
 train(3, model, train_dataloader, optimizer, accelerator, scheduler)
 # Check that the intial optimizer is loaded on the GPU
 for group in optimizer.param_groups:
  __SCREAMING_SNAKE_CASE							=     group['params'][0].device
  break
 assert param_device.type == accelerator.device.type
 __SCREAMING_SNAKE_CASE							=     model.cpu()
 accelerator.wait_for_everyone()
 accelerator.save_state()
 accelerator.wait_for_everyone()

 # Check CPU state
 accelerator.load_state(os.path.join(savedir, 'checkpoints', 'checkpoint_0'), map_location='cpu')
 for group in optimizer.param_groups:
  __SCREAMING_SNAKE_CASE							=     group['params'][0].device
  break
 assert (
     param_device.type == torch.device('cpu').type
 ), F"Loaded optimizer states did not match, expected to be loaded on the CPU but got {param_device}"

 # Check device state
 model.to(accelerator.device)
 accelerator.load_state(os.path.join(savedir, 'checkpoints', 'checkpoint_0'), map_location='on_device')
 for group in optimizer.param_groups:
  __SCREAMING_SNAKE_CASE							=     group['params'][0].device
  break
 assert (
     param_device.type == accelerator.device.type
 ), F"Loaded optimizer states did not match, expected to be loaded on {accelerator.device} but got {param_device}"

 # Check error
 with pytest.raises(TypeError, match='Unsupported optimizer map location passed'):
  accelerator.load_state(os.path.join(savedir, 'checkpoints', 'checkpoint_0'), map_location='invalid')
 accelerator.wait_for_everyone()
 if accelerator.process_index == 0:
  shutil.rmtree(savedir)
 accelerator.wait_for_everyone()


"""simple docstring"""






import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_funnel import FunnelTokenizer


__SCREAMING_SNAKE_CASE							=     logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							=     {'vocab_file': 'vocab.txt', 'tokenizer_file': 'tokenizer.json'}

__SCREAMING_SNAKE_CASE							=     [
    'small',
    'small-base',
    'medium',
    'medium-base',
    'intermediate',
    'intermediate-base',
    'large',
    'large-base',
    'xlarge',
    'xlarge-base',
]

__SCREAMING_SNAKE_CASE							=     {
    'vocab_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/vocab.txt',
        'funnel-transformer/small-base': 'https://huggingface.co/funnel-transformer/small-base/resolve/main/vocab.txt',
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/vocab.txt',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/vocab.txt'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/vocab.txt'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/vocab.txt',
        'funnel-transformer/large-base': 'https://huggingface.co/funnel-transformer/large-base/resolve/main/vocab.txt',
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/vocab.txt',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/vocab.txt'
        ),
    },
    'tokenizer_file': {
        'funnel-transformer/small': 'https://huggingface.co/funnel-transformer/small/resolve/main/tokenizer.json',
        'funnel-transformer/small-base': (
            'https://huggingface.co/funnel-transformer/small-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/medium': 'https://huggingface.co/funnel-transformer/medium/resolve/main/tokenizer.json',
        'funnel-transformer/medium-base': (
            'https://huggingface.co/funnel-transformer/medium-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate': (
            'https://huggingface.co/funnel-transformer/intermediate/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/intermediate-base': (
            'https://huggingface.co/funnel-transformer/intermediate-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/large': 'https://huggingface.co/funnel-transformer/large/resolve/main/tokenizer.json',
        'funnel-transformer/large-base': (
            'https://huggingface.co/funnel-transformer/large-base/resolve/main/tokenizer.json'
        ),
        'funnel-transformer/xlarge': 'https://huggingface.co/funnel-transformer/xlarge/resolve/main/tokenizer.json',
        'funnel-transformer/xlarge-base': (
            'https://huggingface.co/funnel-transformer/xlarge-base/resolve/main/tokenizer.json'
        ),
    },
}
__SCREAMING_SNAKE_CASE							=     {F"""funnel-transformer/{name}""": 512 for name in _model_names}
__SCREAMING_SNAKE_CASE							=     {F"""funnel-transformer/{name}""": {'do_lower_case': True} for name in _model_names}





class 				a__					(						A__       ):
     UpperCAmelCase__         =      VOCAB_FILES_NAMES
     UpperCAmelCase__         =      PRETRAINED_VOCAB_FILES_MAP
     UpperCAmelCase__         =      PRETRAINED_INIT_CONFIGURATION
     UpperCAmelCase__         =      FunnelTokenizer
     UpperCAmelCase__         =      PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     UpperCAmelCase__         =      2



     def __init__(							self :str      ,  _lowerCamelCase :int=None      ,  _lowerCamelCase :List[Any]=None      ,  _lowerCamelCase :Dict=True      ,  _lowerCamelCase :Optional[Any]="<unk>"      ,  _lowerCamelCase :Optional[Any]="<sep>"      ,  _lowerCamelCase :List[Any]="<pad>"      ,  _lowerCamelCase :List[Any]="<cls>"      ,  _lowerCamelCase :Union[str, Any]="<mask>"      ,  _lowerCamelCase :Any="<s>"      ,  _lowerCamelCase :Union[str, Any]="</s>"      ,  _lowerCamelCase :str=True      ,  _lowerCamelCase :Dict=True      ,  _lowerCamelCase :Tuple=None      ,  _lowerCamelCase :Tuple="##"      ,  **_lowerCamelCase :int      ,  ):







      '''simple docstring'''



      super().__init__(
          _lowerCamelCase      ,  tokenizer_file=_lowerCamelCase      ,  do_lower_case=_lowerCamelCase      ,  unk_token=_lowerCamelCase      ,  sep_token=_lowerCamelCase      ,  pad_token=_lowerCamelCase      ,  cls_token=_lowerCamelCase      ,  mask_token=_lowerCamelCase      ,  bos_token=_lowerCamelCase      ,  eos_token=_lowerCamelCase      ,  clean_text=_lowerCamelCase      ,  tokenize_chinese_chars=_lowerCamelCase      ,  strip_accents=_lowerCamelCase      ,  wordpieces_prefix=_lowerCamelCase      ,  **_lowerCamelCase      ,  )

      UpperCamelCase_     :					str   	=json.loads(self.backend_tokenizer.normalizer.__getstate__()   )
      if (
          normalizer_state.get('lowercase'      ,  _lowerCamelCase   ) != do_lower_case
          or normalizer_state.get('strip_accents'      ,  _lowerCamelCase   ) != strip_accents
          or normalizer_state.get('handle_chinese_chars'      ,  _lowerCamelCase   ) != tokenize_chinese_chars
      ):
       UpperCamelCase_     :					int   	=getattr(_lowerCamelCase      ,  normalizer_state.pop('type'   )   )
       UpperCamelCase_     :					Dict   	=do_lower_case
       UpperCamelCase_     :					Tuple   	=strip_accents
       UpperCamelCase_     :					int   	=tokenize_chinese_chars
       UpperCamelCase_     :					Tuple   	=normalizer_class(**_lowerCamelCase   )

      UpperCamelCase_     :					Dict   	=do_lower_case



     def  lowerCamelCase_						(							self :Optional[int]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[int]=None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[Any]   	=[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
       output += token_ids_a + [self.sep_token_id]

      return output



     def  lowerCamelCase_						(							self :List[Any]      ,  _lowerCamelCase :List[int]      ,  _lowerCamelCase :Optional[List[int]] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					Optional[int]   	=[self.sep_token_id]
      UpperCamelCase_     :					List[Any]   	=[self.cls_token_id]
      if token_ids_a is None:
       return len(cls   ) * [self.cls_token_type_id] + len(token_ids_a + sep   ) * [0]
      return len(cls   ) * [self.cls_token_type_id] + len(token_ids_a + sep   ) * [0] + len(token_ids_a + sep   ) * [1]




     def  lowerCamelCase_						(							self :Optional[Any]      ,  _lowerCamelCase :str      ,  _lowerCamelCase :Optional[str] = None   ):







      '''simple docstring'''



      UpperCamelCase_     :					int   	=self._tokenizer.model.save(_lowerCamelCase      ,  name=_lowerCamelCase   )
      return tuple(_lowerCamelCase   )
