Module Ocannl.Precision_policy

module Tn = Ir.Tnode
module Ops = Ir.Ops
module Tensor = Ocannl_tensor.Tensor

Precision-assignment policy over a model (gh-ocannl-492 task 1): assigns storage precisions across a tensor graph instead of the user hand-annotating every tensor. This is the storage-precision sibling of the compute-precision policy in Ir.Numerics — the two are the "one roof" gh-ocannl-478 asks for.

Semantics of apply:

Call apply after the model (and its gradient graph, if any) is fully constructed and before the first compilation: assignments to already-settled nodes fail loudly (the settlement guards in Tn.update_prec), and op construction after apply would infer from pre-policy precisions.

fp8 note (gh-ocannl-481): the codomain is Ops.prec, so when a second fp8 format (e4m3) lands as a precision, per-class fp8 assignment (e4m3 weights/activations, e5m2 gradients) is expressible here without interface changes.

type t = {
  1. param_prec : Ops.prec Base.option;
    (*

    For values of trainable leaves (root.params).

    *)
  2. activation_prec : Ops.prec Base.option;
    (*

    For values of every non-param tensor: op results, inputs, unannotated constants.

    *)
  3. grad_prec : Ops.prec Base.option;
    (*

    For gradient nodes (of params and intermediates alike).

    *)
}
val uniform : Ops.prec -> t

The same precision for all three classes — the "full bf16 / full f16" styles. Mixed styles (e.g. reduced compute with grad_prec = Some Ops.single) are record literals away.

val apply : ?except:(Tn.t -> bool) -> t -> Tensor.t -> unit