Lightning-AI / Lightning-AI/lightning-thunder
Functional JIT loading closures sharp edge
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
## Strategy required
This issue resumes form PR2410, we need to decide on the strategy for closures sharp edge. Let's start simple, I think we can all agree that this is a sharp edge if we jit `foo`:
``` python
x = 5
def foo():
return x
```
And that's because we are using a variable outside of the jitted scope. However, here is where things get interesting: should we consider the following a sharp egde?
``` python
def foo(x):
def bar():
return x
return bar()
```
I assume that, since we captured x when jitting `foo`, this should not be a sharp edge for `bar` because the variable was declared in the scope(or in this case captured). To fix such a case we can remember what variables we captured and then look them up when we see a freevar. However, @mruberry has an interesting point, what happens in the case that the variable gets deleted? How can we deal with something like:
``` python
def foo():
a = 5
def bar():
nonlocal a
del a
bar()
return a
```
In conclusion, what do you think should be the definition of sharp edge in this context?
cc @apaz-cli @t-vi @mruberry
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing PR2410 and the three closure examples in this issue. Compare how jitted functions handle free variables, captured variables, and deleted nonlocal variables, then document an agreed definition of this sharp edge and the strategy for addressing it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100