mixle.inference.precision_plan module

Automatic precision allocation from both data and computation.

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, target_rel_error=None, observed_rel_error=None, validation_count=0, context_digest=None, executed_dtype=None, execution_status='not_executed', fallback=None)[source]

Bases: object

A validated precision recommendation, distinct from its eventual execution receipt.

Parameters:
  • compute_dtype (Any)

  • rationale (str)

  • target_rel_error (float | None)

  • observed_rel_error (float | None)

  • validation_count (int)

  • context_digest (str | None)

  • executed_dtype (Any)

  • execution_status (str)

  • fallback (str | None)

reduced()[source]

Return whether the plan uses lower-than-float64 compute precision.

Return type:

bool

record_execution(dtype, *, fallback=None)[source]

Record the dtype that actually entered the execution path.

Parameters:
  • dtype (Any)

  • fallback (str | None)

Return type:

None

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