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
Support T5 Model #794
Conversation
@@ -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) |
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.
上面判断了是否axes为None, 下面又调用了一个可能返回为None的函数,这个需要给一个方案来解决,要么这个函数是否不能返回为None
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.
Done.
之前实现是因为ONNX版本不同判断axes是Node的一个属性还是输入,若是输入再用_const_weight_or_none
获取value
目前修改逻辑,因为paddle.unsqueeze
支持axes
为一个Tensor,所以按如下逻辑判断:
- 若
axes
为一个属性,直接获取属性值 - 若
axes
为一个输入节点,输入该节点的name
从而去掉_const_weight_or_none
函数
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.
目前发现一个问题,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( |
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.
改成isinstance(axes, (list, tuple, np.ndarray))这样会更简洁点
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.
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) |
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.
Done.加入necessary=True
条件
Create A Good Pull Request
Please check the follow step before merging this pull request
If this PR add new model support, please update
model_zoo.md
and add model to out test model zoos(@wjj19950828)Do follow contributes
1、新增op:LessOrEqual
2、修复Unsqueeze、MatMul op:
x_shape
或者y_shape
可能为空导致x_shape[0]报错,增加不为空条件3、重写Gather逻辑,具体如下:
a、首先判断
indices
的shape是否为1D,若为1D,则直接调用paddle.gather
b、若
indices
的shape不为1D:paddle.nn.Embedding
替代gather之前实现gather,当axis>0时会多两个transpose,现在版本则无,如下图:
4、去掉重复
GatherND
代码5、支持HF T5模型