Mojo function
compute_dynamic_fp8_scale
compute_dynamic_fp8_scale[out_dtype: DType](row_max: Scalar[dtype], scale_ub: Scalar[dtype]) -> Tuple[Scalar[dtype], Scalar[dtype]]
Compute dynamic FP8 scale factor and its reciprocal from a row max.
Computes scale_factor = min(row_max, scale_ub) / fp8_max and its reciprocal.
Does not use math.recip to avoid a reciprocal approximation that gives up
too much precision.
Parameters:
- โout_dtype (
DType): The FP8 output dtype (float8_e4m3fn or float8_e4m3fnuz).
Args:
- โrow_max (
Scalar): Maximum absolute value across the row/group. - โscale_ub (
Scalar): Upper bound to clamp the scale factor.
Returns:
Tuple: A tuple of (scale_factor, scale_factor_recip).
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!