Skip to main content

JAX/Equinox implementation of Megalodon for efficient long-context training and inference

Project description

megalodon-jax

A JAX/Equinox implementation of Megalodon: Efficient LLM Pretraining and Inference with Unlimited Context Length, aligned with the original released PyTorch/CUDA implementation.

Highlights

  • Long-context language modeling with chunked attention and ComplexEMA
  • JIT-compatible streaming inference with fixed-capacity caches
  • Packed-sequence training with document-isolated attention, recurrent state, normalization, and loss
  • SafeTensors checkpoints and original-upstream PyTorch checkpoint conversion
  • Source-level parity checks and the official released tokenizer bundle

Installation

For CPU:

pip install megalodon-jax

For NVIDIA GPUs using the pip-managed CUDA 13 runtime:

pip install "megalodon-jax[cuda13]"

Python 3.11 or newer is required. See Installation and setup for CUDA requirements, optional features, unreleased main installs, development setup, and troubleshooting.

Quick start

import jax
from megalodon_jax import MegalodonConfig, MegalodonForCausalLM

model_key, input_key = jax.random.split(jax.random.PRNGKey(0))
config = MegalodonConfig(
    vocab_size=32_000,
    model_dim=512,
    num_layers=8,
    num_heads=1,
    chunk_size=256,
    cema_ndim=16,
)
model = MegalodonForCausalLM(config, key=model_key)

input_ids = jax.random.randint(input_key, (1, 128), 0, config.vocab_size)
logits, _ = model(input_ids)
print(logits.shape)  # (1, 128, 32000)

Where to go next

The documentation index covers the remaining implementation and compatibility references.

Related

Citation

@misc{ma2024megalodon,
      title={Megalodon: Efficient LLM Pretraining and Inference with Unlimited Context Length},
      author={Xuezhe Ma and Xiaomeng Yang and Wenhan Xiong and Beidi Chen and Lili Yu and Hao Zhang and Jonathan May and Luke Zettlemoyer and Omer Levy and Chunting Zhou},
      year={2024},
      eprint={2404.08801},
      archivePrefix={arXiv},
      primaryClass={cs.LG}
}

Project details


Download files

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

Source Distribution

megalodon_jax-0.2.1.tar.gz (754.3 kB view details)

Uploaded Source

Built Distribution

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

megalodon_jax-0.2.1-py3-none-any.whl (93.7 kB view details)

Uploaded Python 3

File details

Details for the file megalodon_jax-0.2.1.tar.gz.

File metadata

  • Download URL: megalodon_jax-0.2.1.tar.gz
  • Upload date:
  • Size: 754.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for megalodon_jax-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0be4b9706b8e272671d888be3e6d56a9c6235339413465663fc62925f762dc0c
MD5 2c38149347ccb27dda8384d3dec7f284
BLAKE2b-256 2905cb55d237373bfc8b6a6a90e1dc11a0840dab50f0c225d6893e2035318512

See more details on using hashes here.

Provenance

The following attestation bundles were made for megalodon_jax-0.2.1.tar.gz:

Publisher: publish.yml on pszemraj/megalodon-jax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file megalodon_jax-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: megalodon_jax-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 93.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for megalodon_jax-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 acebaed160d7069c209b3807854979f882e8edd8072ffa949995f81bc1b6a319
MD5 c56d71b2efd21db46b747dabffaf29b1
BLAKE2b-256 c4941076c52894ce3c0785c483929727ea8390c1b6ed66398764ec495ea1e8b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for megalodon_jax-0.2.1-py3-none-any.whl:

Publisher: publish.yml on pszemraj/megalodon-jax

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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