Lightning-AI / Lightning-AI/lightning-thunder

Incorrect prologue for a while loop over a list of tensors

Open
#1,335 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

🐛 Bug

I was preparing an example reproducer for one problem and hit the following error:

File ~/dev/lightning-thunder/thunder/__init__.py:623, in jit.<locals>.get_computation_and_inputs(*args, **kwargs)
    620 cs.last_interpreter_log = last_interpreter_log
    621 cs.last_interpreted_instructions = (i for i in last_interpreter_log if isinstance(i, dis.Instruction))
--> 623 inps, pro_to_epi = pro(*args, **kwargs)
    625 computation_trc = dce(computation_trc)
    626 computation_traces.append(computation_trc)

File ~/dev/lightning-thunder/thunder/__init__.py:727, in jit.<locals>.prologue_execution_timer.<locals>.wrapped(*args, **kwargs)
    725 cs.last_prologue_execution_start = time.perf_counter_ns()
    726 try:
--> 727     return fn(*args, **kwargs)
    728 finally:
    729     cs.last_prologue_execution_stop = time.perf_counter_ns()

File thunder.prologue_2:10, in prologue(*args, **kwargs)
      8 check_len(kwargs, 0)
      9 subscr: "Any" = args[0]
---> 10 t0: "cpu f32[2, 2]" = subscr[1]
     11 a: "cpu f32[2, 2]" = args[1]
     12 t_0_0: "cpu f32[2, 2]" = subscr[0]

IndexError: list index out of range

Sample script to trigger the error:

import torch
import thunder

def func(t0s, a):
    t1s = []
    while t0s:
        t0 = t0s.pop()
        t1 = t0 + a
        t1s.append(t1)
    return sum(t1s)

jfunc = thunder.jit(func)
t0s = [torch.randn(2, 2) for _ in range(2)]
a = torch.randn(2, 2)
jfunc(t0s, a)

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 with the sample script and inspect thunder/init.py around the prologue invocation at lines 623 and 727, then examine the generated thunder.prologue_2 shown in the traceback. Reproduce the list-consuming while loop and compare the generated indexing with the loop's execution; done means the script runs without IndexError and returns the expected tensor result.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.