Skip to main content

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

This project is released as a Python package on PyPi:

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. Or ask the DeepWiki:

Ask DeepWiki

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}
}

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.2.tar.gz (756.0 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.2-py3-none-any.whl (92.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: megalodon_jax-0.2.2.tar.gz
  • Upload date:
  • Size: 756.0 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.2.tar.gz
Algorithm Hash digest
SHA256 9b272b0349ca819050a453bfe0654dd7cd1444db132e7d9f75a9607816a68436
MD5 c581fae32b9f64d443f8ad5ddd578b71
BLAKE2b-256 441571bf1b648dc20986b372e98f2960308ac28e8b79dd4835360343c9e739bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for megalodon_jax-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: megalodon_jax-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 92.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 014ca8ea66f2f4f99ff6173835a472ddb026950a4c88abcfea5556b365895a8f
MD5 065531294973f7317c7fbdc532a7643e
BLAKE2b-256 4aca2a3fbbef0791d850422ada9f5608c804c8712db3a94ca68729d96b6462ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for megalodon_jax-0.2.2-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.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 files

0.2.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page