Code Monkey home page Code Monkey logo

ocaml-xla's Introduction

ocaml-xla

XLA (Accelerated Linear Algebra) bindings for OCaml. This is based on the xla-rs Rust bindings, the semantics for the various operands are documented on the xla website.

Main workflow

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.4.4.

For a linux platform, this can be done via:

wget https://github.com/elixir-nx/xla/releases/download/v0.4.4/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 package can use. This requires a GPU with 16GB of memory or 32GB of memory when running on CPU (tweak the use_gpu variable in the example code to choose between CPU and GPU).

# 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 and
# safetensors python libraries to be installed.
python examples/convert_llama_checkpoint.py ..../LLaMA/7B/consolidated.00.pth

# Run the example.
dune exec examples/llama.exe

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 tokenizer files.
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/get_gpt2_weights.py

# Run the example.
dune exec examples/nanogpt.exe

ocaml-xla's People

Contributors

laurentmazare avatar tachukao avatar

Stargazers

Niranjan Anandkumar avatar mt_curat avatar Mike DuPont avatar  avatar shubham avatar Raph avatar Guilherme avatar mt_caret avatar Brandon84 avatar Gist avatar Kevin avatar  avatar  avatar Daniel Quernheim avatar Guillaume Hennequin avatar Tienson Qin avatar Sangwoo Joh avatar Lukasz Stafiniak avatar Seb Mondet avatar Jeremy Yallop avatar Dimitris Mostrous avatar Thomas Gazagnaire avatar Jeffrey Fetzer avatar Zaki Mughal [sivoais] avatar  avatar Sora Morimoto avatar ElBe2049 avatar Arulselvan Madhavan avatar

Watchers

James Cloos avatar  avatar Jeremy Yallop avatar Guillaume Hennequin avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.