def run_backward(self, num_runs): """ Run the backward path of an operator in a loop """ with core.DeviceScope(self.op_bench.dev): op = self.op_bench.backward() if not workspace.RunOperatorMultiple(op, num_runs): raise ValueError("Unable to run operator gradient test case: {}".format(self.test_name))
def run_forward(self, num_runs, print_per_iter=False): """ Run the forward path of an operator in a loop """ with core.DeviceScope(self.op_bench.dev): op = self.op_bench.forward() if not workspace.RunOperatorMultiple(op, num_runs): raise ValueError("Unable to run operator test case: {}".format(self.test_name))
def test_sparse_to_dense_mask_invalid_inputs(self): op = core.CreateOperator( 'SparseToDenseMask', ['indices', 'values', 'default', 'lengths'], ['output'], mask=[999999999, 2], max_skipped_indices=3) workspace.FeedBlob( 'indices', np.array([2000000000000, 999999999, 2, 3, 4, 5], dtype=np.int32)) workspace.FeedBlob( 'values', np.array([1, 2, 3, 4, 5, 6], dtype=np.float)) workspace.FeedBlob('default', np.array(-1, dtype=np.float)) workspace.FeedBlob('lengths', np.array([6], dtype=np.int32)) try: workspace.RunOperatorOnce(op) except RuntimeError: self.fail("Exception raised with only one negative index") # 3 invalid inputs should throw. workspace.FeedBlob( 'indices', np.array([-1, 1, 2, 3, 4, 5], dtype=np.int32)) with self.assertRaises(RuntimeError): workspace.RunOperatorMultiple(op, 3)
def run_forward(self, num_runs): """ Run the forward path of an operator in a loop """ if not workspace.RunOperatorMultiple(self.op_bench.forward(), num_runs): raise ValueError("Unable to run operator test case: {}".format( self.test_name))
def benchmark_func(num_runs): if not workspace.RunOperatorMultiple(op, num_runs): raise RuntimeError('Unable to run operator test case ' % test_name)