Custom cpp pass by reference

When we use pybind11 for example to forward using:

std::vector<at::Tensor> lltm_forward(
    at::Tensor input,
    at::Tensor weights,
    at::Tensor bias,
    at::Tensor old_h,
    at::Tensor old_cell) {

Are tensors passed by reference, or by value? Can I modify them?

As far as I know, at::Tensors are always passed by reference.
If you would like to get a copy, you can call clone() inside your method.

1 Like