Skip to content

Commit 8dee608

Browse files
committed
chore: improve AGENTS.md and add copilot instructions
1 parent 77ce059 commit 8dee608

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

.github/copilot-instructions.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Optimum Neuron Copilot Instructions
2+
3+
Use the root AGENTS.md as the single source of truth for onboarding, build, test, and architecture guidance:
4+
5+
- [AGENTS.md](../AGENTS.md)
6+
7+
The AGENTS.md file also links to subsystem-specific guides under [optimum/neuron/models/inference/AGENTS.md](../optimum/neuron/models/inference/AGENTS.md), [optimum/neuron/vllm/AGENTS.md](../optimum/neuron/vllm/AGENTS.md), and [tools/cache/AGENTS.md](../tools/cache/AGENTS.md).

AGENTS.md

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Optimum Neuron Agent Guide (Root)
22

3-
This repository bridges Hugging Face libraries with AWS Trainium/Inferentia. Use this file for project-wide guidance and see the model-specific guides:
3+
Optimum Neuron bridges Hugging Face libraries (Transformers, Diffusers, PEFT) with AWS Trainium/Inferentia accelerators. Use this file for project-wide guidance and the model-specific guides below:
44
- Inference models guide: [optimum/neuron/models/inference/AGENTS.md](optimum/neuron/models/inference/AGENTS.md)
55
- vLLM guide: [optimum/neuron/vllm/AGENTS.md](optimum/neuron/vllm/AGENTS.md)
66

@@ -18,7 +18,20 @@ This repository bridges Hugging Face libraries with AWS Trainium/Inferentia. Use
1818

1919
## Essential Developer Workflows
2020

21+
### Virtual Environment (Required)
22+
23+
Always activate the venv before any command; commands fail without it.
24+
25+
```bash
26+
python3 -m venv .venv
27+
source .venv/bin/activate
28+
pip install -e ".[neuronx,tests]"
29+
```
30+
2131
### Testing (Neuron hardware required)
32+
33+
Most tests require real Neuron hardware and will skip or fail on CPU-only machines.
34+
2235
```bash
2336
pytest tests/decoder/
2437
pytest tests/training/
@@ -42,6 +55,8 @@ optimum-cli export neuron \
4255
llama-neuron/
4356
```
4457

58+
Use separate processes for export and load to avoid Neuron device conflicts.
59+
4560
### Training Invocation
4661
```bash
4762
NEURON_CC_FLAGS="--model-type transformer" torchrun \
@@ -71,3 +86,44 @@ For the full porting checklist and test guidance, see [optimum/neuron/models/inf
7186

7287
## Cache Management
7388
Compiled models are cached to the HF Hub. Test helpers live in [tests/conftest.py](tests/conftest.py). Relevant env vars: `NEURON_CC_FLAGS`, `NEURON_COMPILE_CACHE_URL`, `NEURON_RT_VISIBLE_CORES`.
89+
90+
## CI/CD Workflows (Summary)
91+
92+
All test workflows follow the same pattern:
93+
1. Checkout code
94+
2. Install Neuronx runtime (via `.github/actions/install_neuronx_runtime`)
95+
3. Prepare venv `aws_neuron_venv_pytorch` (via `.github/actions/prepare_venv`)
96+
4. Install `optimum-neuron[neuronx,tests]` (via `.github/actions/install_optimum_neuron`)
97+
5. Run pytest in the venv
98+
99+
## Runtime Pitfalls
100+
101+
- Static shapes: runtime input shapes must match compiled shapes.
102+
- Export and load in separate processes to avoid device conflicts.
103+
- Neuron runtime does not release devices reliably within the same process.
104+
- Decoder graph changes require cache prune when using the fixtures defined under `tests/fixtures/export_models.py`: `python tools/prune_test_models.py`.
105+
106+
## Environment Variables
107+
108+
- `HF_TOKEN`: Required for hub access in tests.
109+
- `NEURON_CC_FLAGS="--model-type transformer"`: Required for training compilation.
110+
- `NEURON_RT_VISIBLE_CORES`: Control visible NeuronCores.
111+
112+
## Validation Checklist (Before PR)
113+
114+
1. Activate venv: `source .venv/bin/activate`.
115+
2. Style check: `make style_check` (or `make style`).
116+
3. Run relevant tests:
117+
- CPU export logic: `pytest tests/exporters/`
118+
- INF2 decoder: `pytest tests/decoder/`
119+
- TRN1 training: `pytest -m "is_trainium_test" tests/training/`
120+
4. Check model-specific AGENTS.md if you touched a model directory.
121+
122+
## Troubleshooting
123+
124+
- `ruff: command not found`: activate venv first.
125+
- `No module named 'neuronx_distributed'`: install extras with `pip install -e ".[neuronx]"`.
126+
- Tests failing on CPU: expected for most Neuron tests.
127+
- Compilation timeout: large models take 30-60 min, use `--timeout 0`.
128+
129+
Trust these instructions and only search for more context if something is missing or incorrect.

0 commit comments

Comments
 (0)