Lightning-AI / Lightning-AI/lightning-thunder

backwards for autograd.Function

Open
#1,017 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

autograd program-coverage
Dominant language
Python
Stars
1.5k
Forks
121
PR merge metrics
No merged PRs in 30d

Description

We currently "fudge" autograd.Function by running through the forward as if it was the function and rely on the differentiation of that to work.
(This is not good when there is `.detach()` or some such in the forward.)

Given that
- we do know the call args (in the sense of "meta") of the backward once we have traced through the forward,
- we do not yet know the return signature (because we might have `None` or a Tensor of the same shape as the matching input for the tensor inputs).

I wonder if we could, after tracing the forward
- make a non-prim symbol with the forward trace as subsymbols,
- inspect the `ctx`,
- trace through the backward at that time, put that in a non-primitive symbol as well and make a gradient rule mapping the two.

This will be a considerable amount of magic, unfortunately, but it might just work.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the current autograd.Function handling and how the forward trace is used for differentiation. Examine how ctx, backward tracing, None returns, and same-shape tensor returns would fit the proposed non-primitive symbols and gradient rule. Done means autograd.Function no longer relies on differentiating the forward when cases such as detach are present.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
compilers, machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.