Using a model trainned back when the module was named 'mozilla_voice_tts'

Hi,

I’m trying to use a TTS model trainned on the dev branch when the module was named “mozilla_voice_tts” but now I can’t load the model since the module is named now “TTS” and I need the new features. Here’s the error I get:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-9-7fc488f938b8> in <module>
     29 num_chars = len(phonemes) if C.use_phonemes else len(symbols)
     30 model = setup_model(num_chars, num_speakers, C, speaker_embedding_dim)
---> 31 cp = torch.load(MODEL_PATH, map_location=torch.device('cpu'))
     32 model.load_state_dict(cp['model'])
     33 model.eval()

~/miniconda3/envs/TTS/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    582                     opened_file.seek(orig_position)
    583                     return torch.jit.load(opened_file)
--> 584                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
    585         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    586 

~/miniconda3/envs/TTS/lib/python3.6/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, **pickle_load_args)
    841     unpickler.persistent_load = persistent_load
    842     print(dir(unpickler))
--> 843     result = unpickler.load()
    844 
    845     return result

ModuleNotFoundError: No module named 'mozilla_voice_tts'

What can I do here ? Thanks

You basically change everything back to TTS in the files where you get error messages. You can check older versions of the file on github to see how it should be.

This is merely a name change that should have happened, but due to Mozilla changing focus are now rolled back to allow for easier commits to the code …

Yeah I changed everything back to “TTS” I don’t have a single time “mozilla_voice_tts” in my code but I guess it must be referenced in the checkpoint because it’s the “torch.load” function that trows this error. And I don’t know how to edit this file it won’t open in vscode since it’s over 400Mb.

Hm, I don’t know whether that is really like that. But before you search forever, just use a branch just before the reversal:

git checkout d4319fe

Works for me :slight_smile:

Yeah but I need the recent dev branch because I’m using the generic vocoder trained recently

OK, I think I read sth about pickels recently. Could be that you are stuck. @erogol Do you know what he could do without reverting that change himself?

if you use the latest dev it fixes the issue

I’m almost sure it’s from the checkpoint of the model since the load function only take the path to the checkpoint and the map_location

torch.load(MODEL_PATH, map_location=torch.device(‘cpu’))

I’m already using the latest dev (08394e46b926478781a0a488949ba622c23670b4 that is to say latest dev minus two readme modification)

don’t load it use tts.io.load_checkpoint

2 Likes

ModuleNotFoundError                       Traceback (most recent call last)
~/workspace/TTS/TTS/tts/utils/io.py in load_checkpoint(model, checkpoint_path, amp, use_cuda)
     10     try:
---> 11         state = torch.load(checkpoint_path, map_location=torch.device('cpu'))
     12     except ModuleNotFoundError:

~/miniconda3/envs/TTS/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    583                     return torch.jit.load(opened_file)
--> 584                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
    585         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)

~/miniconda3/envs/TTS/lib/python3.6/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, **pickle_load_args)
    841     unpickler.persistent_load = persistent_load
--> 842     result = unpickler.load()
    843 

ModuleNotFoundError: No module named 'mozilla_voice_tts'

During handling of the above exception, another exception occurred:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-9-1e5ef3ece411> in <module>
     29 num_chars = len(phonemes) if C.use_phonemes else len(symbols)
     30 model = setup_model(num_chars, num_speakers, C, speaker_embedding_dim)
---> 31 model = load_checkpoint(model, MODEL_PATH)
     32 #model.load_state_dict(cp['model'])
     33 model.eval()

~/workspace/TTS/TTS/tts/utils/io.py in load_checkpoint(model, checkpoint_path, amp, use_cuda)
     12     except ModuleNotFoundError:
     13         pickle_tts.Unpickler = RenamingUnpickler
---> 14         state = torch.load(checkpoint_path, map_location=torch.device('cpu'), pickle_module=pickle_tts)
     15     model.load_state_dict(state['model'])
     16     if amp and 'amp' in state:

~/miniconda3/envs/TTS/lib/python3.6/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    582                     opened_file.seek(orig_position)
    583                     return torch.jit.load(opened_file)
--> 584                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
    585         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    586 

~/miniconda3/envs/TTS/lib/python3.6/site-packages/torch/serialization.py in _load(zip_file, map_location, pickle_module, **pickle_load_args)
    840     unpickler = pickle_module.Unpickler(data_file, **pickle_load_args)
    841     unpickler.persistent_load = persistent_load
--> 842     result = unpickler.load()
    843 
    844     return result

~/workspace/TTS/TTS/utils/io.py in find_class(self, module, name)
      9         if 'TTS' in module:
     10             module = module.replace('TTS', 'TTS')
---> 11         return super().find_class(module, name)
     12 
     13 

ModuleNotFoundError: No module named 'mozilla_voice_tts'

In this snippet

module = module.replace(‘TTS’, ‘TTS’)

isn’t it supposed to be:

module = module.replace(‘mozilla_voice_tts’, ‘TTS’)

So I replaced this function:

def find_class(self, module, name):
        if 'TTS' in module:
            module = module.replace('TTS', 'TTS')
        return super().find_class(module, name)

by this

def find_class(self, module, name):
        return super().find_class(module.replace('mozilla_voice_tts', 'TTS'), name)

in the RenamingUnpickler class in the io.py file and the model is loading fine.
If it looks right to you, I can do a small PR.

1 Like

yes please send a PR

The PR worked fine for my jupyter notebook but now that I want to continue trainning I get the same error due to the fact that train_tts uses torch.load() and not tts.io.load_checkpoint().
I tried to replace it in the code but it wasn’t as simple. I get an error that terms of the loss are not on the same device even when model.cuda() and criterion.cuda() are in the script. Am I missing something ? Is there a reason that the script uses torch.load ?