Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing warning emitted from Tensor::scatter_reduce. #846

Open
iago-lito opened this issue Feb 7, 2024 · 0 comments
Open

Confusing warning emitted from Tensor::scatter_reduce. #846

iago-lito opened this issue Feb 7, 2024 · 0 comments

Comments

@iago-lito
Copy link

The following program:

use tch::{Device, Kind, Tensor};

fn main() {
    // Columns of a conceptual (6, 3) sparse matrix.
    let a = Tensor::from_slice(&[7.3, 5.5, 6.1, 3.3]).set_requires_grad(true);
    let b = Tensor::from_slice(&[8.8, 4.6]).set_requires_grad(true);
    let c = Tensor::from_slice(&[4.9, 8.9, 6.7]).set_requires_grad(true);
    // Indices of every columns value.
    let ia = Tensor::from_slice(&[0, 2, 3, 5]);
    let ib = Tensor::from_slice(&[1, 3]);
    let ic = Tensor::from_slice(&[1, 2, 4]);
    let src = Tensor::cat(&[a, b, c], 0);
    let idx = Tensor::cat(&[ia, ib, ic], 0);
    let rowsums =
        Tensor::zeros(6, (Kind::Double, Device::Cpu)).scatter_reduce(0, &idx, &src, "sum");
    println!("rowsums: {rowsums}"); // [7.3, 13.7, 14.4, 10.7, 6.7, 3.3].
} 

yields

Warning: The reduce argument of torch.scatter with Tensor src is deprecated and will be removed in a future PyTorch release. Use torch.scatter_reduce instead for more reduction options. (function operator())

As it turns out, adding the following lines makes it panic:

    let total = rowsums.sum(Kind::Double);
    total.backward();
called `Result::unwrap()` on an `Err` value: Torch("derivative for aten::scatter is not implemented")

I eventually figured that the fix is to replace .scatter_reduce(0, &idx, &src, "sum") by .reduce_add(0, &idx, &src), but the whole process has been rather confusing. What is the actual meaning of the warning I had? Is it actually related to the later panic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant