recipe.h

处理 FP8 配方的函数。

函数

void nvte_delayed_scaling_recipe_amax_and_scale_update(const NVTETensor amax_history, const NVTETensor scale, NVTETensor updated_amax_history, NVTETensor updated_scale, const char *amax_compute_algo, NVTEDType fp8_dtype, float margin, cudaStream_t stream)

使用延迟缩放配方更新 FP8 缩放因子。

amax 历史记录轮换 -1(例如,第一个条目移至最后一个,最后一个条目移至倒数第二个),并且第一个条目设置为零。估计缩放因子,使得 FP8 张量的最大绝对值为 \( 2^{-\text{margin}} \text{max}_\text{fp8\_dtype} \)

参数:
  • amax_history[in] 最大绝对值的历史记录。形状:[history_length, num_scales]

  • scale[in] 转换为 FP8 的缩放因子。形状:[num_scales]

  • updated_amax_history[out] 更新后的最大绝对值历史记录。形状:[history_length, num_scales]

  • updated_scale[out] 更新后的转换为 FP8 的缩放因子。形状:[num_scales]

  • amax_compute_algo[in] 减少 amax 历史记录的方法。选项为 “max” 和 “most_recent”。

  • fp8_dtype[in] FP8 数据类型。

  • margin[in] 缩放因子边距。

  • stream[in] CUDA 流。

void nvte_delayed_scaling_recipe_amax_and_scale_update_after_reduction(const NVTETensor amax_reduction_buffer, std::vector<NVTETensor> amax_histories, std::vector<NVTETensor> scales, const char *amax_compute_algo, NVTEDType fp8_dtype, float margin, cudaStream_t stream)

在 amax 归约后,使用延迟缩放配方批量更新 FP8 缩放因子。

执行的操作包括:如果全局归约缓冲区的相关段不为 0,则使用该段更新最新的 amax 历史记录;根据以下规则轮换 amax 历史记录;以及更新缩放比例。

amax 历史记录轮换 -1(例如,第一个条目移至最后一个,最后一个条目移至倒数第二个),并且第一个条目设置为零。估计缩放因子,使得 FP8 张量的最大绝对值为 \( 2^{-\text{margin}} \text{max}_\text{fp8\_dtype} \)

参数:
  • amax_reduction_buffer[in] 用于 amax 归约的连续缓冲区。形状:[num_scales * num_tensors]

  • amax_histories[inout] 最大绝对值的 amax 历史记录列表。形状:num_tensors x [history_length, num_scales]

  • scales[inout] 转换为 FP8 的缩放因子列表。形状:num_tensors x [num_scales]

  • amax_compute_algo[in] 减少 amax 历史记录的方法。选项为 “max” 和 “most_recent”。

  • fp8_dtype[in] FP8 数据类型。

  • margin[in] 缩放因子边距。

  • stream[in] CUDA 流。