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

[ BugFix ] convert call: tranform the static func. #46278

Merged

Conversation

2742195759
Copy link
Contributor

@2742195759 2742195759 commented Sep 20, 2022

PR types

Bug fixes

PR changes

Others

Describe

fix bug in convert call: tranform the static func.
解决了同一个Layer示例,多次forward的问题,之前会导致对StaticFunction进行动转静,会导致错误。
例如下面的代码:

import paddle                                                                                                                                                                                                       

class SimpleNet(paddle.nn.Layer):                 
    def __init__(self):
        super(SimpleNet, self).__init__()

    def forward(self, x):
        a = [1]
        if True: 
            a.append(1)
        if True: 
            a.append(2)
        return a if True else 1 

snet = SimpleNet()
def vlist_of_dict(x):
    a = snet(paddle.ones([1,1]))
    a = snet(paddle.ones([2,2]))
    return a 

b = paddle.to_tensor([True, False, True])
x = paddle.to_tensor([3])
z = paddle.to_tensor([6])
y = paddle.rand((100, 2, 2))

#print(paddle.jit.to_static(vlist_of_dict).code)
print(paddle.jit.to_static(vlist_of_dict)(x))

第二次会对动转静之后的代码在进行动转静。添加了一个额外的字段,表示已经被转写过,如果转写过就直接return。

这里注意两个case:同一个Layer实例的多次forward,同一个Layer多个实例的多次forward

@2742195759 2742195759 changed the title fix bug in convert call: tranform the static func. [ BugFix ] convert call: tranform the static func. Sep 20, 2022
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.

2 participants