未验证 提交 11c2874e 编写于 作者: L Li Min 提交者: GitHub

[fix-doc-bug] Fix fused_attention_op english doc test=document_fix (#36803)

* Fix fused_attention english doc test=document_fix
上级 54ef9d06
...@@ -194,24 +194,27 @@ def fused_multi_head_attention(x, ...@@ -194,24 +194,27 @@ def fused_multi_head_attention(x,
Multi-Head Attention performs multiple parallel attention to jointly attending Multi-Head Attention performs multiple parallel attention to jointly attending
to information from different representation subspaces. This API only to information from different representation subspaces. This API only
support self_attention. The pseudo code is as follows: support self_attention. The pseudo code is as follows:
if pre_layer_norm:
out = layer_norm(x); .. code-block:: python
out = linear(out) + qkv)bias
else: if pre_layer_norm:
out = linear(x) + bias; out = layer_norm(x)
out = transpose(out, perm=[2, 0, 3, 1, 4]); out = linear(out) + qkv) + bias
# extract q, k and v from out. else:
q = out[0:1,::] out = linear(x) + bias
k = out[1:2,::] out = transpose(out, perm=[2, 0, 3, 1, 4])
v = out[2:3,::] # extract q, k and v from out.
out = q * k^t; q = out[0:1,::]
out = attn_mask + out; k = out[1:2,::]
out = softmax(out); v = out[2:3,::]
out = dropout(out); out = q * k^t
out = out * v; out = attn_mask + out
out = transpose(out, perm=[0, 2, 1, 3]); out = softmax(out)
out = out_linear(out); out = dropout(out)
out = layer_norm(x + dropout(linear_bias + out)); out = out * v
out = transpose(out, perm=[0, 2, 1, 3])
out = out_linear(out)
out = layer_norm(x + dropout(linear_bias + out))
Parameters: Parameters:
x (Tensor): The input tensor of fused_multi_head_attention. The shape is x (Tensor): The input tensor of fused_multi_head_attention. The shape is
...@@ -245,6 +248,9 @@ def fused_multi_head_attention(x, ...@@ -245,6 +248,9 @@ def fused_multi_head_attention(x,
ln_epsilon (float, optional): Small float value added to denominator of layer_norm ln_epsilon (float, optional): Small float value added to denominator of layer_norm
to avoid dividing by zero. Default is 1e-5. to avoid dividing by zero. Default is 1e-5.
Returns:
Tensor: The output Tensor, the data type and shape is same as `x`.
Examples: Examples:
.. code-block:: python .. code-block:: python
......
...@@ -24,11 +24,12 @@ import collections ...@@ -24,11 +24,12 @@ import collections
class FusedMultiHeadAttention(Layer): class FusedMultiHeadAttention(Layer):
""" """
Attention mapps queries and a set of key-value pairs to outputs, and Attention mapps queries and a set of key-value pairs to outputs, and
Multi-Head Attention performs multiple parallel attention to jointly attending Multi-Head Attention performs multiple parallel attention to jointly attending
to information from different representation subspaces. to information from different representation subspaces.
Please refer to `Attention Is All You Need <https://arxiv.org/pdf/1706.03762.pdf>`_ Please refer to `Attention Is All You Need <https://arxiv.org/pdf/1706.03762.pdf>`_
for more details. for more details.
Parameters: Parameters:
embed_dim (int): The expected feature size in the input and output. embed_dim (int): The expected feature size in the input and output.
num_heads (int): The number of heads in multi-head attention. num_heads (int): The number of heads in multi-head attention.
...@@ -42,17 +43,18 @@ class FusedMultiHeadAttention(Layer): ...@@ -42,17 +43,18 @@ class FusedMultiHeadAttention(Layer):
`embed_dim`. Default None. `embed_dim`. Default None.
vdim (int, optional): The feature size in value. If None, assumed equal to vdim (int, optional): The feature size in value. If None, assumed equal to
`embed_dim`. Default None. `embed_dim`. Default None.
normalize_before (bool, optional): Indicate whether it is pre_layer_norm (True) normalize_before (bool, optional): Indicate whether it is pre_layer_norm
or post_layer_norm architecture (False). Default False. (True) or post_layer_norm architecture (False). Default False.
need_weights (bool, optional): Indicate whether to return the attention need_weights (bool, optional): Indicate whether to return the attention
weights. Now, only False is supported. Default False. weights. Now, only False is supported. Default False.
weight_attr(ParamAttr, optional): To specify the weight parameter property. weight_attr(ParamAttr, optional): To specify the weight parameter property.
Default: None, which means the default weight parameter property is used. Default: None, which means the default weight parameter property is used.
See usage for details in :code:`ParamAttr` . See usage for details in :code:`ParamAttr`.
bias_attr (ParamAttr|bool, optional): To specify the bias parameter property. bias_attr (ParamAttr|bool, optional): To specify the bias parameter property.
Default: None, which means the default bias parameter property is used. Default: None, which means the default bias parameter property is used.
If it is set to False, this layer will not have trainable bias parameter. If it is set to False, this layer will not have trainable bias parameter.
See usage for details in :code:`ParamAttr` . See usage for details in :code:`ParamAttr`.
Examples: Examples:
.. code-block:: python .. code-block:: python
...@@ -139,6 +141,7 @@ class FusedMultiHeadAttention(Layer): ...@@ -139,6 +141,7 @@ class FusedMultiHeadAttention(Layer):
""" """
Applies multi-head attention to map queries and a set of key-value pairs Applies multi-head attention to map queries and a set of key-value pairs
to outputs. to outputs.
Parameters: Parameters:
query (Tensor): The queries for multi-head attention. It is a query (Tensor): The queries for multi-head attention. It is a
tensor with shape `[batch_size, query_length, embed_dim]`. The tensor with shape `[batch_size, query_length, embed_dim]`. The
...@@ -163,6 +166,7 @@ class FusedMultiHeadAttention(Layer): ...@@ -163,6 +166,7 @@ class FusedMultiHeadAttention(Layer):
nothing wanted or needed to be prevented attention to. Default None. nothing wanted or needed to be prevented attention to. Default None.
cache (MultiHeadAttention.Cache|MultiHeadAttention.StaticCache, optional): cache (MultiHeadAttention.Cache|MultiHeadAttention.StaticCache, optional):
Now, only None is supported. Default None. Now, only None is supported. Default None.
Returns: Returns:
Tensor|tuple: It is a tensor that has the same shape and data type \ Tensor|tuple: It is a tensor that has the same shape and data type \
as `query`, representing attention output. as `query`, representing attention output.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册