MCPcopy Index your code
hub / github.com/LaurentMazare/xla-rs

github.com/LaurentMazare/xla-rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
468 symbols 1,232 edges 30 files 128 documented · 27%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

xla-rs

Experimentation using the xla compiler from rust

Pre-compiled binaries for the xla library can be downloaded from the elixir-nx/xla repo. These should be extracted at the root of this repository, resulting in a xla_extension subdirectory being created, the currently supported version is 0.8.0.

For a linux platform, this can be done via:

wget https://github.com/elixir-nx/xla/releases/download/v0.8.0/xla_extension-x86_64-linux-gnu-cpu.tar.gz
tar -xzvf xla_extension-x86_64-linux-gnu-cpu.tar.gz

If the xla_extension directory is not in the main project directory, the path can be specified via the XLA_EXTENSION_DIR environment variable.

Generating some Text Samples with LLaMA

The LLaMA large language model can be used to generate text. The model weights are only available after completing this form and once downloaded can be converted to a format this crate can use. This requires a GPU with 16GB of memory or 32GB of memory when running on cpu (using the -cpu flag).

# Download the tokenizer config.
wget https://huggingface.co/hf-internal-testing/llama-tokenizer/raw/main/tokenizer.json -O llama-tokenizer.json

# Extract the pre-trained weights, this requires the transformers python library to be installed.
# This creates a npz file storing all the weights.
python examples/llama/convert_checkpoint.py ..../LLaMA/7B/consolidated.00.pth

# Run the example.
cargo run --example llama --release

Generating some Text Samples with GPT2

One of the featured examples is GPT2. In order to run it, one should first download the tokenization configuration file as well as the weights before running the example. In order to do this, run the following commands:

# Download the vocab file.
wget https://openaipublic.blob.core.windows.net/gpt-2/encodings/main/vocab.bpe

# Extract the pre-trained weights, this requires the transformers python library to be installed.
# This creates a npz file storing all the weights.
python examples/nanogpt/get_weights.py

# Run the example.
cargo run --example nanogpt --release

Extension points exported contracts — how you extend this code

FromRawBytes (Interface)
(no doc) [2 implementers]
src/npy.rs
ArrayElement (Interface)
(no doc) [2 implementers]
src/wrappers/mod.rs
NativeType (Interface)
A type implementing the `NativeType` trait can be directly converted to constant ops or literals.
src/wrappers/mod.rs

Core symbols most depended-on inside this repo

len
called by 77
examples/llama/var_store.rs
as_ptr
called by 52
src/wrappers/shape.rs
clone
called by 31
src/wrappers/xla_op.rs
reshape
called by 26
src/wrappers/xla_op.rs
handle_status
called by 24
src/wrappers/mod.rs
ptr
called by 24
src/wrappers/xla_builder.rs
build
called by 23
src/wrappers/xla_op.rs
wrap
called by 21
src/wrappers/xla_op.rs

Shape

Method 221
Function 188
Class 50
Enum 6
Interface 3

Languages

Rust63%
C++36%
Python1%

Modules by API surface

xla_rs/xla_rs.cc156 symbols
src/wrappers/xla_op.rs51 symbols
src/wrappers/xla_builder.rs33 symbols
src/wrappers/literal.rs28 symbols
src/wrappers/shape.rs24 symbols
src/wrappers/mod.rs22 symbols
examples/llama/main.rs21 symbols
examples/nanogpt/main.rs17 symbols
src/wrappers/pjrt_client.rs16 symbols
src/npy.rs13 symbols
examples/llama/var_store.rs12 symbols
xla_rs/xla_rs.h11 symbols

For agents

$ claude mcp add xla-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact