


'''simple docstring'''






import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_torch


if is_torch_available():
 import torch

 from transformers.generation import DisjunctiveConstraint




@require_torch
class  a     (     unittest.TestCase       ):
 def 							__UpperCAmelCase		( self						)					->							Dict:
      # For consistency across different places the DisjunctiveConstraint is called,
      # dc.token_ids is a list of integers. It is also initialized only by integers.

      _a			      =							[[1, 2, 4], [1, 2, 3, 4]]
      _a			      =							DisjunctiveConstraint(__magic_name__						)
      self.assertTrue(isinstance(dc.token_ids      ,				__magic_name__						)						)

      with self.assertRaises(__magic_name__						):
           DisjunctiveConstraint(torch.LongTensor([[1, 2, 4], [1, 2, 3]]						)						)

      with self.assertRaises(__magic_name__						):
           DisjunctiveConstraint([torch.LongTensor([1, 2, 4]						), torch.LongTensor([1, 2, 3, 4, 5]						)]						)
 def 							__UpperCAmelCase		( self						)					->							Optional[Any]:
      # We can't have constraints that are complete subsets of another. This leads to a preverse
      # interpretation of "constraint fulfillment": does generating [1,2,3] fulfill the constraint?
      # It would mean that it generated [1,2] which fulfills it, but it's in the middle of potentially
      # fulfilling [1,2,3,4]. If we believe that [1,2,3] does fulfill the constraint, then the algorithm
      # will necessarily never reach [1,2,3,4], giving users a false sense of control (better to just not allow it).
      _a			      =							[[1, 2], [1, 2, 3, 4]]

      with self.assertRaises(__magic_name__						):
           DisjunctiveConstraint(__magic_name__						)  # fails here
 def 							__UpperCAmelCase		( self						)					->							List[Any]:
      _a			      =							[[1, 2, 3], [1, 2, 4]]

      _a			      =							DisjunctiveConstraint(__magic_name__						)

      _a      ,   _a      ,   _a			      =							dc.update(1						)
      _a			      =							stepped is True and completed is False and reset is False
      self.assertTrue(__magic_name__						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.current_seq == [1]						)

      _a      ,   _a      ,   _a			      =							dc.update(2						)
      _a			      =							stepped is True and completed is False and reset is False
      self.assertTrue(__magic_name__						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.current_seq == [1, 2]						)

      _a      ,   _a      ,   _a			      =							dc.update(3						)
      _a			      =							stepped is True and completed is True and reset is False
      self.assertTrue(__magic_name__						)
      self.assertTrue(dc.completed						)  # Completed!
      self.assertTrue(dc.current_seq == [1, 2, 3]						)




 def 							__UpperCAmelCase		( self						)					->							Union[str, Any]:
      _a			      =							[[1, 2, 3], [1, 2, 4, 5], [1, 2, 5]]

      _a			      =							DisjunctiveConstraint(__magic_name__						)

      _a      ,   _a      ,   _a			      =							dc.update(1						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.current_seq == [1]						)

      _a      ,   _a      ,   _a			      =							dc.update(2						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.current_seq == [1, 2]						)

      _a      ,   _a      ,   _a			      =							dc.update(4						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.current_seq == [1, 2, 4]						)

      _a      ,   _a      ,   _a			      =							dc.update(5						)
      self.assertTrue(dc.completed						)  # Completed!
      self.assertTrue(dc.current_seq == [1, 2, 4, 5]						)

      dc.reset()

      _a      ,   _a      ,   _a			      =							dc.update(1						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.remaining() == 3						)
      self.assertTrue(dc.current_seq == [1]						)

      _a      ,   _a      ,   _a			      =							dc.update(2						)
      self.assertTrue(not dc.completed						)
      self.assertTrue(dc.remaining() == 2						)
      self.assertTrue(dc.current_seq == [1, 2]						)

      _a      ,   _a      ,   _a			      =							dc.update(5						)
      self.assertTrue(dc.completed						)  # Completed!
      self.assertTrue(dc.remaining() == 0						)
      self.assertTrue(dc.current_seq == [1, 2, 5]						)





'''simple docstring'''






import argparse

import torch

from transformers import BertConfig, BertForPreTraining, load_tf_weights_in_bert
from transformers.utils import logging


logging.set_verbosity_info()






def 	_A				(lowerCAmelCase__  :str				,						lowerCAmelCase__  :int				,						lowerCAmelCase__  :Any		)   ->  str:




     '''simple docstring'''



     _a			      =							BertConfig.from_json_file(lowerCAmelCase__		)
     print(f'Building PyTorch model from configuration: {config}'		)
     _a			      =							BertForPreTraining(lowerCAmelCase__		)

     # Load weights from tf checkpoint
     load_tf_weights_in_bert(lowerCAmelCase__				,						lowerCAmelCase__				,						lowerCAmelCase__		)

     # Save pytorch-model
     print(f'Save PyTorch model to {pytorch_dump_path}'		)
     torch.save(model.state_dict()				,						lowerCAmelCase__		)


if __name__ == "__main__":
 a_					:    Optional[int]          =    argparse.ArgumentParser()
 # Required parameters
 parser.add_argument(
     "--tf_checkpoint_path", default=None, type=str, required=True, help="Path to the TensorFlow checkpoint path."
 )
 parser.add_argument(
     "--bert_config_file",
     default=None,
     type=str,
     required=True,
     help=(
         "The config json file corresponding to the pre-trained BERT model. \n"
         "This specifies the model architecture."
     ),
 )
 parser.add_argument(
     "--pytorch_dump_path", default=None, type=str, required=True, help="Path to the output PyTorch model."
 )
 a_					:    Optional[int]          =    parser.parse_args()
 convert_tf_checkpoint_to_pytorch(args.tf_checkpoint_path, args.bert_config_file, args.pytorch_dump_path)

