Expand description
The test harness of ruxla.
Following PyTorch’s OpInfo, each primitive declares test samples
(OpInfo): parameters and arguments for the element types to test. A
shared harness then runs the same checks on every primitive:
check_opevaluates each sample with the interpreter and with the native backend’s operations ([ruxla_core::eval_native]), which must agree bit for bit (both useruxla-kernels);check_op_xlalowers each sample to StableHLO, runs it with XLA through a PJRT plugin, and compares it with the interpreter, for every element type the primitive accepts. XLA is the independent reference;check_op_vmapbatches each sample withvmapand compares the batched function with a loop over examples (check_vmap);random_functionmakes random well-typed programs, to compare the three on combinations of primitives.
§Examples
use ruxla_testing::{check_op, op_infos};
let add = op_infos().into_iter().find(|info| info.name() == "add").unwrap();
assert!(check_op(&add, 0).is_empty());Structs§
- AdReport
- The result of
check_op_ad. - Failure
- A failed check.
- OpInfo
- The test declaration of one primitive.
- Rng
- A deterministic random number generator (SplitMix64).
- Sample
- One test case of a primitive: parameters and arguments.
- XlaReport
- The result of
check_op_xla.
Enums§
- Domain
- The range of values to draw.
Functions§
- check_
function_ ad - Checks the derivatives of
fatargs(forward mode against finite differences, reverse mode with the inner-product test) with random tangents and cotangents fromseed. Only outputs of typef64are compared with finite differences. - check_
op - Checks every sample of
infofor its declared element types with the interpreter and the native backend, and returns the failures. - check_
op_ ad - Checks the derivatives of the
f64andc128samples ofinfo(those that the primitive accepts, exceptedge values, which include points where functions are not differentiable). - check_
op_ vmap - Checks
vmapof every sample ofinfofor its declared element types against a loop overaxis_sizeexamples, with the interpreter and the native backend, for several choices of input axes. Returns the failures. - check_
op_ vmap_ xla check_op_vmap, also running the batched functions with XLA.- check_
op_ xla - Checks the samples of
infoagainst XLA for every element type: the declared ones, and the others that the primitive accepts. - check_
vmap - Checks that
vmap(f)agrees with a loop over examples, for a functionfand the arguments of each example (all with the same types). - check_
vmap_ xla check_vmap, and also runs the batched function with XLA, which must agree with the interpreter withinxla_tolerance(ortolerancefor floats, if it is looser).- check_
vmap_ xla_ only check_vmapfor a function that only XLA runs (extern_call): the batched function and the loop both run with XLA.- compare
- Compares two host arrays within a tolerance, describing the first difference.
- edge_
values - Returns values at the edges of a type: NaN, infinities, signed zeros, and halfway cases for floats; the extremes, -1, 0, and 1 for integers.
- from_
values - Builds an array from values, converted to
dtypeasElement::from_valuedoes. - op_
infos - Returns the OpInfo declarations of every primitive.
- pjrt_
cpu_ client - Returns a client of the PJRT CPU plugin, or
Noneif the plugin is not available. - random_
function - Returns a random well-typed function of about
sizeequations withf32andi32inputs of shape[3, 4], and arguments for it. The function returns its last three values. - run_
with_ xla - Compiles a function with XLA, runs it on
args, and returns its outputs. - single_
equation - Builds a function that applies
primto arguments of the given types. - stack
- Stacks arrays of the same type and shape along a new dimension
axis. - tolerance
- Returns the tolerance
(rtol, atol)for comparing results of a type with expected values. - values_
close - Returns whether two values are equal within a tolerance. NaN equals NaN.
- xla_
tolerance - Returns the tolerance
(rtol, atol)for comparing XLA with the interpreter.
Type Aliases§
- Samples
Fn - Creates the samples of a primitive for one element type.