Skip to main content

Crate ruxla_import

Crate ruxla_import 

Source
Expand description

Importing functions written in JAX into ruxla’s IR.

The Python function ruxla.export_jaxpr(fn, *args) traces a JAX function, rewrites its jaxpr into the primitives that ruxla’s IR has (inlining calls, expanding the PRNG on raw u32 key data, and so on), and writes it as a JSON document. from_json reads the document into a Function, which ruxla runs like a function traced from Rust: with the interpreter, compiled ahead of time to Rust (ruxla-codegen), or lowered to XLA.

The document’s format is described in python/ruxla/_jaxpr.py: a function of variables (ids, element types, and shapes), constants and literals (base64 of their little-endian bytes), and equations (the primitive’s name, the inputs, the outputs, and the parameters as JSON values). The primitives and most parameters have JAX’s names, which are also ruxla’s.

§Examples

use ruxla_ir::HostArray;

// `jnp.sin(x)` for `x: f32[2]`, as `ruxla.export_jaxpr` writes it.
let doc = r#"{"format_version": 1, "function": {
    "invars": [{"id": 0, "dtype": "f32", "shape": [2]}], "constvars": [],
    "eqns": [{"prim": "sin", "inputs": [{"var": 0}],
              "outputs": [{"id": 1, "dtype": "f32", "shape": [2]}],
              "params": {"accuracy": null}}],
    "outvars": [{"var": 1}]}}"#;
let f = ruxla_import::from_json(doc).unwrap();
assert_eq!(f.to_string(), "{ lambda ; a:f32[2]. let\n    b:f32[2] = sin a\n  in (b,) }");

Enums§

Error
Errors while importing a document.

Constants§

FORMAT_VERSION
The version of the JSON document that this crate reads.

Functions§

base64
Decodes standard base64 (with padding), the encoding of the data of constants and literals in the documents.
from_json
Reads the JSON document written by ruxla.export_jaxpr into a function, and checks that its types agree with ruxla’s shape inference.
from_value
from_json from a parsed document.
primitive
The primitive named name, if ruxla has it.

Type Aliases§

Result
A specialized result type.