Created by: Aurelius84
PR types
New features
PR changes
APIs
Describe
support usage: to_static(model)
Code Example:
Before this PR,if we want decorate a forward()
from model, we shall write code like(not decorator mode):
model.forward = to_static(model.forward, input_spec=...)
It's not easy-to-use. In this PR,we support decorate model directly and convert call for foward
and all inner function.
class SimpleNet(Layer):
def __init__(self, ...):
.......
def forward(self, x):
......
return out
net = SimpleNet()
x = paddle.to_tensor(np.ones(4, 10))
# case 1: decorate model and feed data
net = to_static(net)
out = net(x)
print(out)
# case 2: decorate model with InputSpec
net = to_static(net, input_spec=[InputSpec([None, 8, 10])])
self.assertListEqual(list(input_shape), [-1, 8, 10])
# case 3: redecorate with new InputSpec
net = declarative(net, input_spec=[InputSpec([None, 16, 10])])
input_shape = net.forward.inputs[0].shape
self.assertListEqual(list(input_shape), [-1, 16, 10])