Skip to main content

jax-triton

PyPI version

The jax-triton repository contains integrations between JAX and Triton, including support for Gluon dialect.

Documentation can be found here.

This is not an officially supported Google product.

Quickstart

The main function of interest is jax_triton.triton_call for applying Triton functions to JAX arrays, including inside jax.jit-compiled functions. For example, we can define a kernel from the Triton tutorial:

import triton
import triton.language as tl


@triton.jit
def add_kernel(
    x_ptr,
    y_ptr,
    length,
    out_ptr,                   # out_type pointers follow the inputs.
    block_size: tl.constexpr,  # constexpr params can go anywhere.
):
  """Adds two vectors output = x + y."""
  pid = tl.program_id(axis=0)
  block_start = pid * block_size
  offsets = block_start + tl.arange(0, block_size)
  mask = offsets < length
  x = tl.load(x_ptr + offsets, mask=mask)
  y = tl.load(y_ptr + offsets, mask=mask)
  output = x + y
  tl.store(out_ptr + offsets, output, mask=mask)

Then we can apply it to JAX arrays using jax_triton.triton_call:

import jax
import jax.numpy as jnp
import jax_triton as jt

def add(x: jax.Array, y: jax.Array) -> jax.Array:
  block_size = 8
  return jt.triton_call(
      x,
      y,
      x.size,
      kernel=add_kernel,
      out_type=jax.typeof(x),
      grid=(x.size // block_size,),
      block_size=block_size)

x_val = jnp.arange(8)
y_val = jnp.arange(8, 16)
print(add(x_val, y_val))
print(jax.jit(add)(x_val, y_val))

One could also use in-out parameters for kernels by passing a read-write Ref (created via jax.new_ref). The kernel mutates the Ref in place, so it is not listed in out_type:

@triton.jit
def add_inplace_y_kernel(
    x_ptr,          # input vector
    y_inout_ptr,    # explicit in-out vector (could be anywhere)
    length,
    block_size: tl.constexpr,
):
  """Adds two vectors in place: y = x + y."""
  pid = tl.program_id(axis=0)
  block_start = pid * block_size
  offsets = block_start + tl.arange(0, block_size)
  mask = offsets < length
  x = tl.load(x_ptr + offsets, mask=mask)
  y = tl.load(y_inout_ptr + offsets, mask=mask)
  output = x + y
  tl.store(y_inout_ptr + offsets, output, mask=mask)


# jitting isn't mandatory, but makes invocation more efficient.
@jax.jit
def add_inplace_y(x: jax.Array, y_ref) -> None:
  block_size = 8
  jt.triton_call(
      x,
      y_ref,         # read-write Ref argument, mutated in place
      x.size,
      kernel=add_inplace_y_kernel,
      out_type=(),  # no allocated outputs; the Ref is mutated in place
      grid=(x.size // block_size,),
      block_size=block_size)

x_val = jnp.arange(8)
y_ref = jax.new_ref(jnp.arange(8, 16))
add_inplace_y(x_val, y_ref)
print(y_ref[...])

See the examples directory, especially fused_attention.py and the fused attention ipynb.

Some other use-cases are also covered in tests.

Installation

$ pip install jax-triton

Make sure you have a CUDA- or ROCm- compatible jax installed. For example you could run:

$ pip install "jax[cuda13]"

Development

To develop jax-triton, you can clone the repo with:

$ git clone https://github.com/jax-ml/jax-triton.git

and do an editable install with:

$ cd jax-triton
$ pip install -e .

To run the jax-triton tests, you'll need pytest:

$ pip install pytest
$ pytest tests/

Metadata

Release files for jax-triton 0.5.0

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

Source distribution (sdist)

Source distribution for jax-triton 0.5.0
File Size Uploaded Provenance Actions
jax_triton-0.5.0.tar.gz 23.3 kB With provenance Details for jax_triton-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jax-triton 0.5.0
File Interpreter ABI Platform Actions
jax_triton-0.5.0-py3-none-any.whl Python 3 none any Details for jax_triton-0.5.0-py3-none-any.whl

Total release size: 46.1 kB

Release files / jax_triton-0.5.0.tar.gz

Download URL jax_triton-0.5.0.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
85b8d7b169bd5b794e15abb60f7bf4764ca28a9ed0cf00de717fd9a60fa4f3f9
BLAKE2b-256 checksum
How to use checksums
86a80af2821522ab46ff71c03167a8a5e0577686319b0460dae35596a9d5b0ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Nov 5, 2026.

Transparency log

Release files / jax_triton-0.5.0-py3-none-any.whl

Download URL jax_triton-0.5.0-py3-none-any.whl
Size 22.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84c03c1d832ba13b0d4da06b81b1f2880054e7351b07518d874b5de9d1dd249d
BLAKE2b-256 checksum
How to use checksums
d38b7781009c33398298b1caf102c24cf2d9a46a323efd9c18ec5471650a0756
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Nov 5, 2026.

Transparency log

Security for jax-triton 0.5.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jax_triton-0.5.0.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 Nov 5, 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.

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