Lightning-AI / Lightning-AI/lightning-thunder

Support tracing through input-dtype asserts

Open
#2,306 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

## 🚀 Feature

When there are asserts on the input dtypes, we would want to pass the actual dtype instead of jitting with the thunder dtype equivalent

```python
import torch
import thunder

a = torch.rand((2, 2), dtype=torch.bfloat16)

def foo(x):
assert x.dtype in (torch.float32, torch.bfloat16), x.dtype
return x

jfoo = thunder.jit(foo)

b = jfoo(a)
```

results in the following error:

```shell
File "lightning-thunder/repro.py", line 7, in foo
assert x.dtype in (torch.float32, torch.bfloat16), x.dtype
^^^^^^^^^^^^^^^^^^
AssertionError: thunder.dtypes.bfloat16
```

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 running the reproduction in lightning-thunder/repro.py and trace how input dtypes are represented during thunder.jit tracing. Look for the dtype handling involved in evaluating the assert, then verify that the example accepts torch.bfloat16 while preserving the asserted dtype 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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.