Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support dynamic getitem in dictionary for symbolic values #1450

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jjsjann123
Copy link
Collaborator

@jjsjann123 jjsjann123 commented Nov 18, 2024

The old logic assumes getitem in dict is always a constant.

With a script like this:

def foo(a, v):
    return a[v].relu()

jfoo = thunder.jit(foo, cache="symbolic values")
a = {2: torch.randn(2, 2, device="cuda"), 8: torch.randn(3, 3, device="cuda")}
out = jfoo(a, 2)

Running into exceptions here:

NotImplementedError: Exception occured unpacking object from ProvenanceRecord(
  i1 = PseudoInst.INPUT_ARGS()
  i2 = PseudoInst.BINARY_SUBSCR(i1, 0)
  i3 = PseudoInst.BINARY_SUBSCR(i2, PseudoInst.CONSTANT([IntegerProxy name=i0, value=2, static=CONSTRAINT.CONSTRAINABLE]))
)

Since we now have PseudoInst.CONSTANT([IntegerProxy name=i0, value=2, static=CONSTRAINT.CONSTRAINABLE]), which tries to unwrap an IntegerProxy as constant.

The updated logic would preserve the wrapped value if it's holding a number proxy. So the above trace becomes something like this:

ProvenanceRecord(
  i1 = PseudoInst.INPUT_ARGS()
  i2 = PseudoInst.BINARY_SUBSCR(i1, 0)
  i3 = PseudoInst.BINARY_SUBSCR(i1, 1)
  i4 = PseudoInst.BINARY_SUBSCR(i2, i3)
)

@jjsjann123 jjsjann123 changed the title [WIP][DO NOT REVIEW] support dynamic getitem in dictionary for symbolic values Dec 1, 2024
@jjsjann123 jjsjann123 marked this pull request as ready for review December 1, 2024 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant