Skip to main content

Research-friendly implementation of LLMs in JAX

Project description

fabrique

Fabrique is a collection of popular LLMs in JAX. It provides clean and research-friendly code as well as easy-to-use wrappers for end users.

Fabrique uses model snapshots from Huggingface Hub and provides familiar high-level API.

Installation

You can install the latest released version of fabrique from PYPI:

pip install fabrique

Alternatively, you can mount the development version of fabrique directly to your project and use existing code as reference for your own models:

cd /path/to/your/project

# clone the repository
git clone https://github.com/dfdx/fabrique

# or even add it as a submodule
# git submodule add git@github.com:dfdx/fabrique.git

# set up PYTHONPATH to include fabrique as a package
export PYTHONPATH=.:fabrique

Usage

High-level API

from fabrique.models.llm import LLM


model_id = "microsoft/phi-4"

# note: use keyword arguments that fit your hardware
llm = LLM.from_pretrained(model_id, max_batch_size=1, max_seq_len=512)

out = llm.generate("""<|user|>\nHow to print a value in Python?<|end|>\n<|assistant|>""")
print(out)

Working with models directly

Fabrique is built using Flax NNX. Citing NNX's home page:

NNX is a Neural Network library for JAX that focuses on providing the best development experience, so building and experimenting with neural networks is easy and intuitive. It achieves this by embracing Python’s object-oriented model and making it compatible with JAX transforms, resulting in code that is easy to inspect, debug, and analyze.

All Fabrique models can be found in fabrique/models/<model-name>/modeling.py files. Feel free to copy and modify them. If something in the code is unclear, consider it a bug.

The very first model was inspired by the Meta's Llama 3 repo.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fabrique-0.1.2-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file fabrique-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fabrique-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.4

File hashes

Hashes for fabrique-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6d6865753a706f589bc5957989ab05c09b1d89058a2faf4803c8ea10108bce77
MD5 2467e6536cb370c6b7eb411d900fafa5
BLAKE2b-256 423ff26accafde6ea80a7ee8af2629690c8efa8678355fbeab3232b5d3be472d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page