optimum-neuron / tests
AGENTS.md270 starsChanged 10 months agoApache-2.0View on GitHub
Read this before working on any test code under tests/. Fixtures in tests/fixtures/llm/ are registered as pytest plugins in tests/conftest.py: This makes neuron_llm_config, any_generate_model, and speculation available to all tests. Full documentation is in the tests/fixtures/llm/export_models.py module docstring. Key points: Each model is compiled for two shapes: (batch_size=4, seq_len=1024) and (batch_size=1, seq_len=8192). Config names follow the pattern <model>-<batch>x<seq>, e.g. llama-4x1024. neuron_llm_config — for tests that need a specific model config: any_generate_model — for tests that should run across all generation…
- Deletes or force-pushes
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository32 other files it gives its agents.
- AGENTS.mdAGENTS.md
- optimum/neuron/cache/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/backend/modules/attention/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/gemma3/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/granite/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/llama4/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/llama/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/mixtral/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/phi3/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/qwen2/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/qwen3/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/qwen3_moe/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/smollm3/AGENTS.mdAGENTS.md
- optimum/neuron/models/inference/smolvlm/AGENTS.mdAGENTS.md
- optimum/neuron/vllm/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- optimum/neuron/cache/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/gemma3/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/granite/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/llama4/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/llama/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/mixtral/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/phi3/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/qwen2/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/qwen3/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/qwen3_moe/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/smollm3/CLAUDE.mdCLAUDE.md
- optimum/neuron/models/inference/smolvlm/CLAUDE.mdCLAUDE.md
- optimum/neuron/vllm/CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
The file
We split this AGENTS.md into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 3
Read this before working on any test code under tests/.
- Distinctive: line 83
If you skip the pre-export step, fixtures will auto-export on first use.
- Distinctive: line 108
There is no such thing as a "stale compiler cache entry.": If the HLO graph changes (because you changed model code), the hash changes, and …
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Test Infrastructure Agent Guide
Read this before working on any test code under tests/.
Directory Structure
tests/
conftest.py # Root conftest — registers fixture plugins via pytest_plugins
fixtures/llm/
export_models.py # Model export fixtures + CLI (see detailed docs in the module docstring)
vllm_service.py # vLLM OpenAI-compatible service launcher fixture
vllm_docker_service.py # vLLM Docker service launcher fixture
decoder/ # LLM decoder tests (generation, export, pipelines, modules, etc.)
conftest.py # Reorders @subprocess_test tests to run before session fixtures
vllm/ # vLLM integration tests
engine/ # Direct engine API tests
service/ # OpenAI-compatible serving tests
docker/ # Docker container testsFixture Registration
Fixtures in tests/fixtures/llm/ are registered as pytest plugins in tests/conftest.py:
pytest_plugins = [
"fixtures.llm.vllm_docker_service",
"fixtures.llm.vllm_service",
"fixtures.llm.export_models",
]This makes neuron_llm_config, any_generate_model, and speculation available to all tests.
The Export Models Fixture System
Full documentation is in the tests/fixtures/llm/export_models.py module docstring. Key points:
Model Configurations
Each model is compiled for two shapes: (batch_size=4, seq_len=1024) and (batch_size=1, seq_len=8192).
Config names follow the pattern <model>-<batch>x<seq>, e.g. llama-4x1024.
Using Fixtures in Tests
neuron_llm_config — for tests that need a specific model config:
@pytest.mark.parametrize("neuron_llm_config", ["llama-4x1024"], indirect=True)
def test_something(neuron_llm_config: dict[str, Any]):
model = NeuronModelForCausalLM.from_pretrained(neuron_llm_config["neuron_model_path"])any_generate_model — for tests that should run across all generation models:
def test_greedy_expectations(any_generate_model):
model_path = any_generate_model["neuron_model_path"]
config_name = any_generate_model["name"] # e.g. "llama-4x1024"Both yield a dict with keys: name, model_id, task, export_kwargs, neuron_model_id, neuron_model_path.
Hub Caching
Compiled models are pushed to private HF Hub repos. The repo name encodes all invalidation keys:
<org>/optimum-neuron-testing-<version>-<sdk>-<instance>-<code_hash>-<config_name>.
The code hash changes when pyproject.toml or anything under optimum/neuron/models/inference/ changes.
Old repos must be pruned manually: python tools/prune_test_models.py.
Always Pre-Export Models Before Running Tests
CI always runs python tests/fixtures/llm/export_models.py as a separate step before any pytest invocation (see .github/workflows/test_inf2_llm.yml and test_inf2_vllm.yml). You must do the same locally:
# Export all models (or use a pattern like 'llama*')
python tests/fixtures/llm/export_models.py
# Then run tests
pytest -sv tests/decoder/test_decoder_generation.pyIf you skip the pre-export step, fixtures will auto-export on first use. This causes:
- Long hangs: compilation takes 10-30+ minutes per model, making it hard to tell if a test is stuck or just compiling.
- NeuronCore conflicts: the compilation process may conflict with subprocess-isolated tests that also need device access.
Expected Test Durations
Based on CI logs (inf2.8xlarge, models pre-exported), entire test groups complete within:
| Test group | Duration |
| LLM utils / hub / CLI / embedding | < 1 min each |
| LLM export tests | ~4 min |
| LLM generation tests | ~7 min |
| LLM pipeline tests | ~5 min |
| LLM module tests (NKI kernels) | ~19 min |
| LLM cache tests | ~5 min |
| vLLM engine generation | ~20 min |
| vLLM service tests | ~15 min |
An individual test should complete within 2 minutes. If a test hangs longer than that, the most likely cause is a missing pre-export triggering compilation inside the fixture. Pre-export, then re-run.
Never Wipe the Neuron Compiler Cache
The Neuron compiler cache is content-addressed: each compiled NEFF is keyed by the SHA hash of the HLO graph that produced it. The hash space is large enough to make collisions practically impossible.
There is no such thing as a "stale compiler cache entry." If the HLO graph changes (because you changed model code), the hash changes, and a new entry is created. The old entry is simply never matched again — it does no harm.
Wiping the compiler cache (e.g. rm -rf /var/tmp/neuron-compile-cache) only forces expensive recompilation with zero benefit. Never suggest or perform cache deletion as a debugging step.
Subprocess Test Ordering
tests/decoder/conftest.py contains a pytest_collection_modifyitems hook that moves @subprocess_test-decorated tests to run before all other tests. This prevents session-scoped fixtures (which load models onto NeuronCores) from blocking subprocess tests that need device access in a child process.
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
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.

