Skip to content

Update call argument storing in the reverse mode - #1416

Merged
vgvassilev merged 3 commits into
vgvassilev:masterfrom
PetroZarytskyi:arg-store
Jun 20, 2025
Merged

Update call argument storing in the reverse mode#1416
vgvassilev merged 3 commits into
vgvassilev:masterfrom
PetroZarytskyi:arg-store

Conversation

@PetroZarytskyi

@PetroZarytskyi PetroZarytskyi commented Jun 19, 2025

Copy link
Copy Markdown
Collaborator

This PR moves the storing system of ref-type call arguments to the same framework as the rest of Clad. This leads to 2 changes in the produced code:

  1. Only original variables (not temporaries _t) are used as pullback args
// forward pass
_t0 = a;
modify(_t0); // a is modified so we store it
...
// reverse pass
a = _t0;
// modify_pullback(_t0, ...) <-- used to be this
modify_pullback(a, ...);

This is safe because pullbacks have the same storing system as the gradients, meaning they are responsible for restoring a to its original state.

  1. In loops, the tape is handled a little differently:
a = clad::back(_t0);
modify_pullback(a, ...);
clad::pop(_t0);

became

a = clad::pop(_t0);
modify_pullback(a, ...);

This PR also updates the documentation of this part.

@github-actions

Copy link
Copy Markdown
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@codecov

codecov Bot commented Jun 19, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vgvassilev vgvassilev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm!

@vgvassilev
vgvassilev merged commit bfd7322 into vgvassilev:master Jun 20, 2025
89 checks passed
@PetroZarytskyi
PetroZarytskyi deleted the arg-store branch August 30, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants