xlnstorch.benchmark.UnaryBench#
- class xlnstorch.benchmark.UnaryBench(func, shape, lns=True, f=None, b=None, backward=False, device='cpu', kwargs=None)#
A benchmark for unary operations in xlnstorch or torch. Inputs are generated from the standard normal distribution.
- Parameters:
func (Callable) – The unary function to benchmark, e.g., torch.sign or torch.relu.
shape (Tuple) – The shape of the input tensor.
lns (bool, optional) – If True, uses xlnstorch.randn for generating inputs, otherwise uses torch.randn.
f (int, optional) – The precision parameter for the input LNSTensor.
b (float, optional) – The base parameter for the input LNSTensor.
backward (bool, optional) – If True, the input tensor will require gradients for backward pass.
device (torch.device or str, optional) – The device on which to create the input tensor (default is “cpu”).
kwargs (Dict, optional) – Additional keyword arguments to pass to the function being benchmarked.
- __init__(func, shape, lns=True, f=None, b=None, backward=False, device='cpu', kwargs=None)#
Methods
__init__(func, shape[, lns, f, b, backward, ...])after_epoch(idx)Symmetric counterpart of
before_epoch().before_epoch(idx)Called before the idx-th epoch.
forward(x)The workload under test (e.g.
model(*args, **kwargs)).make_inputs()Produce input tensors for one iteration of the benchmark.
post_forward(output)Optional light-weight processing of the forward result.
Attributes
device