Attribute Error: Code works in Jupiter notebook/ipython but not as script in python/intellij

I have built a model some time ago with fastai 1.0.61. I have LetterTokenizer (char level tokeniser function) inheriting from BaseTokenizer. The error happens when trying to load data and run inference from a normal python program, whereas everything works just fine from Jupiter Notebooks and iPython. I will try to reproduce the error and attach full error trace later. I see torch.load(…), _legacy_load(…) and finally unpickler.load() in the error trace. Any suggestions greatly appreciated.
Error is "Cant’ get attribute ‘LetterTokenizer’ on <module ‘main’.