cyx-6 commented on code in PR #14907:
URL: https://github.com/apache/tvm/pull/14907#discussion_r1202836964
##########
python/tvm/relax/op/nn/nn.py:
##########
@@ -1035,13 +1036,32 @@ def attention(
a 4-D tensor ending with seq_len_kv, and broadcastable to
(batch_size, num_head, seq_len, seq_len_kv).
- scale: Optional[FloatImm]
- The custom scale applied before the softmax. The default value is 1 /
sqrt(head_dim).
+ causal_mask: Optional[str]
+ The optional causal mask, i.e. 'TopLeft' and 'BottomRight'.
+ For example, with seq_len = 4, seq_len_kv = 2,
+ mask for 'TopLeft':
+ [[1, 0],
+ [1, 1],
+ [1, 1],
+ [1, 1]]
+ mask for 'BottomRight':
+ [[1, 1],
+ [1, 1],
+ [1, 1],
+ [1, 1]]
Review Comment:
sure, I have added the detailed mask definition in the docs.
##########
python/tvm/relax/frontend/torch/fx_translator.py:
##########
@@ -1015,19 +1015,24 @@ def _cross_entropy(self, node: fx.node.Node) ->
relax.Expr:
)
def _scaled_dot_product_attention(self, node: fx.node.Node) -> relax.Var:
- assert len(node.args) <= 4, "Dropout, and causal masking are not
supported."
+ assert (
+ len(node.args) <= 4
+ ), "Dropout is not supported, and is_causal should be called by
kwargs."
transpose_S_H = lambda tensor: relax.op.permute_dims(tensor, [0, 2, 1,
3])
query = transpose_S_H(self.env[node.args[0]])
key = transpose_S_H(self.env[node.args[1]])
value = transpose_S_H(self.env[node.args[2]])
+ causal_mask = (
+ "TopLeft" if "is_causal" in node.kwargs and
node.kwargs["is_causal"] is True else None
Review Comment:
yes, I have updated the code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]