I have an identical issue: a function which uses autograd works when called directly, but throws the “element 0 of tensors…” error when called from the forward pass of a custom autograd.Function. The code worked in version 0.3 but no longer works in 0.4. Is there any update on this?