

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# Support FlashAttention
<a name="model-parallel-attention-head-size-for-flash-attention"></a>

Suppor FlashAttention t for 是该库的一项功能，仅适用于*分布式变压器模型，分布式变压器*模型是为模型并行训练而封装的 Trans [https://sagemaker.readthedocs.io/en/v2.199.0/api/training/smp_versions/latest/smd_model_parallel_pytorch.html#smdistributed-modelparallel-torch-distributedmodel](https://sagemaker.readthedocs.io/en/v2.199.0/api/training/smp_versions/latest/smd_model_parallel_pytorch.html#smdistributed-modelparallel-torch-distributedmodel)former 模型。此功能还与 [张量并行性](model-parallel-extended-features-pytorch-tensor-parallelism.md) 兼容。

该[FlashAttention](https://github.com/HazyResearch/flash-attention)库仅在设置`attention_head_size`为 8 的倍数且小于 128 的值时才支持模型。因此，在训练分布式变压器并确保其 FlashAttention 正常工作时，应调整参数以使注意力头大小符合要求。有关更多信息，另请参阅*FlashAttention GitHub存储库*中的[安装和功能](https://github.com/HazyResearch/flash-attention#installation-and-features)。

例如，假设您使用 `hidden_width=864` 和 `num_heads=48` 配置转换器模型。的头部大小计算公式 FlashAttention 为`attention_head_size = hidden_width / num_heads = 864 / 48 = 18`。要启用 FlashAttention，您需要将`num_heads`参数调整为 `54``attention_head_size = hidden_width / num_heads = 864 / 54 = 16`，即 8 的倍数。