





'''simple docstring'''

import gc
import unittest

from transformers import MODEL_FOR_MASKED_LM_MAPPING, TF_MODEL_FOR_MASKED_LM_MAPPING, FillMaskPipeline, pipeline
from transformers.pipelines import PipelineException
from transformers.testing_utils import (
    is_pipeline_test,
    is_torch_available,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_gpu,
    slow,
)

from .test_pipelines_common import ANY






@is_pipeline_test
class        UpperCAmelCase     (	unittest.TestCase    ):
 __lowercase       		=    MODEL_FOR_MASKED_LM_MAPPING
 __lowercase       		=    TF_MODEL_FOR_MASKED_LM_MAPPING
 def 					UpperCAmelCase_							(    self				:List[str]							)->							str:
     super().tearDown()
     # clean-up as much as possible GPU memory occupied by PyTorch
     gc.collect()
     if is_torch_available():
         import torch

         torch.cuda.empty_cache()
 @require_tf
 def 					UpperCAmelCase_							(    self				:Any							)->							Dict:
     A__    =      pipeline(task="fill-mask"						,	model="sshleifer/tiny-distilroberta-base"						,	top_k=2						,	framework="tf"							)
     A__    =      unmasker("My name is <mask>"							)
     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             {"sequence": "My name is grouped", "score": 2.1E-05, "token": 3_80_15, "token_str": " grouped"},
             {"sequence": "My name is accuser", "score": 2.1E-05, "token": 2_55_06, "token_str": " accuser"},
         ]						,	)

     A__    =      unmasker("The largest city in France is <mask>"							)
     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             {
                 "sequence": "The largest city in France is grouped",
                 "score": 2.1E-05,
                 "token": 3_80_15,
                 "token_str": " grouped",
             },
             {
                 "sequence": "The largest city in France is accuser",
                 "score": 2.1E-05,
                 "token": 2_55_06,
                 "token_str": " accuser",
             },
         ]						,	)

     A__    =      unmasker("My name is <mask>"						,	targets=[" Patrick", " Clara", " Teven"]						,	top_k=3							)
     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             {"sequence": "My name is Clara", "score": 2E-05, "token": 1_36_06, "token_str": " Clara"},
             {"sequence": "My name is Patrick", "score": 2E-05, "token": 34_99, "token_str": " Patrick"},
             {"sequence": "My name is Te", "score": 1.9E-05, "token": 29_41, "token_str": " Te"},
         ]						,	)
 @require_torch
 def 					UpperCAmelCase_							(    self				:Optional[Any]							)->							List[Any]:
     A__    =      pipeline(task="fill-mask"						,	model="sshleifer/tiny-distilroberta-base"						,	top_k=2						,	framework="pt"							)

     A__    =      unmasker("My name is <mask>"							)
     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             {"sequence": "My name is Maul", "score": 2.2E-05, "token": 3_56_76, "token_str": " Maul"},
             {"sequence": "My name isELS", "score": 2.2E-05, "token": 1_64_16, "token_str": "ELS"},
         ]						,	)

     A__    =      unmasker("The largest city in France is <mask>"							)
     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             {
                 "sequence": "The largest city in France is Maul",
                 "score": 2.2E-05,
                 "token": 3_56_76,
                 "token_str": " Maul",
             },
             {"sequence": "The largest city in France isELS", "score": 2.2E-05, "token": 1_64_16, "token_str": "ELS"},
         ]						,	)

     A__    =      unmasker("My name is <mask>"						,	targets=[" Patrick", " Clara", " Teven"]						,	top_k=3							)
     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             {"sequence": "My name is Patrick", "score": 2.1E-05, "token": 34_99, "token_str": " Patrick"},
             {"sequence": "My name is Te", "score": 2E-05, "token": 29_41, "token_str": " Te"},
             {"sequence": "My name is Clara", "score": 2E-05, "token": 1_36_06, "token_str": " Clara"},
         ]						,	)

     A__    =      unmasker("My name is <mask> <mask>"						,	top_k=2							)

     self.assertEqual(
         nested_simplify(lowercase_						,	decimals=6							)						,	[
             [
                 {
                     "score": 2.2E-05,
                     "token": 3_56_76,
                     "token_str": " Maul",
                     "sequence": "<s>My name is Maul<mask></s>",
                 },
                 {"score": 2.2E-05, "token": 1_64_16, "token_str": "ELS", "sequence": "<s>My name isELS<mask></s>"},
             ],
             [
                 {
                     "score": 2.2E-05,
                     "token": 3_56_76,
                     "token_str": " Maul",
                     "sequence": "<s>My name is<mask> Maul</s>",
                 },
                 {"score": 2.2E-05, "token": 1_64_16, "token_str": "ELS", "sequence": "<s>My name is<mask>ELS</s>"},
             ],
         ]						,	)
 @require_torch_gpu
 def 					UpperCAmelCase_							(    self				:Dict							)->							Tuple:
     A__    =      pipeline("fill-mask"						,	model="hf-internal-testing/tiny-random-distilbert"						,	device=0						,	framework="pt"							)

     # convert model to fp16
     pipe.model.half()

     A__    =      pipe("Paris is the [MASK] of France."							)
     # We actually don't care about the result, we just want to make sure
     # it works, meaning the float16 tensor got casted back to float32
     # for postprocessing.
     self.assertIsInstance(lowercase_						,	lowercase_							)
 @slow
 @require_torch
 def 					UpperCAmelCase_							(    self				:Dict							)->							Optional[Any]:
     A__    =      pipeline(task="fill-mask"						,	model="distilroberta-base"						,	top_k=2						,	framework="pt"							)
     self.run_large_test(lowercase_							)
 @slow
 @require_tf
 def 					UpperCAmelCase_							(    self				:Any							)->							Tuple:
     A__    =      pipeline(task="fill-mask"						,	model="distilroberta-base"						,	top_k=2						,	framework="tf"							)
     self.run_large_test(lowercase_							)
 def 					UpperCAmelCase_							(    self				:List[str]						,	lowercase_				:Any							)->							List[str]:
     A__    =      unmasker("My name is <mask>"							)
     self.assertEqual(
         nested_simplify(lowercase_							)						,	[
             {"sequence": "My name is John", "score": 0.0_0_8, "token": 6_10, "token_str": " John"},
             {"sequence": "My name is Chris", "score": 0.0_0_7, "token": 15_73, "token_str": " Chris"},
         ]						,	)
     A__    =      unmasker("The largest city in France is <mask>"							)
     self.assertEqual(
         nested_simplify(lowercase_							)						,	[
             {
                 "sequence": "The largest city in France is Paris",
                 "score": 0.2_5_1,
                 "token": 22_01,
                 "token_str": " Paris",
             },
             {
                 "sequence": "The largest city in France is Lyon",
                 "score": 0.2_1_4,
                 "token": 1_27_90,
                 "token_str": " Lyon",
             },
         ]						,	)

     A__    =      unmasker("My name is <mask>"						,	targets=[" Patrick", " Clara", " Teven"]						,	top_k=3							)
     self.assertEqual(
         nested_simplify(lowercase_							)						,	[
             {"sequence": "My name is Patrick", "score": 0.0_0_5, "token": 34_99, "token_str": " Patrick"},
             {"sequence": "My name is Clara", "score": 0.0_0_0, "token": 1_36_06, "token_str": " Clara"},
             {"sequence": "My name is Te", "score": 0.0_0_0, "token": 29_41, "token_str": " Te"},
         ]						,	)
 @require_torch
 def 					UpperCAmelCase_							(    self				:List[str]							)->							str:
     A__    =      pipeline(task="fill-mask"						,	model="sshleifer/tiny-distilroberta-base"						,	framework="pt"							)
     A__    =      None
     A__    =      None
     self.run_pipeline_test(lowercase_						,	[]							)
 @require_tf
 def 					UpperCAmelCase_							(    self				:Any							)->							Optional[int]:
     A__    =      pipeline(task="fill-mask"						,	model="sshleifer/tiny-distilroberta-base"						,	framework="tf"							)
     A__    =      None
     A__    =      None
     self.run_pipeline_test(lowercase_						,	[]							)
 def 					UpperCAmelCase_							(    self				:List[str]						,	lowercase_				:Dict						,	lowercase_				:Optional[Any]						,	lowercase_				:Tuple							)->							Union[str, Any]:
     if tokenizer is None or tokenizer.mask_token_id is None:
         self.skipTest("The provided tokenizer has no mask token, (probably reformer or wav2vec2)"							)

     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_							)
     A__    =      [
         F"This is another {tokenizer.mask_token} test",
     ]
     return fill_masker, examples
 def 					UpperCAmelCase_							(    self				:List[Any]						,	lowercase_				:str						,	lowercase_				:int							)->							Union[str, Any]:
     A__    =      fill_masker.tokenizer
     A__    =      fill_masker.model

     A__    =      fill_masker(
         F"This is a {tokenizer.mask_token}"						,	)
     self.assertEqual(
         lowercase_						,	[
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
         ]						,	)

     A__    =      fill_masker([F"This is a {tokenizer.mask_token}"]							)
     self.assertEqual(
         lowercase_						,	[
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
         ]						,	)

     A__    =      fill_masker([F"This is a {tokenizer.mask_token}", F"Another {tokenizer.mask_token} great test."]							)
     self.assertEqual(
         lowercase_						,	[
             [
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             ],
             [
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             ],
         ]						,	)

     with self.assertRaises(lowercase_							):
         fill_masker([None]							)
     # No mask_token is not supported
     with self.assertRaises(lowercase_							):
         fill_masker("This is"							)

     self.run_test_top_k(lowercase_						,	lowercase_							)
     self.run_test_targets(lowercase_						,	lowercase_							)
     self.run_test_top_k_targets(lowercase_						,	lowercase_							)
     self.fill_mask_with_duplicate_targets_and_top_k(lowercase_						,	lowercase_							)
     self.fill_mask_with_multiple_masks(lowercase_						,	lowercase_							)
 def 					UpperCAmelCase_							(    self				:Dict						,	lowercase_				:str						,	lowercase_				:Optional[int]							)->							List[Any]:
     A__    =      tokenizer.get_vocab()
     A__    =      sorted(vocab.keys()							)[:2]
     # Pipeline argument
     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_						,	targets=lowercase_							)
     A__    =      fill_masker(F"This is a {tokenizer.mask_token}"							)
     self.assertEqual(
         lowercase_						,	[
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
         ]						,	)
     A__    =      {vocab[el] for el in targets}
     self.assertEqual({el["token"] for el in outputs}						,	lowercase_							)
     A__    =      [tokenizer.decode([x]							) for x in target_ids]
     self.assertEqual({el["token_str"] for el in outputs}						,	set(lowercase_							)							)

     # Call argument
     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_							)
     A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	targets=lowercase_							)
     self.assertEqual(
         lowercase_						,	[
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
         ]						,	)
     A__    =      {vocab[el] for el in targets}
     self.assertEqual({el["token"] for el in outputs}						,	lowercase_							)
     A__    =      [tokenizer.decode([x]							) for x in target_ids]
     self.assertEqual({el["token_str"] for el in outputs}						,	set(lowercase_							)							)

     # Score equivalence
     A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	targets=lowercase_							)
     A__    =      [top_mask["token_str"] for top_mask in outputs]
     A__    =      [top_mask["score"] for top_mask in outputs]

     # For some BPE tokenizers, `</w>` is removed during decoding, so `token_str` won't be the same as in `targets`.
     if set(lowercase_							) == set(lowercase_							):
         A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	targets=lowercase_							)
         A__    =      [top_mask["score"] for top_mask in unmasked_targets]
         self.assertEqual(nested_simplify(lowercase_							)						,	nested_simplify(lowercase_							)							)

     # Raises with invalid
     with self.assertRaises(lowercase_							):
         A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	targets=[]							)
     # For some tokenizers, `""` is actually in the vocabulary and the expected error won't raised
     if "" not in tokenizer.get_vocab():
         with self.assertRaises(lowercase_							):
             A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	targets=[""]							)
         with self.assertRaises(lowercase_							):
             A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	targets=""							)
 def 					UpperCAmelCase_							(    self				:Union[str, Any]						,	lowercase_				:Optional[Any]						,	lowercase_				:Dict							)->							List[str]:
     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_						,	top_k=2							)
     A__    =      fill_masker(F"This is a {tokenizer.mask_token}"							)
     self.assertEqual(
         lowercase_						,	[
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
         ]						,	)

     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_							)
     A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	top_k=2							)
     self.assertEqual(
         lowercase_						,	[
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
         ]						,	)
     self.assertEqual(nested_simplify(lowercase_							)						,	nested_simplify(lowercase_							)							)
 def 					UpperCAmelCase_							(    self				:Optional[Any]						,	lowercase_				:List[Any]						,	lowercase_				:List[Any]							)->							str:
     A__    =      tokenizer.get_vocab()
     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_							)

     # top_k=2, ntargets=3
     A__    =      sorted(vocab.keys()							)[:3]
     A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	top_k=2						,	targets=lowercase_							)

     # If we use the most probably targets, and filter differently, we should still
     # have the same results
     A__    =      [el["token_str"] for el in sorted(lowercase_						,	key=lambda lowercase_							: x["score"]						,	reverse=lowercase_							)]
     # For some BPE tokenizers, `</w>` is removed during decoding, so `token_str` won't be the same as in `targets`.
     if set(lowercase_							).issubset(lowercase_							):
         A__    =      fill_masker(F"This is a {tokenizer.mask_token}"						,	top_k=3						,	targets=lowercase_							)
         # They should yield exactly the same result
         self.assertEqual(nested_simplify(lowercase_							)						,	nested_simplify(lowercase_							)							)
 def 					UpperCAmelCase_							(    self				:Any						,	lowercase_				:Union[str, Any]						,	lowercase_				:Optional[int]							)->							Optional[Any]:
     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_							)
     A__    =      tokenizer.get_vocab()
     # String duplicates + id duplicates
     A__    =      sorted(vocab.keys()							)[:3]
     A__    =      [targets[0], targets[1], targets[0], targets[2], targets[1]]
     A__    =      fill_masker(F"My name is {tokenizer.mask_token}"						,	targets=lowercase_						,	top_k=10							)

     # The target list contains duplicates, so we can't output more
     # than them
     self.assertEqual(len(lowercase_							)						,	3							)



 def 					UpperCAmelCase_							(    self				:Tuple						,	lowercase_				:Tuple						,	lowercase_				:Optional[int]							)->							Union[str, Any]:
     A__    =      FillMaskPipeline(model=lowercase_						,	tokenizer=lowercase_							)

     A__    =      fill_masker(
         F"This is a {tokenizer.mask_token} {tokenizer.mask_token} {tokenizer.mask_token}"						,	top_k=2							)
     self.assertEqual(
         lowercase_						,	[
             [
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             ],
             [
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             ],
             [
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
                 {"sequence": ANY(lowercase_							), "score": ANY(lowercase_							), "token": ANY(lowercase_							), "token_str": ANY(lowercase_							)},
             ],
         ]						,	)










'''simple docstring'''

import argparse
import os
import re

import packaging.version


__lowerCAmelCase							:     List[Any]		     ="examples/"
__lowerCAmelCase							:     Dict		     ={
    "examples": (re.compile(R"^check_min_version\(\"[^\"]+\"\)\s*$", re.MULTILINE), "check_min_version(\"VERSION\")\n"),
    "init": (re.compile(R"^__version__\s+=\s+\"([^\"]+)\"\s*$", re.MULTILINE), "__version__ = \"VERSION\"\n"),
    "setup": (re.compile(R"^(\s*)version\s*=\s*\"[^\"]+\",", re.MULTILINE), R"\1version=\"VERSION\","),
    "doc": (re.compile(R"^(\s*)release\s*=\s*\"[^\"]+\"$", re.MULTILINE), "release = \"VERSION\"\n"),
}
__lowerCAmelCase							:     List[str]		     ={
    "init": "src/transformers/__init__.py",
    "setup": "setup.py",
}
__lowerCAmelCase							:     str		     ="README.md"





def 						UpperCamelCase    (							_lowerCamelCase : Optional[Any]						,	_lowerCamelCase : Union[str, Any]						,	_lowerCamelCase : Optional[Any]	):
    with open(_lowerCamelCase						,	"r"						,	encoding="utf-8"						,	newline="\n"	) as f:
        A__    =      f.read()
    A__,     A__    =      REPLACE_PATTERNS[pattern]
    A__    =      replace.replace("VERSION"						,	_lowerCamelCase	)
    A__    =      re_pattern.sub(_lowerCamelCase						,	_lowerCamelCase	)
    with open(_lowerCamelCase						,	"w"						,	encoding="utf-8"						,	newline="\n"	) as f:
        f.write(_lowerCamelCase	)





def 						UpperCamelCase    (							_lowerCamelCase : int	):
    for folder, directories, fnames in os.walk(_lowerCamelCase	):
        # Removing some of the folders with non-actively maintained examples from the walk
        if "research_projects" in directories:
            directories.remove("research_projects"	)
        if "legacy" in directories:
            directories.remove("legacy"	)
        for fname in fnames:
            if fname.endswith(".py"	):
                update_version_in_file(os.path.join(_lowerCamelCase						,	_lowerCamelCase	)						,	_lowerCamelCase						,	pattern="examples"	)





def 						UpperCamelCase    (							_lowerCamelCase : int						,	_lowerCamelCase : Union[str, Any]=False	):
    for pattern, fname in REPLACE_FILES.items():
        update_version_in_file(_lowerCamelCase						,	_lowerCamelCase						,	_lowerCamelCase	)
    if not patch:
        update_version_in_examples(_lowerCamelCase	)





def 						UpperCamelCase    (							):
    A__    =      "🤗 Transformers currently provides the following architectures"
    A__    =      "1. Want to contribute a new model?"
    with open(_lowerCamelCase						,	"r"						,	encoding="utf-8"						,	newline="\n"	) as f:
        A__    =      f.readlines()

    # Find the start of the list.
    A__    =      0
    while not lines[start_index].startswith(_start_prompt	):
        start_index += 1
    start_index += 1

    A__    =      start_index
    # Update the lines in the model list.
    while not lines[index].startswith(_end_prompt	):
        if lines[index].startswith("1."	):
            A__    =      lines[index].replace(
                "https://huggingface.co/docs/transformers/main/model_doc"						,	"https://huggingface.co/docs/transformers/model_doc"						,	)
        index += 1

    with open(_lowerCamelCase						,	"w"						,	encoding="utf-8"						,	newline="\n"	) as f:
        f.writelines(_lowerCamelCase	)





def 						UpperCamelCase    (							):
    with open(REPLACE_FILES["init"]						,	"r"	) as f:
        A__    =      f.read()
    A__    =      REPLACE_PATTERNS["init"][0].search(_lowerCamelCase	).groups()[0]
    return packaging.version.parse(_lowerCamelCase	)





def 						UpperCamelCase    (							_lowerCamelCase : Dict=False	):
    A__    =      get_version()
    if patch and default_version.is_devrelease:
        raise ValueError("Can't create a patch version from the dev branch, checkout a released version!"	)
    if default_version.is_devrelease:
        A__    =      default_version.base_version
    elif patch:
        A__    =      F"{default_version.major}.{default_version.minor}.{default_version.micro + 1}"
    else:
        A__    =      F"{default_version.major}.{default_version.minor + 1}.0"

    # Now let's ask nicely if that's the right one.
    A__    =      input(F"Which version are you releasing? [{default_version}]"	)
    if len(_lowerCamelCase	) == 0:
        A__    =      default_version

    print(F"Updating version to {version}."	)
    global_version_update(_lowerCamelCase						,	patch=_lowerCamelCase	)
    if not patch:
        print("Cleaning main README, don't forget to run `make fix-copies`."	)
        clean_main_ref_in_model_list()





def 						UpperCamelCase    (							):
    A__    =      get_version()
    A__    =      F"{current_version.major}.{current_version.minor + 1}.0.dev0"
    A__    =      current_version.base_version

    # Check with the user we got that right.
    A__    =      input(F"Which version are we developing now? [{dev_version}]"	)
    if len(_lowerCamelCase	) == 0:
        A__    =      dev_version

    print(F"Updating version to {version}."	)
    global_version_update(_lowerCamelCase	)
    print("Cleaning main README, don't forget to run `make fix-copies`."	)
    clean_main_ref_in_model_list()


if __name__ == "__main__":
  __lowerCAmelCase							:     Union[str, Any]		     =argparse.ArgumentParser()
  parser.add_argument("--post_release", action="store_true", help="Whether this is pre or post release.")
  parser.add_argument("--patch", action="store_true", help="Whether or not this is a patch release.")
  __lowerCAmelCase							:     int		     =parser.parse_args()
  if not args.post_release:
    pre_release_work(patch=args.patch)
  elif args.patch:
    print("Nothing to do after a patch :-)")
  else:
    post_release_work()



