Error while using Functional Module in PyTorch C++

I’m facing the following error while trying to reproduce results from PyTorch Official Examples.

The error seems to be at the line: push_back(Functional(torch::log_softmax, 1, torch::nullopt));.

Things I’ve changed: I’m using my own Dataset class and dataset. The network is exactly the same.

no matching function for call to ‘torch::nn::Functional::Functional(<unresolved overloaded function type>, int, const c10::nullopt_t&)’
     push_back(Functional(torch::log_softmax, 1, torch::nullopt));

Any idea why this could happen?

One thing to keep in mind is that you likely need to use a very new version of PyTorch (i.e. compiled from the master git branch or nightly releases).
The example you linked was added just a week ago, so it might need features from very recent PyTorch. The background is that some bits of the C++ API still have some catch-up to do to achieve parity with “classic” PyTorch.

Best regards

Thomas

In such a case a static cast to the right variant of the overloaded function works, you can try something like

torch::nn::Functional(static_cast<torch::Tensor(*)(const torch::Tensor &, int64_t)>(torch::log_softmax), 0)
1 Like