# Set up your environment for ExecuTorch quantization

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/)
- [Explore PTQ and QAT for ExecuTorch INT8 deployment](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/1-introduction/)
- [Set up your environment for ExecuTorch quantization](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/2-set-up-your-environment/)
- [Apply PTQ and export a quantized VGF model](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/3-run-ptq-and-export-vgf/)
- [Apply QAT and export a quantized VGF model](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/4-run-qat-and-export-vgf/)
- [Inspect the graph with Model Explorer](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/5-validate-and-choose-a-quantization-strategy/)
- [Next Steps](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/quantize-neural-upscaling-models/_next-steps/)

## Install and configure PyTorch, TorchAO, and ExecuTorch for quantization
In this section, you create a Python environment with PyTorch, TorchAO, and ExecuTorch components needed for quantization and `.vgf` export.

> **Note**  
> If you already use [Neural Graphics Model Gym](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/model-training-gym/), keep that environment and reuse it here.

## Create a virtual environment
Create and activate a virtual environment:
```bash
python3 -m venv venv
source venv/bin/activate
python -m pip install --upgrade pip
```

## Clone the ExecuTorch repository
In your virtual environment, clone the ExecuTorch repository and run the installation script:
```bash
git clone https://github.com/pytorch/executorch.git
cd executorch
./install_executorch.sh
```

## Run the Arm backend setup script
From the root of the cloned `executorch` repository, run the Arm backend setup script:
```bash
./examples/arm/setup.sh \
  --i-agree-to-the-contained-eula \
  --disable-ethos-u-deps \
  --enable-mlsdk-deps
```
In the same terminal session, source the generated setup script so the Arm backend tools (including the model converter) are available on your `PATH`:
```bash
source ./examples/arm/arm-scratch/setup_path.sh
```
Verify the model converter is available:
```bash
command -v model-converter || command -v model_converter
```
Verify your imports:
```python
import torch
import torchvision
import torchao

import executorch
import executorch.backends.arm
from executorch.backends.arm.vgf.partitioner import VgfPartitioner

print("torch:", torch.__version__)
print("torchvision:", torchvision.__version__)
print("torchao:", torchao.__version__)
```
> **Tip**  
> If `executorch.backends.arm` is missing, you installed an ExecuTorch build without the Arm backend. Use an ExecuTorch build that includes `executorch.backends.arm` and the VGF partitioner.  
> If you checked out a specific ExecuTorch branch (for example, `release/1.0`) and you run into version mismatches, check out the main branch of ExecuTorch from the cloned repository and install from source:
```bash
pip install -e .
```

## What you’ve accomplished and what’s next
In this section, you:
- Created a Python virtual environment with PyTorch, TorchAO, and ExecuTorch
- Ran the Arm backend setup script and verified the model converter is available on your `PATH`

In the next section, you apply PTQ to a sample model and generate a `.vgf` artifact.
