Closed tfogal closed 3 months ago
Here is a smaller repro, (also this doesn't require the patch from #601):
import torch
import thunder
from transformers.utils.generic import ModelOutput
def fn(x):
mo = ModelOutput(foo=x)
return mo["foo"]
# Sanity - eager works
print(fn(torch.randn(3,)))
# Recursion error
thunder.jit(fn)(torch.randn(3,))
Since ModelOutput
inherits OrderedDict
https://github.com/huggingface/transformers/blob/1c68f2cafb4ca54562f74b66d1085b68dd6682f5/src/transformers/utils/generic.py#L310, I tried OrderedDict
instead on a whim, and the thunder.jit
worked. just fyi
Thank you @kshitij12345 for the minimal repro and @crcrpar for the additional info.
The thing we need is to support the wrapper tracking here so we know the mo["foo"]
is the same object as the x
we put in there. This is a bit tricky due to the multi-inheritance, but so we should check
ModelOutput.__post_init__
jitted through or do we have an "opaqueness gap"?.wrapped_items
of mo's WrappedValue
populated from the postinit function's populating the OrderedDict self?.items()
(which comes from OrderedDict and should be lookasided) in .__getitem__
give us the same wrapped values back?If anyone wants to take a stab, don't hesitate to chatting me up. If not I will try to look and write up what I'm doing. (Additional the infinite recursion is not great, likely somethign funny.)
Thinking about this more: Maybe, just maybe, all this works right and the inf recursion is a problem with the MRO in the lookaside in the __getitem__
. We do implement things like iterating over items through __getitem__
and should be careful to call OrderedDict.__getitem__(self,...)
from the ordered iteration rather than self.__getitem__
.
I have a fix, based on Kshiteej's repro and Masaki's additional analysis. Awesome work, @kshitij12345 and @crcrpar
🐛 Bug
Full log of the run which includes the full traceback.
To Reproduce
First apply Kshiteej's patch from #601.
Then install the
tfogal/thunder-nemo
branch of https://github.com/tfogal/NeMo. Then run:Note you'll need a few files for the referenced
./data
directory; you can ping me privately for now, and I'll work on pulling them out from behind the curtain.Environment
cc @tfogal