I saw almost all of the examples in the libtorch tutorial have returned a single Tensor in the forward method.
struct Net : torch::nn::Module {
torch::Tensor forward(torch::Tensor x) {
x = torch::relu(batch_norm1(conv1(x)));
x = torch::relu(batch_norm2(conv2(x)));
x = torch::relu(batch_norm3(conv3(x)));
x = torch::tanh(conv4(x));
return x;
}
}
However, I’m confused about how can we let the forward method return a tuple/pair? I’m currently doing a reinforcement learning task, and I need the network forward method to return both the policy and the position value. How can I translate the following code to C++? Is it possible to do it without the JIT stuff?
def forward(self, state_input):
x = self.common_layer(state_input)
x_action = self.policy_layer(x)
x_value = torch.tanh(self.value_layer(x))
return x_action, x_value
Thanks a lot!