Skip to content

TypeError: object of type 'NoneType' has no len() #6

Description

@gdet

Hello everyone,

I am trying to finetune the GPT-2 model following this code https://github.com/piegu/fastai-projects/blob/master/finetuning-English-GPT2-any-language-Portuguese-HuggingFace-fastaiv2_FAST.ipynb . And I have this error before dataloaders:

 Traceback (most recent call last):
   File "fastaitokenizer.py", line 249, in <module>
     dls = tls.dataloaders(bs=bs, seq_len=sl)
   File "/home/myuser/.conda/envs/fastai2/lib/python3.8/site-packages/fastai2/data/core.py", line 203, in dataloaders
     dl = dl_type(self.subset(0), bs=bs, shuffle=shuffle_train, drop_last=drop_last, n=n, device=device,
   File "/home/myuser/.conda/envs/fastai2/lib/python3.8/site-packages/fastcore/utils.py", line 454, in _f
     return inst if to_return else f(*args, **kwargs)
   File "/home/myuser/.conda/envs/fastai2/lib/python3.8/site-packages/fastai2/text/data.py", line 92, in __init__
     lens = [len(o) for o in self.items if str(o)!='nan']
   File "/home/myuser/.conda/envs/fastai2/lib/python3.8/site-packages/fastai2/text/data.py", line 92, in <listcomp>
     lens = [len(o) for o in self.items if str(o)!='nan']
 TypeError: object of type 'NoneType' has no len()

The error is in all data code section not in sample data section. In sample data code section where you test your code I have no error.
What could be the problem?
I opened the file /home/myuser/.conda/envs/fastai2/lib/python3.8/site-packages/fastai2/text/data.py and added if o is none to add len(o) as zero but then I have an error about the size of the tensors. Something like:

RuntimeError: stack expects each tensor to be equal size, but got [1024] at entry 1 and [962] at entry 2

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions