Lightning-AI / Lightning-AI/lightning-thunder

`disable_torch_autograd_support` should consider `no_grad` and `inference_mode`

Open
#315 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

## 🚀 Feature

Per title

### Motivation

I'm running a benchmark of my own with `@torch.inference_mode()` (I also tried `@torch.no_grad`)

`thunder.compile` is failing with `NotImplementedError: VJP for PrimIDs.RECIPROCAL is not implemented` even though the benchmark doesn't run `backward`

### Pitch

```python
model = thunder.jit(model, disable_torch_autograd=True)

# is equivalent to

with torch.inference_mode():
model = thunder.jit(model)

# and

with torch.no_grad():
model = thunder.jit(model)
```

With careful consideration if the user also passes a conflicting `disable_torch_autograd=...`

cc @carmocca @borda

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

No file or test is named; begin at the thunder.jit entry point and trace how disable_torch_autograd relates to torch.no_grad and torch.inference_mode. Done means those contexts provide equivalent behavior, while an explicitly conflicting disable_torch_autograd value is handled deliberately.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
compilers, machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.