LayerPrecisionPolicy

Models & Types ยท AiDotNet.MixedPrecision

Defines precision policies for different layer types during mixed-precision training.

For Beginners

Not all layers behave well in low precision. This class helps you configure which layers should stay in higher precision (FP32 or FP16) even when using mixed-precision training.

How It Works

Why Some Layers Need Higher Precision:

Constructors

Constructor Summary
LayerPrecisionPolicy(MixedPrecisionType defaultPrecision) Creates a new layer precision policy with the specified default precision.

Properties

Property Summary
MixedPrecisionType DefaultPrecision { get; } Gets the default precision for layers not matching any rule.

Methods

Method Summary
IReadOnlyList<string> GetExcludedPatterns(MixedPrecisionType minimumPrecision) Gets all layer patterns that should be excluded from a given precision level.
LayerPrecisionPolicy AddPattern(string pattern, MixedPrecisionType precision) Adds a pattern-based precision rule.
LayerPrecisionPolicy ForBF16() Creates the default policy for BF16 mixed-precision training.
LayerPrecisionPolicy ForFP16() Creates the default policy for FP16 mixed-precision training.
LayerPrecisionPolicy ForFP8() Creates the default policy for FP8 mixed-precision training.
LayerPrecisionPolicy ForFP8ConvNets() Creates a policy for convolutional networks with FP8.
LayerPrecisionPolicy ForFP8Transformers() Creates a policy for transformer models with FP8.
LayerPrecisionPolicy ForPrecision(MixedPrecisionType precisionType) Creates the default policy for a precision type โ€” the one you want when the config names a precision and you have no reason to override which layers stay in FP32.
LayerPrecisionPolicy FullPrecision() Creates a fully FP32 policy (no mixed precision).
LayerPrecisionPolicy KeepInFP16(string pattern) Keeps layers matching the pattern in FP16 (useful when default is FP8).
LayerPrecisionPolicy KeepInFP32(string pattern) Keeps layers matching the pattern in full precision (FP32).
LayerPrecisionPolicy SetPrecision(string layerName, MixedPrecisionType precision) Sets the precision for a specific layer by exact name.
MixedPrecisionType GetPrecision(string layerName) Gets the precision to use for a layer with the given name.
bool ShouldSkipMixedPrecision(string layerName) Determines if a layer should skip mixed precision entirely (stay in FP32).
bool ShouldUseHigherPrecision(string layerName) Determines if a layer should be kept in higher precision (FP32 or FP16).
string ToString()