def convert_orig_tf1_checkpoint_to_pytorch(tf_checkpoint_path,
                                           convbert_config_file,
                                           pytorch_dump_path):
    conf = ConvBertConfig.from_json_file(convbert_config_file)
    model = ConvBertModel(conf)

    model = load_tf_weights_in_convbert(model, conf, tf_checkpoint_path)
    model.save_pretrained(pytorch_dump_path)
    def test_inference_no_head(self):
        model = ConvBertModel.from_pretrained("YituTech/conv-bert-base")
        input_ids = torch.tensor([[1, 2, 3, 4, 5, 6]])
        output = model(input_ids)[0]

        expected_shape = torch.Size((1, 6, 768))
        self.assertEqual(output.shape, expected_shape)

        expected_slice = torch.tensor([[[-0.0864, -0.4898, -0.3677],
                                        [0.1434, -0.2952, -0.7640],
                                        [-0.0112, -0.4432, -0.5432]]])

        self.assertTrue(
            torch.allclose(output[:, :3, :3], expected_slice, atol=1e-4))
    def test_inference_masked_lm(self):
        model = ConvBertModel.from_pretrained("YituTech/conv-bert-base")
        input_ids = torch.tensor([[0, 1, 2, 3, 4, 5]])
        output = model(input_ids)[0]
        print(output[:, :3, :3])

        expected_shape = torch.Size((1, 6, 768))
        self.assertEqual(output.shape, expected_shape)

        # TODO Replace values below with what was printed above.
        expected_slice = torch.tensor(
            [[[-0.0348, -0.4686, -0.3064], [0.2264, -0.2699, -0.7423], [0.1032, -0.4501, -0.5828]]]
        )

        self.assertTrue(torch.allclose(output[:, :3, :3], expected_slice, atol=1e-4))
 def create_and_check_model(
     self, config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
 ):
     model = ConvBertModel(config=config)
     model.to(torch_device)
     model.eval()
     result = model(input_ids, attention_mask=input_mask, token_type_ids=token_type_ids)
     result = model(input_ids, token_type_ids=token_type_ids)
     result = model(input_ids)
     self.parent.assertEqual(result.last_hidden_state.shape, (self.batch_size, self.seq_length, self.hidden_size))
 def test_model_from_pretrained(self):
     for model_name in CONVBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         model = ConvBertModel.from_pretrained(model_name)
         self.assertIsNotNone(model)