You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Sample request] Gemma-4 (E2B) text inference on Inf2 via torch-neuronx #127
Is your feature request related to a problem?
There's no torch-neuronx/inference sample for Google's Gemma-4 family. optimum-neuron doesn't
support Gemma-4, and the model's per-layer KV-sharing / Per-Layer-Embeddings don't trace through the
vendor stack out of the box, so there's currently no reference for running these models on Inferentia.
Describe the solution you'd like
A self-contained notebook — hf_pretrained_gemma4_e2b_inference_on_inf2.ipynb — that runs google/gemma-4-E2B-it on a single NeuronCore (inf2.xlarge) with greedy output token-for-token
identical to the CPU reference. It demonstrates a two-graph KV-cache design (prefill + single-token
decode) with the KV cache passed as graph I/O via torch_neuronx.trace, host-side Per-Layer-Embeddings,
and eager attention. Includes a validation cell (SEQ_MATCH vs CPU) and a tok/s measurement
(~45 tok/s measured).
Scope / what I can contribute
I have this working and validated end-to-end (Neuron SDK 2.23, torch-neuronx 2.8, transformers 5.13).
I'd start with the E2B notebook (single-core, matches the existing hf_pretrained_* convention), and
can follow up with a tensor-parallel (TP=2) E4B/12B sample if the maintainers want it.
Question for maintainers: preferred layout — a single notebook in torch-neuronx/inference/, or a
subdirectory (torch-neuronx/inference/gemma4_e2b/) with the notebook + a short README documenting the
Gemma-4-specific gotchas (layer_scalar buffer loading, eager-attention for sliding_window, host-side
PLE, softcap)? And is TP inference in scope for this repo or better suited elsewhere?
I've read CONTRIBUTING.md and will fork, sign the CLA, and ensure the notebook runs clean top-to-bottom
on a fresh Inf2.
Following up alongside PR #128: closing this as well, since torch-neuronx (torch-xla) is entering maintenance mode as of release 2.32.0. Thanks for the detailed writeup.
Activity
github-actions commentedon Jul 12, 2026
Hi @xbill9, Thank you for filing the issue! We will take a look and get back to you.
aws-cph commentedon Aug 17, 2026
Following up alongside PR #128: closing this as well, since torch-neuronx (torch-xla) is entering maintenance mode as of release 2.32.0. Thanks for the detailed writeup.
arminagha1234 commentedon Aug 18, 2026
Hi please reach out to me, @xbill9 aghaebra@amazon.com thank you for contributing !