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

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

Metadata

Release files for megalodon-jax 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for megalodon-jax 0.2.2
File Size Uploaded Provenance Actions
megalodon_jax-0.2.2.tar.gz 756.0 kB With provenance Details for megalodon_jax-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for megalodon-jax 0.2.2
File Interpreter ABI Platform Actions
megalodon_jax-0.2.2-py3-none-any.whl Python 3 none any Details for megalodon_jax-0.2.2-py3-none-any.whl

Total release size: 848.9 kB

Release files / megalodon_jax-0.2.2.tar.gz

Download URL megalodon_jax-0.2.2.tar.gz
Size 756.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9b272b0349ca819050a453bfe0654dd7cd1444db132e7d9f75a9607816a68436
BLAKE2b-256 checksum
How to use checksums
441571bf1b648dc20986b372e98f2960308ac28e8b79dd4835360343c9e739bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

Release files / megalodon_jax-0.2.2-py3-none-any.whl

Download URL megalodon_jax-0.2.2-py3-none-any.whl
Size 92.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
014ca8ea66f2f4f99ff6173835a472ddb026950a4c88abcfea5556b365895a8f
BLAKE2b-256 checksum
How to use checksums
4aca2a3fbbef0791d850422ada9f5608c804c8712db3a94ca68729d96b6462ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

Security for megalodon-jax 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for megalodon_jax-0.2.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files Full provenance

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