Closed wpalfi closed 3 years ago
Btw. many many thanks, I really love your library! It is incredibly fast:+1:.
Hi @wpalfi, thanks for the report and feedback! The root cause of the issue is attempting to fetch from a cube map using all-zero texture coordinates in the background pixels. The zero vector cannot be projected onto the cube surface, and nvdiffrast doesn't currently handle this in any smart fashion and divides by zero internally. This leads to fetching from an arbitrary texel in the forward pass and producing NaNs in the backward pass.
The attached zip below has a modified version of nvdiffrast/common/texture.cu
where these issues are remedied. Cube map uvs that cause internal overflows or NaNs now always output a zero result in the forward pass and yield zero gradients. I'll include these modifications also in the next release that I'll try to get out in the next couple of weeks.
nan_fix.zip (9.49 kB)
Thank you @s-laine for the quick response. So I guess I can just ignore the issue, as the nan-gradients are not propagated and there should also be no performance loss.
Workaround:
If one needs anomaly detection, just add uv = torch.where(rast[...,3:]==0, tensor(1.), uv)
before dr.texture()
.
Correct - in this case the NaNs would not be propagated so it's less serious than what anomaly detection suggests. Closing.
The following example adds a cube texture to the triangle torch sample:
When I add
with torch.autograd.detect_anomaly():
, it fails withnvdiffrast 0.2.5 Windows 10, VS2019 pytorch 1.9.0