█

AI/TLDR

Buy me a coffee
Buy me a coffee

TrnRT

An open LLM inference engine for AWS Trainium2 that serves GLM-5.3-Flash through an OpenAI-compatible API, with decode run as NKI megakernels

Serving & DeploymentOpen source
Latest
v0.1.0
Updated
8 Nov 2026
Language
Python
License
Apache-2.0
$git clone https://github.com/RunanywhereAI/trnrt.git && cd trnrt

What's new

v0.1.08 Nov 2026

First public release: the GLM-5.3-Flash model layer and NKI kernels, the engine, OpenAI-compatible server, session-affine router and offline compile pipeline.

IN SHORT

What is TrnRT?

TrnRT is an open-source inference engine for large language models on AWS Trainium, built by RunAnywhere and released under the Apache-2.0 license. It serves an OpenAI-compatible API from a single `trn2.48xlarge` instance (16 Trainium2 chips). It sits in the Serving & Deployment category of the Models & Inference tools and is open-source, written in Python and licensed Apache-2.0.

Updated Markdown version ↗

Overview

TrnRT is an open-source inference engine for large language models on AWS Trainium, built by RunAnywhere and released under the Apache-2.0 license. It serves an OpenAI-compatible API from a single `trn2.48xlarge` instance (16 Trainium2 chips). GLM-5.3-Flash — Z.ai's 320B-parameter Mixture-of-Experts model with 18B active parameters, run in FP8 with a 1M-token context — is the first and so far only supported model; the README says the engine, router, caches and compile pipeline are built to carry more model families.

The engine's distinguishing idea is the decode megakernel. Instead of a chain of small kernels, each layer half runs as one fused kernel written in NKI, the Neuron Kernel Interface, covering the KDA attention, the fused DSA layer, mHC and the MoE feed-forward block. The project's reasoning is that decode on Trainium is dominated by small instructions, kernel boundaries and exposed collectives rather than memory bandwidth, so each kernel keeps its working set in on-chip SBUF memory, uses both physical cores symmetrically and moves the collectives inside the kernel. RunAnywhere's launch post reports that this fusion cut a batch-8 decode step from 32.2 ms to 24.2 ms.

Around the kernels sits a serving stack: two engines per box, each tensor-parallel over 32 logical NeuronCores, behind a session-affine router on port 8000; a radix-tree prefix cache over FP8 KV pages with a host-memory tier for evicted pages and state checkpoints; and an API that handles chat and completions, streaming, tool calls and reasoning output. Compilation is done offline on any x86_64 host with no NeuronCore — a five-step pipeline (shapes, decisions, capture, compile, strip) that takes hours — so the serving box loads a prebuilt cache and compiles nothing by default.

TrnRT architecture: clients call a session-affine router on port 8000 that sends each session to one of two engines, each tensor-parallel over 32 NeuronCores with a scheduler, prefix cache and NKI megakernels; below, a five-step offline compile pipeline on an x86_64 host produces the compile cache the engines load.
One trn2.48xlarge: a router in front of two engines, fed by a compile cache built offline on a CPU host.TrnRT README ↗

On SemiAnalysis's AgentX harness, which replays real coding-agent sessions, the README reports 3.57M tokens per minute (28.9 requests per minute) on one `trn2.48xlarge` at decode batch 12 with 32 concurrent agents and a 1M-token context, which it prices at $0.040 per million tokens at the spot rate and $0.167 on a capacity block. The launch post notes these runs are self-run, that about 95% of counted tokens are cached prompt input, and that there is no GPU baseline on the same traces.

What it does

  • NKI decode megakernels — one fused kernel per layer half for KDA attention, the fused DSA layer, mHC and the MoE FFN
  • 1M-token context through sparse attention (top 2,048) and linear attention with fixed-size state
  • A prefix cache built as a radix tree over FP8 KV pages, with a host-memory tier for evicted pages and state checkpoints
  • Two tensor-parallel engines per `trn2.48xlarge` behind a session-affine, prefix-aware router
  • OpenAI-compatible chat and completions with streaming, tool calls and reasoning output
  • Offline compile on any x86_64 host, so the serving instance loads a ready compile cache instead of compiling

Getting started

You need Docker, a `trn2.48xlarge` to serve on and any x86_64 host to compile on; the project's docs/AWS.md covers Trainium setup for newcomers. These steps follow the README's quickstart.

Build the image

The image bundles Neuron SDK 2.32 (neuronx-cc 2.27) and Python 3.13.

bashbash
git clone https://github.com/RunanywhereAI/trnrt.git && cd trnrt
docker build -f docker/Dockerfile \
  --build-arg TRNRT_VERSION=$(python3 -c 'import trnrt; print(trnrt.__version__)') \
  --build-arg TRNRT_REVISION=$(git rev-parse HEAD) -t trnrt .

Build the compile cache on a CPU host

Five offline steps capture and compile every graph for the pinned GLM-5.3-Flash revision. No NeuronCore is needed, but the run takes hours.

bashbash
OUT=/data/trnrt REV=eb9eb208eb0d988989d07a6a12d0fdeb5f52574a
mkdir -p $OUT/nki $OUT/work
trnrt() { docker run --rm -e HF_TOKEN -v $OUT:$OUT \
  -v $OUT/nki:/var/tmp/nki-intermediate-cache trnrt "$@"; }
trnrt compile shapes zai-org/GLM-5.3-Flash --revision $REV --out $OUT
trnrt compile decisions --model zai-org/GLM-5.3-Flash --revision $REV --out $OUT
trnrt compile capture --out $OUT -- --model $OUT/shapes
trnrt compile compile --out $OUT --work-root $OUT/work
trnrt compile strip --out $OUT

Serve on the trn2.48xlarge

Copy `$OUT/cache` and `$OUT/nki` to the Trainium instance, download the same model revision and start the server.

bashbash
hf download zai-org/GLM-5.3-Flash --revision eb9eb208eb0d988989d07a6a12d0fdeb5f52574a \
  --local-dir /models/GLM-5.3-Flash
docker run --rm --privileged --network host --ipc=host \
  -v /data/trnrt/cache:/cache \
  -v /data/trnrt/nki:/var/tmp/nki-intermediate-cache \
  -v /models/GLM-5.3-Flash:/model \
  -e NEURON_LIBTORCH_CACHE_ROOT=/cache \
  trnrt serve --model /model --port 8000

Call it with any OpenAI client

Passing a `session_id` keeps a conversation on one engine's prefix cache.

pythonpython
from openai import OpenAI

client = OpenAI(base_url="http://localhost:8000/v1", api_key="unused")
reply = client.chat.completions.create(
    model="glm",
    messages=[{"role": "user", "content": "Write a haiku about Trainium."}],
    extra_body={"session_id": "my-session"},
)
print(reply.choices[0].message.content)

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Reach for it when you want to serve GLM-5.3-Flash on AWS Trainium2 capacity instead of GPUs
  • Reach for it for long-running coding-agent workloads with long, heavily reused prompts, where the session-affine router and prefix cache pay off
  • Reach for it as a worked reference for writing fused NKI megakernels on Trainium — docs/MEGAKERNELS.md walks through every kernel

How TrnRT compares

TrnRT alongside other open-source serving & deployment tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
Transformers★ 169kHugging Face Transformers is a Python framework that defines and runs state-of-the-art pretrained models for text, vision, audio, and multimodal tasks, for both inference and training.
vLLM★ 96.8kA high-throughput LLM serving engine that uses PagedAttention and continuous batching to serve many requests at once.
SGLang★ 38.8kA serving framework for LLMs and multimodal models that boosts throughput by reusing shared prompt prefixes across requests.
Modular Platform★ 30.1kModular's AI platform: the MAX inference framework with an OpenAI-compatible serving endpoint and GPU kernel library, plus the Mojo language and compiler.
DeepInfer★ 25.9kDeepSeek's own large-scale inference framework for its models, with expert parallelism, confidence-scheduled speculative decoding and NVIDIA plus Ascend support.
TensorRT-LLM★ 15.1kNVIDIA's library that compiles LLMs into optimized engines for the fastest inference on its data-center GPUs.
OpenLLM★ 12.6kA tool to run any open-source LLM as an OpenAI-compatible API endpoint locally or in the cloud.
TrnRT★ 1.3kAn open LLM inference engine for AWS Trainium2 that serves GLM-5.3-Flash through an OpenAI-compatible API, with decode run as NKI megakernels