MCPcopy Create free account
hub / github.com/modelscope/modelscope / test_save_pretrained

Method test_save_pretrained

tests/models/test_base_torch.py:78–100  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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
103if __name__ == '__main__':

Callers

nothing calls this directly

Calls 5

numpify_tensor_nestedFunction · 0.90
compare_arguments_nestedFunction · 0.85
from_pretrainedMethod · 0.45
evalMethod · 0.45
save_pretrainedMethod · 0.45

Tested by

no test coverage detected