SIGN IN SIGN UP

Qualcomm AI Engine Direct - [GenAI Pipeline] PR2: Strategy Interfaces & Stage Wrappers (#20795)

## Summary

This PR adds the strategy interfaces, and stage wrappers for the GenAI
pipeline. This is the second of 7 PRs establishing the framework
skeleton. It builds on PR1 (data model + engine routing) and introduces
the Strategy pattern ABCs, concrete stage delegation wrappers and
Executorch strategy stubs. No existing files are modified (except
`__init__.py` introduced in PR1 for imports).

### What's included

#### Strategy ABCs (one class per file):

- `ModelPreparationStrategy` — in `strategies/model_preparation/`
- `QuantizationStrategy` — in `strategies/quantization/`
- `CompilationStrategy` — in `strategies/compilation/`
- `InferenceStrategy` — in `strategies/inference/`

Each ABC defines `invoke(context, input_config) -> output_config`.

#### Strategy stubs (raise `NotImplementedError`):

- `ExecuTorchModelPreparationStrategy`
- `ExecuTorchQuantizationStrategy`
- `ExecuTorchCompilationStrategy`
- `ExecuTorchInferenceStrategy`

#### Stage wrappers:

- `ModelPreparationStage`, `QuantizationStage`, `CompilationStage`,
`InferenceStage`.
- Each delegates to its injected strategy via `invoke()`.
- `name` property returns stage constant from `pipeline_types.py`.

#### Pipeline stage ABC:

- `PipelineStage` — abstract base with `name` property and `invoke()`
method.

#### Unit tests (16 tests across 6 test files):

- Strategy ABC enforcement (cannot instantiate, must implement
`invoke()`).
- Strategy stub tests (`NotImplementedError` raised).
- Stage delegation tests (`assert_called_once_with`).
- Stage name tests (use constants).

### PR Review Checklist

- All new classes follow single responsibility (one class per file) -
Yes.
- All dependencies are injected via constructor with sensible defaults -
Yes.
- All external calls are behind injectable interfaces - N/A, no external
calls.
- Unit tests cover every public method - Yes. 
- No existing files are modified (Phase 1 constraint) - Yes (only
`__init__.py` updated to add `PipelineStage` export).
- Docstrings on all public classes and methods - Yes. 
- Type annotations on all function signatures - Yes. 
- Logging follows the strategy in the LLD - N/A, no logging in this PR.

### Related PRs

- PR 1: Core data model, engine routing & exceptions:
https://github.com/pytorch/executorch/pull/20409
- PR 2: Strategy interfaces & stage wrappers: this PR.
- PR 3: Pipeline orchestrator: pending.
- PR 4: Adapter interfaces & default implementations: pending.
- PR 5: Model preparation & quantization strategies: pending
- PR 6: Compilation & inference strategy implementations: pending.
- PR 7: Integration & E2E tests: pending.

## Test plan

```
python -m pytest \
  backends/qualcomm/genai_pipeline/tests/strategies/ \
  backends/qualcomm/genai_pipeline/tests/stages/ \
  -v
```

All 16 unit-tests passed.

### Test Coverage

Command to run:

```
coverage run --rcfile=backends/qualcomm/.coveragerc \
  -m pytest \
    backends/qualcomm/genai_pipeline/tests/strategies/ \
    backends/qualcomm/genai_pipeline/tests/stages/ \
  -v

coverage report --rcfile=backends/qualcomm/.coveragerc \
  --include="backends/qualcomm/genai_pipeline/pipeline_stage.py,backends/qualcomm/genai_pipeline/strategies/*,backends/qualcomm/genai_pipeline/stages/*"
```

Result:

```
Name                                                                                           Stmts   Miss Branch BrPart  Cover   Missing
------------------------------------------------------------------------------------------------------------------------------------------
backends/qualcomm/genai_pipeline/stages/compilation_stage.py                                      14      0      0      0   100%
backends/qualcomm/genai_pipeline/stages/inference_stage.py                                        14      0      0      0   100%
backends/qualcomm/genai_pipeline/stages/model_preparation_stage.py                                14      3      0      0    79%   24, 28, 35
backends/qualcomm/genai_pipeline/stages/quantization_stage.py                                     14      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/compilation/compilation_strategy.py                    7      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/compilation/executorch_compilation_strategy.py         7      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/inference/executorch_inference_strategy.py             7      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/inference/inference_strategy.py                        7      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/model_preparation/model_preparation_strategy.py        7      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/quantization/executorch_quantization_strategy.py       7      0      0      0   100%
backends/qualcomm/genai_pipeline/strategies/quantization/quantization_strategy.py                  7      0      0      0   100%
------------------------------------------------------------------------------------------------------------------------------------------
TOTAL                                                                                            110     3      0      0    97%
```
Q
qti-horodnic committed
53551c160180a6eaa125b902a672bbf5acf37bbf
Parent: 776ba0c
Committed by GitHub <noreply@github.com> on 7/22/2026, 5:22:02 PM