mixle.inference.precision_plan module

Automatic precision allocation – look at the data AND the computation, pick the minimal safe precision.

The control loop that makes “preserve accuracy with minimal compute” the default: a fit samples its data and inspects its model, and where the data is well-conditioned and the model’s leaves are float32-safe it runs the reduced-precision fused kernel; otherwise it stays in float64. Accumulation is ALWAYS float64 (the fused kernels promote the reduction), so the result never drifts regardless of the compute band – the only question this answers is how cheaply each row can be scored. Consulted by optimize(precision="minimal").

This is the data-aware front of the precision spectrum; a per-leaf affine-tracer allocation (different bands for different leaves of one model) is the next refinement on top of this whole-model decision.

class PrecisionPlan(compute_dtype, rationale)[source]

Bases: object

The allocated compute precision and the reason – the audit trail of the auto-allocation.

Parameters:
  • compute_dtype (Any)

  • rationale (str)

compute_dtype: Any
rationale: str
reduced()[source]
Return type:

bool

recommend_compute_precision(model, data, target_rel_error=1e-4, sample_size=4096, min_variance=1e-6, max_magnitude=1e6)[source]

Return the minimal SAFE compute precision (float32 or float64) for fitting model on data.

float32 is chosen only when ALL hold: (1) the model fuses (has a reduced-precision kernel), (2) every leaf family is float32-safe, (3) no leaf is near-degenerate (variance >= min_variance), and (4) the data magnitude is bounded (|x| <= max_magnitude, so (x-mu)**2 neither overflows nor loses the score’s relative precision) – the regime where the fused float32 summed-LL error is verified < ~1e-6. Otherwise float64. (Wide dynamic range is not a risk: floating point keeps ~7 relative digits at any magnitude; only the absolute magnitude and the variance condition the score.)

Parameters:
Return type:

PrecisionPlan