Lightning-AI / Lightning-AI/lightning-thunder

Extend catching empty autocast regions to catch other empty contexts

Open
#1,412 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Originally posted by @kshitij12345 in https://github.com/Lightning-AI/lightning-thunder/pull/1400#discussion_r1833018302

Besides {_enter/_exit}_autocast, from trace_rules.py, I could find
{_enter/_exit}_dual_level for forward mode auto-diff, {_enter/_exit}_inference_mode for inference mode.

Besides these, looking at ctx_manager.py, there could also be Stream, Grad, Device related context managers which are mapped to something like the following


old_stream = torch.cuda.get_current_stream()
new_stream = torch.cuda.Stream()
set_stream(new_stream)
# Some operations
set_stream(old_stream)

Refs:
https://github.com/pytorch/pytorch/blob/781c68c86549aa2fd155f92afb0406b7577ab31c/torch/_dynamo/trace_rules.py#L550-L552
https://github.com/pytorch/pytorch/blob/781c68c86549aa2fd155f92afb0406b7577ab31c/torch/_dynamo/trace_rules.py#L2393-L2394

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 reading the referenced PyTorch trace_rules.py and ctx_manager.py entries for dual-level, inference-mode, Stream, Grad, and Device contexts. Trace how lightning-thunder currently handles empty autocast regions, then define coverage for the other empty contexts and verify that the relevant empty-context cases are handled without changing non-empty behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.