Skip to main content

Crate ruxla_testing

Crate ruxla_testing 

Source
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_op evaluates each sample with the interpreter and with the native backend’s operations ([ruxla_core::eval_native]), which must agree bit for bit (both use ruxla-kernels);
  • check_op_xla lowers 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_vmap batches each sample with vmap and compares the batched function with a loop over examples (check_vmap);
  • random_function makes 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 f at args (forward mode against finite differences, reverse mode with the inner-product test) with random tangents and cotangents from seed. Only outputs of type f64 are compared with finite differences.
check_op
Checks every sample of info for its declared element types with the interpreter and the native backend, and returns the failures.
check_op_ad
Checks the derivatives of the f64 and c128 samples of info (those that the primitive accepts, except edge values, which include points where functions are not differentiable).
check_op_vmap
Checks vmap of every sample of info for its declared element types against a loop over axis_size examples, 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 info against 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 function f and 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 within xla_tolerance (or tolerance for floats, if it is looser).
check_vmap_xla_only
check_vmap for 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 dtype as Element::from_value does.
op_infos
Returns the OpInfo declarations of every primitive.
pjrt_cpu_client
Returns a client of the PJRT CPU plugin, or None if the plugin is not available.
random_function
Returns a random well-typed function of about size equations with f32 and i32 inputs 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 prim to 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§

SamplesFn
Creates the samples of a primitive for one element type.