(self)
| 76 | exists('transformers<5.0'), |
| 77 | 'Skip because transformers version is too high.') |
| 78 | def test_save_pretrained(self): |
| 79 | preprocessor = Preprocessor.from_pretrained( |
| 80 | 'damo/nlp_structbert_sentence-similarity_chinese-tiny') |
| 81 | model = TorchModel.from_pretrained( |
| 82 | 'damo/nlp_structbert_sentence-similarity_chinese-tiny') |
| 83 | model.eval() |
| 84 | with torch.no_grad(): |
| 85 | res1 = numpify_tensor_nested( |
| 86 | model(**preprocessor(('test1', 'test2')))) |
| 87 | save_path = os.path.join(self.tmp_dir, 'test_save_pretrained') |
| 88 | model.save_pretrained( |
| 89 | save_path, save_checkpoint_names='pytorch_model.bin') |
| 90 | self.assertTrue( |
| 91 | os.path.isfile(os.path.join(save_path, 'pytorch_model.bin'))) |
| 92 | self.assertTrue( |
| 93 | os.path.isfile(os.path.join(save_path, 'configuration.json'))) |
| 94 | self.assertTrue(os.path.isfile(os.path.join(save_path, 'vocab.txt'))) |
| 95 | model = TorchModel.from_pretrained(save_path) |
| 96 | model.eval() |
| 97 | with torch.no_grad(): |
| 98 | res2 = numpify_tensor_nested( |
| 99 | model(**preprocessor(('test1', 'test2')))) |
| 100 | self.assertTrue(compare_arguments_nested('', res1, res2)) |
| 101 | |
| 102 | |
| 103 | if __name__ == '__main__': |
nothing calls this directly
no test coverage detected