def test_record_observer(self): model = SingleLayerLinearModel() model.qconfig = default_debug_qconfig prepare(model) # run the evaluation and dump all tensors test_only_eval_fn(model, self.calib_data) test_only_eval_fn(model, self.calib_data) observer_dict = {} get_observer_dict(model, observer_dict) self.assertTrue('fc1.module.observer' in observer_dict.keys(), 'observer is not recorded in the dict') self.assertEqual(len(observer_dict['fc1.module.observer'].get_tensor_value()), 2 * len(self.calib_data)) self.assertEqual(observer_dict['fc1.module.observer'].get_tensor_value()[0], model(self.calib_data[0][0]))
def test_tensor_observer(self): model = SingleLayerLinearModel() model.qconfig = default_debug_qconfig prepare(model) # run the evaluation and dump all tensors test_only_eval_fn(model, self.calib_data) test_only_eval_fn(model, self.calib_data) tensor_dict = {} dump_tensor(model, tensor_dict) # we can torch,save() and torch_load() in bento for further analysis self.assertTrue('fc1.module.activation' in tensor_dict.keys(), 'activation is not recorded in the dict') self.assertEqual(len(tensor_dict['fc1.module.activation']), 2 * len(self.calib_data))