Quickstart · Benchmarks · Docs · Kernels · Blog post · runanywhere.ai
TrnRT is an open inference engine for large language models on AWS Trainium. It serves an OpenAI-compatible API from
one trn2.48xlarge, runs decode as NKI megakernels (about one kernel per layer half), and keeps a prefix cache across
device and host memory. GLM-5.3-Flash is the first supported model. Qwen3.8-27B is in preview, served on Trainium2;
GLM-5.3 and DeepSeek-V4.1-Flash are experimental: GLM-5.3 runs on Trainium2 at a 4,096-token context, and
DeepSeek-V4.1-Flash's first 4 layers have run there.
The cards below are GLM-5.3-Flash's. How we built it, with the AgentX results: Serving GLM-5.3-Flash on one Trainium2 box with NKI layer megakernels.
On InferenceX AgentX, which replays real coding-agent sessions, one
TrnRT engine (8 Trainium2 chips, half a trn2.48xlarge) delivers more tokens per dollar than one 8-GPU H200 node at 1,
4, 8 and 16 concurrent users, and 3.9-5.2× an H100 node's at 16, 24 and 32 users. At 1, 4 and 8 users it runs the
latency-golden build: MTP speculation at InferenceX's golden acceptance length (2.519), the benchmark mode, whose
output text is not the model's. Both columns of those rows, tokens per dollar and tok/s per user, are at that synthetic
acceptance (as H200's are at theirs), so they compare speed, never output quality. All three run GLM-5.3-Flash's FP8
weights and are priced at AWS's Capacity Block list prices. This comparison is GLM-5.3-Flash's; Qwen3.8-27B's own AgentX
run, not compared with a GPU, is under Benchmarks.
| Users | trn2 build | Tokens per $: trn2 ÷ H200 | Tokens per $: trn2 ÷ H100 | P90 interactivity, tok/s per user: trn2 / H200 |
|---|---|---|---|---|
| 1 | latency-golden |
1.73× | 1.60× | 66.3 / 272 |
| 4 | latency-golden |
1.89× | 1.88× | 51.3 / 235 |
| 8 | latency-golden |
1.63× | 2.02× | 27.6 / 168 |
| 16 | balanced |
1.09× | 3.89× | 14.2 / 87.8 |
| 24 | throughput |
0.87× | 5.17× | 11.5 / 78.7 |
| 32 | throughput |
0.81× | 4.95× | 10.7 / 50.1 |
Where we're behind. Each trn2 user is slower: P90 interactivity (1 / the P90 inter-token latency, as InferenceX plots it; the wait for the first token is not in it) is 10.7-66.3 tok/s per user against H200's 50.1-272 (at 1-8 users both at synthetic golden acceptance). At 24 and 32 users H200 delivers more tokens per dollar (0.81-0.87×), and on the 8K/1K fixed-length recipe, whose prompts share no prefix (its client's warmup sends the first timed prompt, so one timed request per run can find it cached), trn2 delivers 0.89-1.00× H200's at 1-8 users and 0.52-0.82× at 16-64. Where a decode step's time goes is in docs/RESULTS.md.
InferenceX AgentX harness 1.0.12, canonical workload, one hour per point; ratios compare the same concurrency. The
1-8 user points use MTP at InferenceX's golden acceptance length (2.519; trn2's measured acceptance is 2.20): the
latency-golden build, whose output text is not the model's. Prices, AWS Capacity Blocks list, read 24 Nov 2026:
trn2.48xlarge $2.235 per Trainium2 chip-hour ($35.76 per instance-hour), p5.48xlarge $5.970 per H100-hour, p5e.48xlarge
$6.866 per H200-hour. Every trn2 point is a run of 0.2.0's code with the serve fixes, on 25 Nov 2026 (the 2.20
acceptance dates from 0.2.0), with
benchmarks/ (the image from docker/Dockerfile, Neuron SDK 2.32, and a compile cache built from
source). GSM8K is 97.4-97.6% on the builds served with real acceptance (strict exact match, 5-shot, all 1,319 problems),
and each passed a needle test (on its answers; a host-tier restore is not observable on this server). GPU numbers are
InferenceX's public runs; we report no accuracy score for them and did not check them. Every table, source run and the method:
docs/RESULTS.md.
| Feature | What it does |
|---|---|
| NKI megakernels | One fused kernel per layer half for decode: KDA attention, the fused DSA layer, mHC and the MoE FFN. |
| 1M-token context | GLM-5.3-Flash's sparse attention (top 2,048) and linear attention, with fixed-size state. |
| Prefix cache | A radix tree over FP8 KV pages, plus a host-memory tier for evicted pages and state checkpoints. |
| Engines per box | Two for GLM-5.3-Flash, each tensor-parallel over 32 logical NeuronCores, behind a session-affine router; eight of 8 for Qwen3.8-27B. |
| Builds | GLM-5.3-Flash's latency, balanced (the default) and throughput, each tuned for a band of users per engine (--preset auto --users N picks one), and one for each other model: qwen38, glm53, dsv41. |
| Agent-ready APIs | OpenAI chat, completions and Responses, the Anthropic Messages API, the native /generate and /tokenize: streaming, tool calls, reasoning output and n choices. |
| Structured outputs | JSON schema, regex and EBNF through xgrammar, plus penalties and thinking budgets, each behind a flag. |
| Scheduling | First-come, longest-prefix, shortest-prompt and priority scheduling, queue limits and five prefix-cache eviction policies. |
| Offline compile | Every graph is built on a CPU host; the serving box loads them and compiles nothing by default. |
You need Docker, a trn2.48xlarge to serve on, and any x86_64 host to compile on. New to Trainium? Start with
docs/AWS.md.
1. Build the image (Neuron SDK 2.32 (neuronx-cc 2.27), Python 3.13)
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 .2. Build the compile cache (any x86_64 host, no NeuronCore needed; takes hours)
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 $OUT3. Serve (on the trn2.48xlarge, with $OUT/cache and $OUT/nki copied over)
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 80004. Call it with any OpenAI client
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"}, # keeps a conversation on one engine's prefix cache
)
print(reply.choices[0].message.content)The full guide covers what each step needs, start-up checks, the three builds and every flag: deploy · API · configuration.
Qwen3.8-27B (preview) takes the same steps with its own checkpoint and build: Qwen/Qwen3.8-27B at revision
1d4bf0f2ff6012fd82039f2fa52739d0dd7c60c0 in compile shapes and hf download, no compile decisions step (the
model is dense), --preset qwen38 on compile capture (after the --) and on serve, and --engines 8 on serve:
eight engines of 8 ranks behind the router on port 8000. GLM-5.3 (--preset glm53) and DeepSeek-V4.1-Flash
(--preset dsv41) have builds too, experimental. docs/CONFIGURATION.md lists each build.
| Target | Status |
|---|---|
AWS Trainium2, trn2.48xlarge (16 chips, LNC 2: 2 engines × TP 32 for GLM-5.3-Flash, 8 × TP 8 for Qwen3.8-27B, 1 × TP 64 for GLM-5.3 and DeepSeek-V4.1-Flash) |
✅ Supported |
| GLM-5.3-Flash (320B MoE, 18B active, FP8, 1M-token context) | ✅ Supported |
| Qwen3.8-27B (dense, Gated DeltaNet and gated attention, BF16) | 🔬 Preview: served on Trainium2 (--preset qwen38), checked against an fp32 reference (results) |
| GLM-5.3 (MoE, latent attention with a sparse indexer, FP8) | 🧪 Experimental: runs on Trainium2 at 4,096 tokens (--preset glm53) (results) |
| DeepSeek-V4.1-Flash (MoE with MXFP4 experts, compressed sparse attention, Engram) | 🧪 Experimental: its first 4 layers ran on Trainium2 (--preset dsv41), before a later fix to its selection (results) |
| More open models | 🔜 Coming soon. Request a model |
GLM-5.3-Flash is where TrnRT starts. An experimental model's code is in the tree and matches an upstream reference on CPU on reduced configurations; it may run on Trainium2, but it has not passed every correctness check fixed in advance there, so no served number is claimed for it. A preview model has passed them. docs/MODELS.md says what each one has and what it still needs. docs/ARCHITECTURE.md describes what a new model family needs.
SemiAnalysis AgentX replays real coding-agent sessions. One
trn2.48xlarge ran it at a 1M-token context with 32 concurrent agents, for one hour per point:
| Decode batch | Requests / min | Tokens / min | Decode tok/s per user (p50) | First token, cached (p50) | $ / M tokens (spot) |
|---|---|---|---|---|---|
| 4 | 19.3 | 2.36M | 46.6 | 76.73 s | $0.061 |
| 8 | 25.2 | 3.02M | 29.4 | 28.82 s | $0.047 |
| 12 (default) | 28.9 | 3.57M | 22.3 | 6.53 s | $0.040 |
Tokens count input (cached input included) and output. Spot price: $8.60/h, us-east-2, 3 Nov 2026. On a capacity block at $35.76/h, the batch 12 cost is $0.167 per million tokens. Full tables, cold-prompt latencies, long prompts and methodology are in docs/RESULTS.md.
These numbers were measured with an earlier build of TrnRT, at release 0.1.0's batch presets, which this release's builds replace. At release 0.1.0, this repository passed these checks against that build (docs/KNOWN_ISSUES.md):
- Graph equivalence: EQUAL on all 32 ranks, for all 157 graphs that build compiles in its default batch-12 configuration.
- Outputs: byte-identical to that build's on 384 of 384 requests.
- Serving: the two-engine serve in the Quickstart passed end to end on the device.
On 0.2.0's code with the serve fixes (24-25 Nov 2026), the builds read EQUAL against their reference builds, with
bitwise-equal outputs on the device, and the comparison with H100 and H200 above is a run of that code. 0.3.0 added the
other model families behind a dispatch in two traced files. They first ran on Trainium2 on 30 Nov - 1 Dec 2026, on the
code of pull request #63 before its review fixes, and on that code
tools/graph_equiv.py finds every graph of GLM-5.3-Flash's three builds equal to 0.2.0's. Neither that comparison nor
the device checks, nor the two-engine serve, has been run on 0.4.0's own commit
(KNOWN_ISSUES.md).
The qwen38 build: 8 engines of 8 ranks on one trn2.48xlarge, at most 2 requests running per engine. AgentX
(docs/AGENTX.md): agentx-harness 1.0.12 on a separate client, the public trace set, scored with
InferenceX's definitions per 16 chips (the whole box). The points ran in the order 32, 16, 8 users, every engine's
prompt cache flushed before each, with --max-context-length 262144 (the model's own context):
| Users | Profiled minutes | Requests / min | Tokens/s per chip | P90 tok/s per user | First token p50 / p90 | Prompt read from the cache | Tokens per $ (millions): AWS Capacity Block / SemiAnalysis's rate |
|---|---|---|---|---|---|---|---|
| 32 | 60 (1,532 requests) | 25.3 | 2,297 | 24.2 | 9.9 s / 76.6 s | 93.4% | 3.70 / 14.26 |
| 16 | 60 (1,209 requests) | 20.1 | 1,969 | 25.4 | 1.3 s / 20.7 s | 94.0% | 3.17 / 12.22 |
| 8 | 30 (379 requests) | 12.5 | 1,258 | 24.8 | 1.7 s / 18.2 s | 94.8% | 2.03 / 7.81 |
Measured 30 Nov - 1 Dec 2026 on Neuron SDK 2.32, on the code of pull request #63 before its review fixes; self-run, not an official InferenceX result, and not compared with a GPU here. P90 tok/s per user: 1 / the p90 inter-token latency. Prompt read from the cache: the share of the profiled requests' input tokens the server reported as cached. Tokens per $: total tokens (input, cached input included, and output) at AWS's Capacity Block list price for trn2.48xlarge, $2.235 per chip-hour (read 24 Nov 2026), and at SemiAnalysis's rate for trn2, $0.58 per chip-hour. With at most 2 running per engine, a box decodes 16 requests at once; at 32 users the rest wait. Every point is a valid submission by the harness's own check. The 8-user point ran 30 minutes, to end within the run's time window. On the same serve, GSM8K is 97.42% (± 0.44; 1,319 problems, 5-shot, strict match) and the needle 3 of 3. Every table and how each was checked: docs/RESULTS.md; GLM-5.3's and DeepSeek-V4.1-Flash's device checks, with what they did not pass, are there too.
Decode is not limited by memory bandwidth here; small instructions, kernel boundaries and exposed collectives dominate
it. So each decode megakernel follows three rules: keep the working set in SBUF, use both physical cores symmetrically,
and move the collectives into the kernel. docs/MEGAKERNELS.md walks through every kernel. The
diagram is GLM-5.3-Flash's layout; each other model's build sets its own tensor-parallel degree, and the
serve --engines option sets the number of engines to match (docs/CONFIGURATION.md).
trnrt/
├── __main__.py CLI: serve, engine, compile
├── serve/ OpenAI API, session-affine router, output parsers
├── engine/ scheduler, prefix caches, tensor parallelism
├── models/ GLM-5.3-Flash: KDA, DSA, mHC, MoE, FP8 loading; Qwen3.8-27B, GLM-5.3, DeepSeek-V4.1-Flash
├── kernels/ NKI decode megakernels and prefill kernels
└── compile/ offline compile: shapes, capture, neuronx-cc, strip
docker/ the serving and compile image
tools/ graph-equivalence gate, device checks, doc checks
benchmarks/ the recipe for every published point: builds, clients, scorers, accuracy
tests/ CPU test suite (no NeuronCore needed)
docs/ guides, results, kernel notes
More in docs/ARCHITECTURE.md.
make dev # editable install with test and lint tools (Python 3.13)
make check # lint, type-check, then the CPU test suiteSee docs/DEVELOPMENT.md for the test tiers and CI, CONTRIBUTING.md to send a
change (pull requests target development), SUPPORT.md to get help, and SECURITY.md to
report a vulnerability.
| Resource | Link |
|---|---|
Trainium2 and trn2 instances |
aws.amazon.com/ec2/instance-types/trn2 |
| AWS Neuron SDK documentation | awsdocs-neuron.readthedocs-hosted.com |
| NKI (Neuron Kernel Interface) | NKI documentation |
| Neuron deep learning containers | github.com/aws-neuron/deep-learning-containers |
| EC2 Capacity Blocks for ML | aws.amazon.com/ec2/capacityblocks |
Thanks to the AWS Neuron team for NKI and its documentation, to Z.ai for releasing GLM-5.3-Flash and GLM-5.3, to the Qwen team and DeepSeek for Qwen3.8-27B and DeepSeek-V4.1-Flash, and to SemiAnalysis for AgentX and its public traces. TrnRT includes code derived from other Apache-2.0 projects: see NOTICE and THIRD_PARTY_NOTICES.md.
Built by RunAnywhere.
AWS, Amazon Web Services, Trainium, Inferentia and Neuron are trademarks of Amazon.com, Inc. or its affiliates. The AWS logo appears here as published in AWS's Architecture Icons. TrnRT is an independent open-source project, not affiliated with or endorsed by Amazon Web Services.