mitsuba-renderer / drjit

Dr.Jit — A Just-In-Time-Compiler for Differentiable Rendering
BSD 3-Clause "New" or "Revised" License
601 stars 45 forks source link

Improve the behavior of control flow operations (``dr.if_stmt(), drjit.while_loop()``) in AD-suspended scopes #299

Closed wjakob closed 1 month ago

wjakob commented 1 month ago

Dr.Jit control flow operations (dr.if_stmt(), drjit.while_loop()) currently disable gradient tracking of all variable state when the operation takes place within an AD-disabled scope.

This can be surprising when a @dr.syntax transformation silently passes local variables to such an operation, which then become non-differentiable. @dvicini reported this in issue https://github.com/mitsuba-renderer/drjit/issues/253.

This commit carves out an exception: when variables aren't actually modified by the control flow operation, they can retain their AD identity.

The PR has 3 parts:

The PR depends on a Dr.Jit-Core PR: https://github.com/mitsuba-renderer/drjit-core/pull/104

andyyankai commented 1 month ago

Hi, may I ask if this fix can relate to this issue? Thanks! https://github.com/mitsuba-renderer/mitsuba3/issues/1334