Libtorch IValue from std::vector<IValue>

What is the expected way to create an IValue with a list of IValues? The C++ constructor expects a c10::List<IVector>, i.e., a (GenericList), but this structure appears to be impossible to construct. Any form of syntax I’ve tried to create one of these list structures fails at compilation with a

static_assert(!std::is_same<T, IValue>::value, "This constructor is not valid for List<IValue>. Please use c10::impl::GenericList(elementType) instead.");

Using the recommended c10::impl implementation does not change anything.

I would expect a constructor for IValue to exist with a std::vector<IValue> signature, which is true for constructing an IValue from a tensor vector of type std::vector<Tensor>.

This question has been asked previously, but nobody seems to know how this structure works

Even basic stack allocations of these list structures fails. Neither of these statements will compile with the same uninformative error.

c10::impl::GenericList inputs;
c10::List<torch::IValue> inputs;


I ran into the same issue when my model expected two lists of strings input via *args.

Using vector<vector> gave me the static assert.

Turned out that the inner list could not simply be vector but needed to be a Generic list which had to be initialized with the type.

In my case I solved it like that:

auto batch_1 = c10::impl::GenericList(c10::StringType::get());
auto batch_2 = c10::impl::GenericList(c10::StringType::get());

model.forward({batch_1, batch_2});

Hope that helps!