


from typing import TYPE_CHECKING

from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available


__UpperCamelCase					:	Optional[int]          =				{
    'configuration_utils': ['GenerationConfig'],
    'streamers': ['TextIteratorStreamer', 'TextStreamer'],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase					:	Dict          =				[
           'Constraint',
           'ConstraintListState',
           'DisjunctiveConstraint',
           'PhrasalConstraint',
       ]
       __UpperCamelCase					:	Union[str, Any]          =				[
           'BeamHypotheses',
           'BeamScorer',
           'BeamSearchScorer',
           'ConstrainedBeamSearchScorer',
       ]
       __UpperCamelCase					:	Tuple          =				[
           'EpsilonLogitsWarper',
           'EtaLogitsWarper',
           'ForcedBOSTokenLogitsProcessor',
           'ForcedEOSTokenLogitsProcessor',
           'HammingDiversityLogitsProcessor',
           'InfNanRemoveLogitsProcessor',
           'LogitsProcessor',
           'LogitsProcessorList',
           'LogitsWarper',
           'MinLengthLogitsProcessor',
           'MinNewTokensLengthLogitsProcessor',
           'NoBadWordsLogitsProcessor',
           'NoRepeatNGramLogitsProcessor',
           'PrefixConstrainedLogitsProcessor',
           'RepetitionPenaltyLogitsProcessor',
           'SequenceBiasLogitsProcessor',
           'EncoderRepetitionPenaltyLogitsProcessor',
           'TemperatureLogitsWarper',
           'TopKLogitsWarper',
           'TopPLogitsWarper',
           'TypicalLogitsWarper',
           'EncoderNoRepeatNGramLogitsProcessor',
           'ExponentialDecayLengthPenalty',
           'LogitNormalization',
       ]
       __UpperCamelCase					:	Union[str, Any]          =				[
           'MaxNewTokensCriteria',
           'MaxLengthCriteria',
           'MaxTimeCriteria',
           'StoppingCriteria',
           'StoppingCriteriaList',
           'validate_stopping_criteria',
       ]
       __UpperCamelCase					:	int          =				[
           'GenerationMixin',
           'top_k_top_p_filtering',
           'GreedySearchEncoderDecoderOutput',
           'GreedySearchDecoderOnlyOutput',
           'SampleEncoderDecoderOutput',
           'SampleDecoderOnlyOutput',
           'BeamSearchEncoderDecoderOutput',
           'BeamSearchDecoderOnlyOutput',
           'BeamSampleEncoderDecoderOutput',
           'BeamSampleDecoderOnlyOutput',
           'ContrastiveSearchEncoderDecoderOutput',
           'ContrastiveSearchDecoderOnlyOutput',
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase					:	Tuple          =				[
           'TFForcedBOSTokenLogitsProcessor',
           'TFForcedEOSTokenLogitsProcessor',
           'TFLogitsProcessor',
           'TFLogitsProcessorList',
           'TFLogitsWarper',
           'TFMinLengthLogitsProcessor',
           'TFNoBadWordsLogitsProcessor',
           'TFNoRepeatNGramLogitsProcessor',
           'TFRepetitionPenaltyLogitsProcessor',
           'TFTemperatureLogitsWarper',
           'TFTopKLogitsWarper',
           'TFTopPLogitsWarper',
           'TFForceTokensLogitsProcessor',
           'TFSuppressTokensAtBeginLogitsProcessor',
           'TFSuppressTokensLogitsProcessor',
       ]
       __UpperCamelCase					:	Tuple          =				[
           'TFGenerationMixin',
           'tf_top_k_top_p_filtering',
           'TFGreedySearchDecoderOnlyOutput',
           'TFGreedySearchEncoderDecoderOutput',
           'TFSampleEncoderDecoderOutput',
           'TFSampleDecoderOnlyOutput',
           'TFBeamSearchEncoderDecoderOutput',
           'TFBeamSearchDecoderOnlyOutput',
           'TFBeamSampleEncoderDecoderOutput',
           'TFBeamSampleDecoderOnlyOutput',
           'TFContrastiveSearchEncoderDecoderOutput',
           'TFContrastiveSearchDecoderOnlyOutput',
       ]

try:
       if not is_flax_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __UpperCamelCase					:	Any          =				[
           'FlaxForcedBOSTokenLogitsProcessor',
           'FlaxForcedEOSTokenLogitsProcessor',
           'FlaxLogitsProcessor',
           'FlaxLogitsProcessorList',
           'FlaxLogitsWarper',
           'FlaxMinLengthLogitsProcessor',
           'FlaxTemperatureLogitsWarper',
           'FlaxTopKLogitsWarper',
           'FlaxTopPLogitsWarper',
       ]
       __UpperCamelCase					:	Tuple          =				[
           'FlaxGenerationMixin',
           'FlaxGreedySearchOutput',
           'FlaxSampleOutput',
           'FlaxBeamSearchOutput',
       ]

if TYPE_CHECKING:
       from .configuration_utils import GenerationConfig
       from .streamers import TextIteratorStreamer, TextStreamer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
              from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
              from .logits_process import (
                  EncoderNoRepeatNGramLogitsProcessor,
                  EncoderRepetitionPenaltyLogitsProcessor,
                  EpsilonLogitsWarper,
                  EtaLogitsWarper,
                  ExponentialDecayLengthPenalty,
                  ForcedBOSTokenLogitsProcessor,
                  ForcedEOSTokenLogitsProcessor,
                  HammingDiversityLogitsProcessor,
                  InfNanRemoveLogitsProcessor,
                  LogitNormalization,
                  LogitsProcessor,
                  LogitsProcessorList,
                  LogitsWarper,
                  MinLengthLogitsProcessor,
                  MinNewTokensLengthLogitsProcessor,
                  NoBadWordsLogitsProcessor,
                  NoRepeatNGramLogitsProcessor,
                  PrefixConstrainedLogitsProcessor,
                  RepetitionPenaltyLogitsProcessor,
                  SequenceBiasLogitsProcessor,
                  TemperatureLogitsWarper,
                  TopKLogitsWarper,
                  TopPLogitsWarper,
                  TypicalLogitsWarper,
              )
              from .stopping_criteria import (
                  MaxLengthCriteria,
                  MaxNewTokensCriteria,
                  MaxTimeCriteria,
                  StoppingCriteria,
                  StoppingCriteriaList,
                  validate_stopping_criteria,
              )
              from .utils import (
                  BeamSampleDecoderOnlyOutput,
                  BeamSampleEncoderDecoderOutput,
                  BeamSearchDecoderOnlyOutput,
                  BeamSearchEncoderDecoderOutput,
                  ContrastiveSearchDecoderOnlyOutput,
                  ContrastiveSearchEncoderDecoderOutput,
                  GenerationMixin,
                  GreedySearchDecoderOnlyOutput,
                  GreedySearchEncoderDecoderOutput,
                  SampleDecoderOnlyOutput,
                  SampleEncoderDecoderOutput,
                  top_k_top_p_filtering,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .tf_logits_process import (
                  TFForcedBOSTokenLogitsProcessor,
                  TFForcedEOSTokenLogitsProcessor,
                  TFForceTokensLogitsProcessor,
                  TFLogitsProcessor,
                  TFLogitsProcessorList,
                  TFLogitsWarper,
                  TFMinLengthLogitsProcessor,
                  TFNoBadWordsLogitsProcessor,
                  TFNoRepeatNGramLogitsProcessor,
                  TFRepetitionPenaltyLogitsProcessor,
                  TFSuppressTokensAtBeginLogitsProcessor,
                  TFSuppressTokensLogitsProcessor,
                  TFTemperatureLogitsWarper,
                  TFTopKLogitsWarper,
                  TFTopPLogitsWarper,
              )
              from .tf_utils import (
                  TFBeamSampleDecoderOnlyOutput,
                  TFBeamSampleEncoderDecoderOutput,
                  TFBeamSearchDecoderOnlyOutput,
                  TFBeamSearchEncoderDecoderOutput,
                  TFContrastiveSearchDecoderOnlyOutput,
                  TFContrastiveSearchEncoderDecoderOutput,
                  TFGenerationMixin,
                  TFGreedySearchDecoderOnlyOutput,
                  TFGreedySearchEncoderDecoderOutput,
                  TFSampleDecoderOnlyOutput,
                  TFSampleEncoderDecoderOutput,
                  tf_top_k_top_p_filtering,
              )

       try:
              if not is_flax_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .flax_logits_process import (
                  FlaxForcedBOSTokenLogitsProcessor,
                  FlaxForcedEOSTokenLogitsProcessor,
                  FlaxLogitsProcessor,
                  FlaxLogitsProcessorList,
                  FlaxLogitsWarper,
                  FlaxMinLengthLogitsProcessor,
                  FlaxTemperatureLogitsWarper,
                  FlaxTopKLogitsWarper,
                  FlaxTopPLogitsWarper,
              )
              from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
       import sys

       __UpperCamelCase					:	List[str]          =				_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)



import argparse

from transformers import CanineConfig, CanineModel, CanineTokenizer, load_tf_weights_in_canine
from transformers.utils import logging


logging.set_verbosity_info()
def   snake_case_    (			__lowercase      ,							__lowercase							):
   # Initialize PyTorch model
   UpperCAmelCase_				:   Optional[Any]							= CanineConfig()
   UpperCAmelCase_				:   Any							= CanineModel(__lowercase							)
   model.eval()

   print(F'''Building PyTorch model from configuration: {config}'''							)

   # Load weights from tf checkpoint
   load_tf_weights_in_canine(__lowercase      ,							__lowercase      ,							__lowercase							)

   # Save pytorch-model (weights and configuration)
   print(F'''Save PyTorch model to {pytorch_dump_path}'''							)
   model.save_pretrained(__lowercase							)

   # Save tokenizer files
   UpperCAmelCase_				:   List[Any]							= CanineTokenizer()
   print(F'''Save tokenizer files to {pytorch_dump_path}'''							)
   tokenizer.save_pretrained(__lowercase							)


if __name__ == "__main__":
       __UpperCamelCase					:	int          =				argparse.ArgumentParser()
       # Required parameters
       parser.add_argument(
           '--tf_checkpoint_path',
           default=None,
           type=str,
           required=True,
           help='Path to the TensorFlow checkpoint. Should end with model.ckpt',
       )
       parser.add_argument(
           '--pytorch_dump_path',
           default=None,
           type=str,
           required=True,
           help='Path to a folder where the PyTorch model will be placed.',
       )
       __UpperCamelCase					:	str          =				parser.parse_args()
       convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.pytorch_dump_path)