report
report
¶
Post-Training-Quantization report: operator coverage, output divergence, size and timing analysis.
QuantizationReport
¶
QuantizationReport(float_model, quantized_model, example_inputs, action_keys, quantization_workflow=value)
Analyzes a quantized model and generates a report with a comparison against its floating point equivalent.
Initialize with float and quantized models for comparison.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
float_model
|
Module
|
Original float32 model. |
required |
quantized_model
|
Module
|
Quantized model to compare against. |
required |
example_inputs
|
tuple[Tensor, ...]
|
Example inputs for running inference. |
required |
action_keys
|
list[str]
|
Ordered list of action output keys. |
required |
quantization_workflow
|
str
|
QuantizationWorkflow value. PT2E benchmarks with inductor compilation, eager PTQ benchmarks eager execution. |
value
|
Source code in src/versatil/post_training_compression/report.py
compute_operator_coverage
¶
Count quantized vs total operators in the quantized model's FX graph.
Inspects the quantized model's graph nodes for conv2d and linear operations. A node is considered quantized if any of its args references a dequantize operation.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, int]]
|
Dict with keys "conv2d", "linear", each mapping to |
dict[str, dict[str, int]]
|
{"quantized": N, "total": M}. |
Source code in src/versatil/post_training_compression/report.py
compute_output_divergence
¶
Compare float and quantized model outputs.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float]]
|
Dict keyed by action_key, each mapping to |
dict[str, dict[str, float]]
|
{"max_difference": float, "mean_difference": float}. |
Source code in src/versatil/post_training_compression/report.py
compute_size_reduction
¶
Compare model sizes (float32 bytes vs quantized bytes).
Counts parameter and buffer bytes for both models (quantization scales and zero points are stored as buffers).
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dict with "float_bytes", "quantized_bytes", "compression_ratio". |
Source code in src/versatil/post_training_compression/report.py
compute_inference_timing
¶
Compare float vs quantized model inference latency.
For PT2E models, compiles the quantized model with torch.compile(backend="inductor") to match the real inference path. For eager PTQ models, benchmarks eager execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warmup_runs
|
int
|
Number of warmup iterations before timing. |
10
|
benchmark_runs
|
int
|
Number of iterations to time. |
50
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dict with "float_milliseconds", "quantized_milliseconds", |
dict[str, float]
|
"speedup". |
Source code in src/versatil/post_training_compression/report.py
generate_report
¶
Generate human-readable report string.
Returns:
| Type | Description |
|---|---|
str
|
Formatted string containing operator coverage, |
str
|
output divergence, size reduction, and inference timing. |