THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||
---|---|---|
| ||
class MXNetOperatorBenchmarkBase(ABC): """Abstract Base class for all MXNet operator benchmarks. """ def __init__(self, ctx=mx.cpu(), warmup=10, runs=10, default_parameters={}, custom_parameters=None): self.ctx = ctx self.runs = runs self.warmup = warmup self.results = {} self.inputs = prepare_input_parameters(caller=self.__class__.__name__, default_parameters=default_parameters, custom_parameters=custom_parameters) @abstractmethod def run_benchmark(self): pass def print_benchmark_results(self): if not len(self.results): print("No benchmark results found. Run the benchmark before printing results!") return for key, val in self.results.items(): print("{} - {:.6f} seconds".format(key, val)) def get_benchmark_results(self): return self.results class Add(MXNetOperatorBenchmarkBase): """Helps to Benchmark Tensor Add operation. By default benchmark both forward and backward element_wise tensor addition of 1024*1024 tensor of precision - 'float32'. """ def __init__(self, ctx=mx.cpu(), warmup=10, runs=50, inputs=None): # Set the default Inputs default_parameters = {"lhs": (1024, 1024), "rhs": (1024, 1024), "initializer": nd.normal, "run_backward": True, "dtype": "float32"} super().__init__(ctx=ctx, warmup=warmup, runs=runs, default_parameters=default_parameters, custom_parameters=inputs) self.lhs = get_mx_ndarray(ctx=self.ctx, in_tensor=self.inputs["lhs"], dtype=self.inputs["dtype"], initializer=self.inputs["initializer"], attach_grad=self.inputs["run_backward"]) self.rhs = get_mx_ndarray(ctx=self.ctx, in_tensor=self.inputs["rhs"], dtype=self.inputs["dtype"], initializer=self.inputs["initializer"], attach_grad=self.inputs["run_backward"]) def run_benchmark(self): # Warm up, ignore execution time value _, _ = nd_forward_backward_and_time(F=nd.add, runs=self.warmup, lhs=self.lhs, rhs=self.rhs) # Run Benchmarks exe_time, _ = nd_forward_backward_and_time(F=nd.add, runs=self.runs, lhs=self.lhs, rhs=self.rhs) self.results["MX_Add_Forward_Backward_Time"] = exe_time / self.runs |
Addition of new
...
Module
We propose to add this library as a new module (opperf) under incubator-mxnet/benchmark as "incubator-mxnet/benchmark/opperf". Note that, this does not generate any user facing APIs, this is a library under incubator-mxnet/benchmark folder for general use by community.
API / User Experience
We can define 2 types of users of the library and describe API interface for each of these users.
...