Class Fp8KvCodec
java.lang.Object
smile.llm.quant.Fp8KvCodec
Helpers for FP8 KV store/load with per-tensor scales.
Used by KvCachePool when
smile.chat.kv-cache.dtype is FP8. Ampere stores FP8 and dequants to
BF16/FP16 for attention compute; Hopper may later use native FlashInfer FP8.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatMax finite magnitude for Float8 e4m3fn. -
Method Summary
Modifier and TypeMethodDescriptionstatic floatcomputeScale(Tensor x, float fp8Max) Computes a positive float scale soabs(x)/scale <= fp8Max.static Tensordequantize(Tensor q, float scale, ScalarType outDtype) Dequantizes FP8qwithscaletooutDtype.static booleanisFp8(ScalarType dtype) Returnstruewhendtypeis an FP8 scalar type.static Tensorquantize(Tensor x, float scale, ScalarType fp8Dtype) Quantizesxto FP8 usingscale(x_fp8 ≈ x / scale).
-
Field Details
-
E4M3_MAX
public static final float E4M3_MAXMax finite magnitude for Float8 e4m3fn.- See Also:
-
-
Method Details
-
isFp8
Returnstruewhendtypeis an FP8 scalar type.- Parameters:
dtype- scalar type to test.- Returns:
truewhendtypeis FP8.
-
computeScale
Computes a positive float scale soabs(x)/scale <= fp8Max.- Parameters:
x- tensor to measure.fp8Max- max finite FP8 magnitude.- Returns:
- positive scale for quantization.
-
quantize
Quantizesxto FP8 usingscale(x_fp8 ≈ x / scale).- Parameters:
x- source tensor.scale- positive float scale.fp8Dtype- target FP8 dtype.- Returns:
- quantized FP8 tensor (caller owns).
-
dequantize
Dequantizes FP8qwithscaletooutDtype.- Parameters:
q- FP8 tensor.scale- positive float scale.outDtype- output compute dtype.- Returns:
- dequantized tensor (caller owns).
-