Skip to main content

engine.accuracy_curve

engine.accuracy_curve

Measured accuracy curves for compression (opt-in).

CompressionModel invents no synthetic accuracy curve: it defaults accuracy_delta to 0.0 unless the caller supplies empirical quality data. Measured cost depends on the model, the method, the calibration or retraining recipe, and the task. An AccuracyCurve records what one experiment measured across several compression levels, so a caller can pass it to CompressionModel when evaluating or sweeping operating points.

A curve is tied to one model, one method, one metric, and one dataset. It is a list of measured operating points, each a compression level and the accuracy measured there, plus the accuracy of the uncompressed model in the same harness. Between two adjacent measured points the curve interpolates linearly. Outside the measured range it refuses to answer, because measured curves are often flat and then fall sharply, and the position of the fall differs from model to model.

Nothing here changes a default. CompressionModel uses a curve only when a caller passes one.

Classes

Name Description
AccuracyCurve Accuracy of one model, measured at several compression levels.

AccuracyCurve

engine.accuracy_curve.AccuracyCurve()

Accuracy of one model, measured at several compression levels.

Attributes

Name Type Description
name str Short identifier, shown in solver traces.
axis {'bitwidth', 'sparsity'} What the compression level counts. "bitwidth" is bits per weight after quantization. "sparsity" is the fraction of weights removed.
measured_model str The model and weights that were measured.
method str The compression method as run, including granularity and calibration (for example “round-to-nearest, per-channel, weights only”).
metric str The accuracy metric, which must be a fraction where higher is better.
dataset str The evaluation data.
retrained bool Whether the weights were trained or fine-tuned during or after compression.
baseline_accuracy float Accuracy of the uncompressed model in the same harness, in (0, 1].
points tuple of (float, float) Measured operating points as (compression level, accuracy), with accuracy in [0, 1]. Levels must be distinct. They are stored sorted.
provenance Provenance Where the measurements come from.

Notes

Perplexity and other lower-is-better metrics are outside this type. The solver reports an accuracy change in percentage points, and a perplexity difference is not one.

Methods

Name Description
accuracy_at Return the accuracy at one compression level.
delta_at Return the accuracy change from the uncompressed model.
is_measured Return whether level is one of the measured points.
accuracy_at
engine.accuracy_curve.AccuracyCurve.accuracy_at(level)

Return the accuracy at one compression level.

Parameters
Name Type Description Default
level float Compression level in the units of axis: bits per weight for a bitwidth curve, fraction of weights removed for a sparsity curve. required
Returns
Name Type Description
float Accuracy as a fraction. It is the measured value at a measured point, and a linear interpolation between the two adjacent measured points otherwise.
Raises
Name Type Description
ValueError If level is not finite or is outside the measured range. The curve does not extrapolate.
Notes

Equation: for adjacent measured points (x0, a0) and (x1, a1) with x0 <= level <= x1, accuracy = a0 + (a1 - a0) * (level - x0) / (x1 - x0).

Assumptions: accuracy changes linearly between two adjacent measured points. A sharp fall can happen anywhere between two points, so measure closely spaced points where accuracy changes quickly.

Excludes: extrapolation, uncertainty of the measured points, and any check that the curve was measured on the model being analyzed.

Examples
>>> from mlsysim.engine.accuracy_curve import shipped_curve
>>> curve = shipped_curve("qwen-7b-chat-gptq")
>>> curve.accuracy_at(4)
0.5486
delta_at
engine.accuracy_curve.AccuracyCurve.delta_at(level)

Return the accuracy change from the uncompressed model.

Parameters
Name Type Description Default
level float Compression level in the units of axis. required
Returns
Name Type Description
float Signed change as a fraction, so -0.005 is 0.5 percentage points below the uncompressed model. This is the convention of CompressionResult.estimated_accuracy_delta.
Notes

Equation: delta = accuracy_at(level) - baseline_accuracy.

Assumptions: the baseline was measured in the same harness, on the same data, as every point.

Excludes: relative accuracy (the ratio to the baseline), which some benchmarks use for their quality targets.

Examples
>>> from mlsysim.engine.accuracy_curve import shipped_curve
>>> round(shipped_curve("qwen-7b-chat-gptq").delta_at(4), 4)
-0.0224
is_measured
engine.accuracy_curve.AccuracyCurve.is_measured(level)

Return whether level is one of the measured points.

Parameters
Name Type Description Default
level float Compression level in the units of axis. required
Returns
Name Type Description
bool True when a measured point has this level.

Functions

Name Description
shipped_curve Return one of the example curves that ship with the package.
shipped_curve_names Return the names of the example curves that ship with the package.

shipped_curve

engine.accuracy_curve.shipped_curve(name)

Return one of the example curves that ship with the package.

Parameters

Name Type Description Default
name str One of shipped_curve_names(). required

Returns

Name Type Description
AccuracyCurve The curve, with its provenance. Each one describes the model, method and data it was measured on. It is an example of the format, and it says nothing about any other model or method.

Examples

>>> from mlsysim.engine.accuracy_curve import shipped_curve
>>> shipped_curve("qwen-7b-chat-gptq").axis
'bitwidth'

shipped_curve_names

engine.accuracy_curve.shipped_curve_names()

Return the names of the example curves that ship with the package.

Returns

Name Type Description
tuple of str Names accepted by shipped_curve, in file order.
Back to top