> ## Documentation Index
> Fetch the complete documentation index at: https://docs.r3al.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# End-to-end workflow

> From framework weights to a validated quantized ONNX deliverable.

Every vision model follows the same path: **export to ONNX (if needed), quantize on the platform, monitor the job, download the result, validate locally**.

<Note>
  The R3AL.AI SDK is model-agnostic. Classification, detection, segmentation, pose, custom architectures: if you can export it to ONNX, you can quantize it with the same API. Quantization runs on the platform; export and validation run locally.
</Note>

## 0. Authenticate

```python theme={null}
import r3alai.platform as platform

platform.login("r3l_live_...")   # or set R3AL_API_KEY
```

See [Using the platform](/guides/platform) for creating an account and API key.

## 1. Export to ONNX (if needed)

If you already have `.onnx`, skip to step 2. Otherwise, pass the checkpoint straight to `quantize()` and the SDK exports it locally before upload (local export needs the matching extra, for example `r3alai[export-torch]`):

<CodeGroup>
  ```python Auto-export on quantize theme={null}
  from r3alai.quant import Quantizer

  result = Quantizer().quantize(
      "checkpoint.pt",
      source="pytorch",
      input_shape=[1, 3, 224, 224],
      calibration_data=["img1.jpg", "img2.jpg", "img3.jpg"],  # required for the default ptq_static
      output_dir="./out",
  )
  ```

  ```python Export only theme={null}
  from r3alai.quant import export_to_onnx

  export_to_onnx(
      "checkpoint.pt",
      "./exported",
      source="pytorch",
      input_shape=[1, 3, 224, 224],
  )
  ```
</CodeGroup>

Supported export sources: `onnx` (passthrough), `pytorch`, `ultralytics`, `tensorflow`, `tflite`, `paddle`. Discover them with `r3alai.quant.list_export_sources()`.

## 2. Choose PTQ or QAT

```text theme={null}
Smallest + fastest, have sample images?    →  PTQ: ptq_static   (default)
No calibration data (MatMul-heavy model)?  →  PTQ: ptq_dynamic
PTQ accuracy not good enough?              →  QAT
```

See [Quantization methods](/concepts/methods) for the full decision guide.

## 3. Quantize via the platform (PTQ)

Each call uploads your model, runs the job on R3AL GPUs, streams progress, and downloads the bundle.

<CodeGroup>
  ```python Static INT8 or INT4 (default) theme={null}
  from r3alai.quant import Quantizer

  result = Quantizer().quantize(
      "model.onnx",
      calibration_data=["/data/sample1.jpg", "/data/sample2.jpg", "/data/sample3.jpg"],  # a handful of representative inputs
      output_dir="./out",
  )
  print(result.path)
  ```

  ```python Dynamic INT8 or INT4 (no calibration data) theme={null}
  from r3alai.quant import QuantConfig, Quantizer

  result = Quantizer(QuantConfig(method="ptq_dynamic")).quantize("model.onnx", output_dir="./out")
  print(result.path)
  ```
</CodeGroup>

<Warning>
  If the model needs a special preprocessing step to convert images to input tensors, please handle the preprocessing step yourself. By default, standard preprocessing is applied.   See [Calibration](/concepts/calibration).
</Warning>

## 4. Or train with QAT

When PTQ loses too much accuracy (especially at low bit widths):

```python theme={null}
from r3alai.quant import QuantConfig, Quantizer

result = Quantizer(QuantConfig(mode="qat")).train_qat(
    "model.onnx",
    calibration_data=["/data/img1.jpg", "/data/img2.jpg"],
    output_dir="./qat_out",
    epochs=3,
)
```

See [QAT explained](/concepts/qat).

## 5. Monitor the job

`quantize()` and `train_qat()` block and print live progress. You can also open the platform's **Jobs** page to watch status and progress, and to review past runs. See [Using the platform](/guides/platform).

## 6. Validate locally before shipping

Latency matters on your deployment hardware, so validation runs locally:

```python theme={null}
import numpy as np
from r3alai.quant import Quantizer

# Use an input shape that matches your model (read from ONNX if unsure)
dummy = np.random.randn(1, 3, 224, 224).astype(np.float32)

bench = Quantizer().benchmark(
    original_model="model.onnx",
    quantized_model="./out",
    eval_data=[dummy],
)
print(bench.latency_speedup)
```

See [Benchmarking](/guides/benchmarking) for fidelity checks and how to read the numbers.

## 7. Check the deliverable

```text theme={null}
out/
├── model.quantized.onnx
└── r3alai_manifest.json
```

The manifest records the exact config used. See [Output & manifest](/concepts/manifest).

## Next steps

<CardGroup cols={2}>
  <Card title="Using the platform" icon="cloud" href="/guides/platform">
    Accounts, API keys, the Jobs page, and your plan.
  </Card>

  <Card title="Quantization methods" icon="sliders" href="/concepts/methods">
    Dynamic vs static INT8 or INT4, and when to use QAT.
  </Card>

  <Card title="Calibration" icon="images" href="/concepts/calibration">
    Building a good image set for ptq\_static and QAT.
  </Card>

  <Card title="Python SDK" icon="code" href="/sdk/quantizer">
    The Quantizer facade, PlatformClient, and Job.
  </Card>
</CardGroup>
