Fix JVPs of power, divmod, and slice_update with partly traced inputs#3636
Open
qflen wants to merge 1 commit into
Open
Fix JVPs of power, divmod, and slice_update with partly traced inputs#3636qflen wants to merge 1 commit into
qflen wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3634
Same class as #3627/#3629 (fixed by #3633):
Primitive::jvpimplementations that break the packed-tangents convention (tangents[i]is the tangent of inputargnums[i]; a jvp returns one tangent per output).Powervjp, which scales every partial bycotangents[0], so with both inputs traced both partials used the first input's tangent and the second tangent was ignoredvjpcall per traced input with its own tangent as the cotangent, summedDivModargnums/tangents— segfaultDynamicSliceUpdateargnumsand readtangents[0]/tangents[1]unconditionally — OOB segfault with one traced input, mispaired tangents forargnums = {0, 2}Before
The divmod and slice_update repros in #3634 segfaulted.
After
j = 5.5452, jvp matches vjp and finite differences, and all repros pass.Added a regression test covering tangent pairing for power, per-output tangents for divmod (including a consumer of the second output), and dynamic slice_update with each subset of traced inputs. Each case fails on unfixed main (wrong value for power, segfault for the other two).
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes