conflicts about the description of "input_spec" argument of paddle.jit.to_static() on official documentation

ijnw1ujt  于 2022-11-19  发布在  其他
关注(0)|答案(4)|浏览(107)

(4)方式四:指定非 Tensor 参数类型
says:
net = to_static(input_spec=[InputSpec(shape=[None, 10], name='x'), True])

which has a conflict with 目前仅支持指定 Tensor 类型信息,非 Tensor 类型信息均使用 函数定义的默认值

请提出你的建议 Please give your suggestion

I don't know the implementation of paddle.jit.to_static , so I don't known what to suggest.
Please refer to this :
#45485

6bc51xsx

6bc51xsx1#

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看 官网API文档常见问题历史IssueAI社区 来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

u4vypkhs

u4vypkhs2#

import paddle
from paddle.jit import to_static
from paddle.nn import Layer
from paddle.static import InputSpec

class SimpleNet(Layer):
    def __init__(self, ):
        super(SimpleNet, self).__init__()
        self.linear = paddle.nn.Linear(10, 3)
        self.relu = paddle.nn.ReLU()

    def forward(self, x, use_act=False):
        out = self.linear(x)
        if use_act:
            out = self.relu(out)
        return out

net = SimpleNet()
# 方式一:save inference model with use_act=False
net = to_static(net, input_spec=[InputSpec(shape=[None, 10], name='x')])
paddle.jit.save(net, path='./simple_net')

# 方式二:save inference model with use_act=True
net = to_static(net, input_spec=[InputSpec(shape=[None, 10], name='x'), True])
paddle.jit.save(net, path='./simple_net')
n3ipq98p

n3ipq98p3#

The above code can work, thus shows that input_spec can be used to specify non-Tensor arguments in the forward method.

3j86kqsm

3j86kqsm4#

收到你的反馈,我们更新一下

相关问题