是否可以在 pytorch jit 函数中附加到列表?

问题描述 投票:0回答:0

我有一个创建列表并附加到列表中的函数。我想将我的函数转换为 Pytorch jit 函数,以加快计算速度并用我最终将优化的参数填充列表。我不确定列表是否与 Pytorch jit 函数兼容,当我尝试做简单的例子时我遇到了错误。

例如我尝试这样做

import torch

@torch.jit.script
def my_function(x):
    my_list = []
    for i in range(int(x)):
        my_list.append(i)
    return my_list

a = my_function(10)
print(a)

但是我得到了这个错误

aten::append.t(t[](a!) self, t(c -> *) el) -> t[](a!):
Could not match type int to t in argument 'el': Type variable 't' previously matched to type Tensor is matched to type int.
:
  File "myscript.py", line 18
    my_list = []
    for i in range(int(x)):
        my_list.append(i)
        ~~~~~~~~~~~~~~ <--- HERE
    return my_list

这里有什么问题?我不允许在 PyTorch 中使用列表吗?如果不是,我可以用什么其他可附加的对象来替代它与 PyTorch 兼容?

list pytorch jit
© www.soinside.com 2019 - 2024. All rights reserved.