Skip to content

Commit 01ebc58

Browse files
committed
Try testing more pytest
1 parent 79744f0 commit 01ebc58

File tree

2 files changed

+213
-61
lines changed

2 files changed

+213
-61
lines changed

CLAUDE.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
ExecuTorch is an end-to-end solution for on-device inference powering AI experiences across Meta's products. It provides a portable runtime for executing PyTorch models on resource-constrained devices including mobile phones, embedded systems, and microcontrollers.
8+
9+
## Key Development Commands
10+
11+
### Build Commands
12+
13+
```bash
14+
# Configure CMake build (one-time setup)
15+
rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake ..
16+
17+
# Build the project (use core count + 1 for -j value)
18+
cmake --build cmake-out -j9
19+
20+
# Build with common extensions enabled
21+
cmake . \
22+
-DEXECUTORCH_BUILD_XNNPACK=ON \
23+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
24+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
25+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
26+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
27+
-Bcmake-out
28+
```
29+
30+
### Testing Commands
31+
32+
```bash
33+
# Run all C++ tests
34+
./test/run_oss_cpp_tests.sh
35+
36+
# Run Python tests
37+
pytest
38+
39+
# Run specific test directory
40+
./test/run_oss_cpp_tests.sh runtime/core/test/
41+
42+
# Build and run size tests
43+
./test/build_size_test.sh
44+
```
45+
46+
### Code Quality
47+
48+
```bash
49+
# Set up lintrunner
50+
pip install lintrunner==0.12.7 lintrunner-adapters==0.12.4
51+
lintrunner init
52+
53+
# Run linter
54+
lintrunner
55+
56+
# Auto-fix linting issues
57+
lintrunner -a
58+
59+
# Run specific linters
60+
lintrunner --take CLANGFORMAT
61+
```
62+
63+
### Python Environment Setup
64+
65+
```bash
66+
# Install requirements
67+
./install_requirements.sh
68+
69+
# Install in development mode
70+
pip install -e .
71+
```
72+
73+
## Architecture Overview
74+
75+
### Core Components
76+
77+
**Export Pipeline (exir/)**
78+
- Captures PyTorch models via torch.export
79+
- Lowers models through EXIR dialects (ATen → Edge → Backend/Core ATen)
80+
- Performs optimizations like memory planning and operator fusion
81+
- Serializes to .pte (Program Transfer Entity) format
82+
83+
**Runtime (runtime/)**
84+
- Loads and executes .pte files
85+
- Core structures: Tensor, EValue, Program, Method
86+
- Memory management with static allocation
87+
- Delegate interface for hardware acceleration
88+
89+
**Kernels (kernels/)**
90+
- `portable/`: Reference C++ implementations for all operators
91+
- `optimized/`: SIMD-optimized implementations
92+
- `quantized/`: Quantized operator implementations
93+
- Operators registered via static initialization
94+
95+
**Backends (backends/)**
96+
- Hardware-specific accelerators (Apple CoreML/MPS, ARM, Qualcomm, etc.)
97+
- Each backend provides:
98+
- Partitioner: Identifies subgraphs for delegation
99+
- Preprocess: Converts subgraphs to backend format
100+
- Runtime: Executes delegated operations
101+
102+
### Key Design Patterns
103+
104+
**Memory Management**
105+
- No dynamic allocation in core runtime
106+
- Static memory planning at export time
107+
- MemoryAllocator interface for custom allocation strategies
108+
109+
**Error Handling**
110+
- Result<T, Error> type for fallible operations
111+
- No exceptions (disabled for portability)
112+
- ET_CHECK macros for assertions
113+
114+
**Backend Delegation**
115+
- Subgraphs marked with delegation tags during export
116+
- Backend runtime loaded dynamically
117+
- Fallback to CPU execution if delegation fails
118+
119+
### Model Export Flow
120+
121+
1. Capture PyTorch model with torch.export
122+
2. Lower through EXIR passes (quantization, delegation, optimization)
123+
3. Run memory planning to determine buffer sizes
124+
4. Emit to flatbuffer format (.pte file)
125+
5. Load in runtime and execute
126+
127+
### Extension Modules
128+
129+
**Module (extension/module/)**
130+
- Simplified C++ API for loading and running models
131+
- Handles method execution and tensor I/O
132+
133+
**LLM Support (extension/llm/)**
134+
- Specialized runtime for large language models
135+
- Custom operators for KV caching, rotary embeddings
136+
- Token sampling strategies
137+
138+
**Platform Bindings**
139+
- Android: JNI wrappers in extension/android/
140+
- iOS: Objective-C++ wrappers in extension/apple/
141+
- Python: pybind11 bindings in extension/pybindings/
142+
143+
## Working with Models
144+
145+
Example models are in `examples/models/`. Each model directory typically contains:
146+
- `export_<model>.py`: Exports PyTorch model to .pte
147+
- `model.py`: Model definition
148+
- `runner/`: C++ runner implementation
149+
- `README.md`: Model-specific instructions
150+
151+
Common workflow:
152+
1. Export model: `python export_llama.py`
153+
2. Build runner: `cmake --build cmake-out --target llama_runner`
154+
3. Run inference: `./cmake-out/examples/models/llama/llama_runner --model_path=model.pte`
155+
156+
## Code Style Guidelines
157+
158+
- C++ follows Google style with modifications:
159+
- Functions use `lower_snake_case()`
160+
- Files use `lower_snake_case.cpp`
161+
- Headers use `#pragma once`
162+
- All includes use `<angle_brackets>`
163+
- Python follows PyTorch style
164+
- No dynamic memory allocation in runtime
165+
- Avoid templates to minimize binary size
166+
- Document public APIs with Doxygen comments

pytest.ini

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,44 @@ addopts =
88
--capture=sys
99
# don't suppress warnings, but don't shove them all to the end either
1010
-p no:warnings
11-
# Ignore backends/arm tests you need to run examples/arm/setup.sh to install some tool to make them work
12-
# For GitHub testing this is setup/executed in the unittest-arm job see .github/workflows/pull.yml for more info.
11+
12+
# === STILL IGNORED - Infrastructure Dependencies ===
13+
# Ignore backends/arm tests - requires running examples/arm/setup.sh to install tools
14+
# For GitHub testing this is setup/executed in the unittest-arm job see .github/workflows/pull.yml
1315
--ignore-glob=backends/arm/**/*
14-
# explicitly list out tests that are running successfully in oss
16+
# backends/test - WIP testing infra, see https://github.com/pytorch/executorch/discussions/11140
17+
--ignore=backends/test
18+
# T200992559: Add torchao to ET as core dependency
19+
--ignore=examples/models/llama/tests/test_pre_quantization_transforms.py
20+
# This test depends on test-only cpp ops lib
21+
--ignore=kernels/quantized/test/test_quant_dequant_per_token.py
22+
--ignore=export/tests/test_export_stages.py
23+
24+
# === TEST DIRECTORIES TO RUN ===
1525
.ci/scripts/tests
16-
examples/models/test
26+
27+
# backends
28+
backends/apple/coreml/test
29+
backends/test/harness/tests
30+
backends/test/suite/tests
31+
backends/transforms
32+
backends/xnnpack/test
33+
34+
# codegen
35+
codegen/test
36+
37+
# devtools
1738
devtools/
18-
--ignore=devtools/visualization/visualization_utils_test.py
39+
1940
# examples
41+
examples/models/test
2042
examples/models/llama/tests
2143
examples/models/llama/config
2244
examples/models/llama3_2_vision/preprocess
2345
examples/models/llama3_2_vision/vision_encoder/test
2446
examples/models/llama3_2_vision/text_decoder/test
25-
# examples/models/llava/test TODO: enable this
47+
examples/models/llava/test
48+
2649
# exir
2750
exir/_serialize/test
2851
exir/backend/test
@@ -32,68 +55,31 @@ addopts =
3255
exir/emit/test
3356
exir/program/test
3457
exir/tests/
35-
# executorch/export
58+
59+
# export
3660
export/tests
37-
--ignore=export/tests/test_export_stages.py
38-
# kernels/
61+
62+
# extension
63+
extension/
64+
65+
# kernels
3966
kernels/prim_ops/test
4067
kernels/quantized
41-
# Because this test depends on test only cpp ops lib
42-
# Will add test only cmake targets to re-enable this test
43-
# but maybe it is a bit of anti-pattern
44-
--ignore=kernels/quantized/test/test_quant_dequant_per_token.py
4568
kernels/test/test_case_gen.py
46-
# backends/test
47-
# This effort is WIP and will be enabled in CI once testing infra
48-
# is stable and signal to noise ratio is good (no irrelevant failures).
49-
# See https://github.com/pytorch/executorch/discussions/11140
50-
--ignore=backends/test
51-
backends/test/harness/tests
52-
backends/test/suite/tests
53-
# backends/xnnpack
54-
backends/xnnpack/test/ops
55-
--ignore=backends/xnnpack/test/ops/test_bmm.py
56-
--ignore=backends/xnnpack/test/ops/test_conv2d.py
57-
--ignore=backends/xnnpack/test/ops/test_linear.py
58-
--ignore=backends/xnnpack/test/ops/test_sdpa.py
59-
backends/xnnpack/test/passes
60-
backends/xnnpack/test/recipes
61-
backends/xnnpack/test/serialization
62-
# backends/apple/coreml
63-
backends/apple/coreml/test
64-
# extension/
65-
extension/llm/modules/test
66-
extension/llm/export
67-
extension/llm/custom_ops/test_sdpa_with_kv_cache.py
68-
extension/llm/custom_ops/test_update_cache.py
69-
extension/llm/custom_ops/test_quantized_sdpa.py
70-
extension/pybindings/test
71-
extension/training/pybindings/test
72-
# Runtime
69+
70+
# profiler
71+
profiler/
72+
73+
# runtime
7374
runtime
74-
# Tools
75-
codegen/test
75+
76+
# test
77+
test/
78+
79+
# tools
7680
tools/cmake
77-
# test TODO: fix these tests
78-
# test/end2end/test_end2end.py
79-
--ignore=backends/xnnpack/test/ops/linear.py
80-
--ignore=backends/xnnpack/test/models/llama2_et_example.py
81-
# T200992559: Add torchao to ET as core dependency
82-
--ignore=examples/models/llama/tests/test_pre_quantization_transforms.py
83-
--ignore=exir/backend/test/demos
84-
--ignore=exir/backend/test/test_backends.py
85-
--ignore=exir/backend/test/test_backends_lifted.py
86-
--ignore=exir/backend/test/test_partitioner.py
87-
--ignore=exir/tests/test_common.py
88-
--ignore=exir/tests/test_memory_format_ops_pass_aten.py
89-
--ignore=exir/tests/test_memory_planning.py
90-
--ignore=exir/tests/test_op_convert.py
91-
--ignore=exir/tests/test_passes.py
92-
--ignore=exir/tests/test_quant_fusion_pass.py
93-
--ignore=exir/tests/test_quantization.py
94-
--ignore=exir/tests/test_verification.py
9581

9682
# run the same tests multiple times to determine their
9783
# flakiness status. Default to 50 re-runs
9884
flake-finder = true
99-
flake-runs = 50
85+
flake-runs = 50

0 commit comments

Comments
 (0)