Fp4 Quantize#
- void trt_edgellm::kernel::fp4Quantize( )#
Quantize BF16/FP16 to packed FP4 with swizzled FP8 E4M3 scale factors. SM100+: hardware E2M1 conversion. Pre-SM100: software fallback. input shape [M, N]: M must be multiple of 128, N must be multiple of 16. input dataType must be kBF16 or kHALF.
globalSFis the forward-direction activation global scale (e.g.max|x|/(448*6)); the reciprocal consumed by the FP4 mapping is computed inside the kernel via a single IEEE divide per thread.
- void trt_edgellm::kernel::fp4QuantizeLinearSF( )#
Quantize BF16/FP16 to packed FP4 with linear FP8 E4M3 scale factors. input shape [M, N]: N must be multiple of 16. Unlike
fp4Quantize, outputSF is row-major [M, N / 16] because the SM110 TRT-LLM-style FC1 gather kernel loads A scale factors through a linear SFA layout.
- void trt_edgellm::kernel::fp4QuantizeRoutedLinearSF( )#
Quantize FP16/BF16 token rows to routed packed FP4 rows with linear FP8 E4M3 scale factors.
inputis [T, N],topkIdsis [T, topK],expertGlobalSFis [E],outputFP4is [T * topK, N / 2], andoutputSFis row-major [T * topK, N / 16]. Routed rowtoken * topK + slotusesexpertGlobalSF[topkIds[token, slot]].
- void trt_edgellm::kernel::fp4BuildLayoutAndQuantizeRoutedLinearSFDecode(
- rt::Tensor const&,
- rt::Tensor const&,
- rt::Tensor const&,
- MoELayoutBuffers&,
- rt::Tensor&,
- rt::Tensor&,
- int32_t,
- int32_t,
- cudaStream_t,
Decode-specialized setup path for SM110 NVFP4 MoE.
Combines the compact MoE layout build and routed linear-SF FP4 quantization into one CUDA launch. V1 is intended for decode (
input.shape[0] == 1) with small topK, where clearing the full padded layout dominates setup time.