Skip to content
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

Support T5 Model #794

Merged
merged 19 commits into from May 25, 2022
Merged

Support T5 Model #794

merged 19 commits into from May 25, 2022

Conversation

wjj19950828
Copy link
Collaborator

@wjj19950828 wjj19950828 commented May 11, 2022

Create A Good Pull Request

下面的文字请保留在PR说明的最后面,并在提完PR后,根据实际情况勾选确认以下情况

Please check the follow step before merging this pull request

  • Python code style verification
  • Review all the code diff by yourself
  • All models(TensorFLow/Caffe/ONNX/PyTorch) testing passed
  • Details about your pull request, releated issues

If this PR add new model support, please update model_zoo.md and add model to out test model zoos(@wjj19950828)

  • New Model Supported
  • No New Model Supported

Do follow contributes

1、新增op:LessOrEqual
2、修复Unsqueeze、MatMul op:

  • Unsqueeze为之前的条件判断:axes为一个node,需获取node里的value才能进行判断
  • MatMul为x_shape或者y_shape可能为空导致x_shape[0]报错,增加不为空条件

3、重写Gather逻辑,具体如下:
a、首先判断indices的shape是否为1D,若为1D,则直接调用paddle.gather
b、若indices的shape不为1D:

  • axis为0且输入类型为DataNode,用paddle.nn.Embedding替代gather
  • 其他情况则将indice的shape变成1D,gather之后再reshape回对应大小(若shape获取不到,则用shape_tensor + slice解决)

之前实现gather,当axis>0时会多两个transpose,现在版本则无,如下图:
image

4、去掉重复GatherND代码
5、支持HF T5模型

@@ -741,6 +742,7 @@ def Unsqueeze(self, node):
axes = node.get_attr('axes')
if axes is None:
axes = self.graph.get_input_node(node, idx=1, copy=True)
axes = _const_weight_or_none(axes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上面判断了是否axes为None, 下面又调用了一个可能返回为None的函数,这个需要给一个方案来解决,要么这个函数是否不能返回为None

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.
之前实现是因为ONNX版本不同判断axes是Node的一个属性还是输入,若是输入再用_const_weight_or_none获取value

目前修改逻辑,因为paddle.unsqueeze支持axes为一个Tensor,所以按如下逻辑判断:

  • axes为一个属性,直接获取属性值
  • axes为一个输入节点,输入该节点的name

从而去掉_const_weight_or_none 函数

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前发现一个问题,unsqueeze输入可能有scalar tensor(ONNX支持但Paddle不支持),为解决此问题,还是需要使用_const_weight_or_none 去判断,加入necessary=True条件

  • 若输入shape为空,且axes值为0,使用paddle.reshape替代
  • 否则,使用paddle.unsqueeze

@@ -749,7 +751,8 @@ def Unsqueeze(self, node):
outputs=[node.name],
shape=[1])
else:
if isinstance(axes, list) or isinstance(axes, tuple):
if isinstance(axes, list) or isinstance(axes, tuple) or isinstance(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成isinstance(axes, (list, tuple, np.ndarray))这样会更简洁点

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.重新实现逻辑无此判断条件

@@ -893,72 +896,24 @@ def GatherND(self, node):
def Gather(self, node):
val_x = self.graph.get_input_node(node, idx=0, copy=True)
indices = self.graph.get_input_node(node, idx=1, copy=True)
indices_values = _const_weight_or_none(indices)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.加入necessary=True条件

@wjj19950828 wjj19950828 merged commit e85f692 into PaddlePaddle:develop May 25, 2022
@wjj19950828 wjj19950828 deleted the ONNX_for_HF branch May 25, 2022 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants