-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add dy2static support of LayoutLMv2 SER and LayoutXLM SER #2695
Conversation
@@ -339,7 +339,7 @@ def __init__(self, config): | |||
self.dropout = nn.Dropout(config["attention_probs_dropout_prob"]) | |||
|
|||
def transpose_for_scores(self, x): | |||
new_x_shape = x.shape[:-1] + [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接用paddle.shape是否就ok,避免list
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
使用paddle.shape后使用concat扩充维度会报错,暂时只能这么操作
attention_probs = F.softmax(attention_scores, axis=-1) | ||
# This is actually dropping out entire tokens to attend to, which might | ||
# seem a bit unusual, but is taken from the original Transformer paper. | ||
attention_probs = self.dropout(attention_probs) | ||
context_layer = paddle.matmul(attention_probs, value_layer) | ||
context_layer = context_layer.transpose([0, 2, 1, 3]) | ||
new_context_layer_shape = context_layer.shape[:-2] + [ | ||
new_context_layer_shape = list(context_layer.shape[:-2]) + [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,paddle.shape直接试下?
@@ -335,9 +335,10 @@ def __init__(self, config): | |||
self.dropout = nn.Dropout(config["attention_probs_dropout_prob"]) | |||
|
|||
def transpose_for_scores(self, x): | |||
new_x_shape = x.shape[:-1] + [ | |||
new_x_shape = list(x.shape[:-1]) + [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
attention_scores) | ||
attention_probs = F.softmax(attention_scores, axis=-1) | ||
# This is actually dropping out entire tokens to attend to, which might | ||
# seem a bit unusual, but is taken from the original Transformer paper. | ||
attention_probs = self.dropout(attention_probs) | ||
context_layer = paddle.matmul(attention_probs, value_layer) | ||
context_layer = context_layer.transpose([0, 2, 1, 3]) | ||
new_context_layer_shape = context_layer.shape[:-2] + [ | ||
new_context_layer_shape = list(context_layer.shape[:-2]) + [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
New features
PR changes
Models
Description
add dy2static support of LayoutLMv2 and LayoutxLM
Use the following commands to complete the dynamic and static transformation of the model