Skip to content

Add Gemma-4 (E2B) text inference sample (torch-neuronx)#128

Draft
xbill9 wants to merge 1 commit into
aws-neuron:masterfrom
xbill9:gemma4-e2b-inference
Draft

Add Gemma-4 (E2B) text inference sample (torch-neuronx)#128
xbill9 wants to merge 1 commit into
aws-neuron:masterfrom
xbill9:gemma4-e2b-inference

Conversation

@xbill9

@xbill9 xbill9 commented Jul 12, 2026

Copy link
Copy Markdown

Adds a torch-neuronx/inference sample running google/gemma-4-E2B-it on a single NeuronCore (inf2.xlarge).

Addresses #127.

What it does

A two-graph KV-cache design traced with torch_neuronx.trace:

  • prefill — runs the padded prompt, returns logits + per-layer K/V;
  • decode — one token vs a fixed MAX-length KV buffer passed as graph I/O, updated with a one-hot masked write (no dynamic index ops).

Token embeddings and per-layer inputs are computed on the host and passed as inputs_embeds / per_layer_inputs, so the traced graph is free of the Per-Layer-Embeddings lookup. Uses eager attention + tanh GELU + final-logit softcap to match the reference.

Validation

Ran end-to-end on a fresh inf2 (Neuron SDK 2.23, torch-neuronx 2.8, transformers 5.13):

  • greedy output token-for-token identical to the CPU reference (SEQ_MATCH: True),
  • coherent generation, ~45.6 tok/s.

Notes

  • Draft pending maintainer feedback (see [Sample request] Gemma-4 (E2B) text inference on Inf2 via torch-neuronx #127): preferred placement (single notebook here vs. a subdirectory with a README documenting the Gemma-4 gotchas), and whether a follow-up TP=2 sample for the 4B/12B variants is in scope for this repo.
  • Gated model: the notebook includes the Hugging Face login step and does not bundle weights.
  • I'll sign the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant