flashinfer.fp4_quantization.e2m1_and_ufp8sf_scale_to_float

flashinfer.fp4_quantization.e2m1_and_ufp8sf_scale_to_float(e2m1_tensor: Tensor, ufp8_scale_tensor: Tensor, global_scale_tensor: Tensor | None = None, sf_vec_size: int = 16, ufp8_type: int = 1, is_sf_swizzled_layout: bool = True) Tensor

将 E2M1 格式的张量和 UFP8 比例因子转换为浮点数张量。

此函数通过使用相关的 UFP8 比例因子和全局比例将打包的 FP4 张量(E2M1 格式)转换回浮点数值,从而执行反量化。

参数:
  • e2m1_tensor (torch.Tensor) – 形状为 [M, K/2] 且 dtype 为 uint8 的 E2M1 格式的打包 FP4 张量。

  • ufp8_scale_tensor (torch.Tensor) – dtype 为 uint8 的 UFP8 格式的比例因子张量。

  • global_scale_tensor (torch.Tensor, optional) – 形状为 [1] 且 dtype 为 float32 的全局比例因子。

  • sf_vec_size (int, 可选) – 缩放因子向量大小。默认为 16。

  • ufp8_type (int, optional) – UFP8 比例因子类型(0 表示 UE8M0,1 表示 E4M3)。默认为 1。

  • is_sf_swizzled_layout (bool, optional) – 比例因子是否使用交错布局。默认为 True。

返回值:

形状为 [M, K] 且 dtype 为 float32 的反量化浮点数张量。

返回值类型:

torch.Tensor