Skip to content

output with shape [] doesn't match the broadcast shape [1] error in Tensor::backward() call with LibTorch backend #1816

Closed Answered by femshima
femshima asked this question in Q&A
Discussion options

You must be logged in to vote

Changing

    let intersection: Tensor<B, 1> = (x.clone() * targets.clone()).sum();
    let dice: Tensor<B, 1> = (intersection * 2.0 + 1) / ((x.clone()).sum() + (targets.clone()).sum() + 1);

to

    let intersection: Tensor<B, 1> = (x.clone() * targets.clone()).sum();
    let dice: Tensor<B, 1> = (intersection * 2.0 + 1).reshape([1])
        / ((x.clone()).sum() + (targets.clone()).sum() + 1).reshape([1]);

fixed the issue.

It seems that sum() returns 0-dimension tensor, which results in a dimension mismatch in
https://github.com/tracel-ai/burn/blob/v0.13.2/crates/burn-autodiff/src/ops/tensor.rs#L393.

Maybe related to #1689.

As I found the workaround, I will close discussion.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@femshima
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by femshima
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants