agentleFS
Hugging FaceKnown publisherhuggingface/optimum-neuron/optimum/neuron/models/inference/llama4/AGENTS.md

optimum-neuron / llama4

AGENTS.md270 starsChanged 10 months agoApache-2.0View on GitHub

This directory contains the Neuron-optimized Llama4 inference implementation, aligned to HF Transformers with Neuron-specific changes from NxDI. Reference: NxDI Llama4 implementation Llama4 follows Llama architecture with shared removals: Why removed: Requires neuronxcc.nki private APIs not stabilized for external use. Optimum relies on compiler auto-optimization. Why removed: Advanced serving features for production deployments. vLLM integration handles production needs. Why removed: Optimum uses HF config base with neuron_config.json extensions. Optimum Neuron prioritizes stability, maintainability, and HF ecosystem compatibility.

The file

Files
AGENTS.md

Llama4 Inference Model Guide

This directory contains the Neuron-optimized Llama4 inference implementation, aligned to HF Transformers with Neuron-specific changes from NxDI.

HF reference

What differs vs HF

  • Parallel layers: TP-aware linear/embedding layers replace HF modules.
  • Attention base: NeuronAttentionBase enforces TP head counts and static shapes.
  • Static shapes & KV cache: Uses KVCacheManager and fixed sequence shapes from neuron_config.json.

What was removed from NxDI

Reference: NxDI Llama4 implementation

Llama4 follows Llama architecture with shared removals:

Removed NKI Kernel Implementations

  • MLP TKG kernel - Advanced small batch optimization using NKI compiler primitives
  • Quantized MLP kernels - INT8 quantization with fused operations
  • NKI-based standard MLP - Hand-tuned MLP with optional fused residual add

Why removed: Requires neuronxcc.nki private APIs not stabilized for external use. Optimum relies on compiler auto-optimization.

Removed Serving/Speculative Decoding

  • EAGLE draft models - Speculative decoding with draft models
  • Medusa heads - Multi-head speculative sampling
  • Flash Decoding - Multi-query parallelism for decode phase
  • LoRA serving - Dynamic adapter switching during inference
  • Context parallelism - MLP splitting across cores for long contexts

Why removed: Advanced serving features for production deployments. vLLM integration handles production needs.

Removed Configuration/Utilities

  • NxDI-specific configs - Replaced by Optimum's NxDNeuronConfig
  • Module registration system - Plugin architecture for swapping implementations
  • Preshard hooks - Weight sharding orchestration before init
  • Custom RMSNorm variants - CPU vs NXD mode switching
  • Quantization helpers - Per-layer quantization control

Why removed: Optimum uses HF config base with neuron_config.json extensions.

What Optimum Neuron Keeps

  • Parallel layers with TP-aware sharding
  • NeuronAttentionBase with GQA, flash attention, static KV cache
  • Rotary embeddings with long context scaling
  • State dict conversion (QKV fusion, vocab parallelism)
  • Decoder layer composition

Optimum Neuron prioritizes stability, maintainability, and HF ecosystem compatibility.

Key files

  • optimum/neuron/models/inference/llama4/modeling_llama4.py
  • optimum/neuron/models/inference/backend/modules/attention/attention_base.py

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.