Closed nolanblew closed 6 days ago
After some digging, it looks like we can use NamedTemporaryFile
to get around the issue of holding on to a file.
It would look like this:
with tempfile.NamedTemporaryFile(suffix='texttok.model', delete=False) as tmp:
tfn = tmp.name
Path(tfn).write_text(ar_ckpt['vocab']['texttok.model'])
self.texttok.load(tfn)
os.remove(tfn)
I can create a PR if you'd like, but I have not tested on linux/osx and don't have the means to do so.
I can confirm that this fix works on windows 10 if you also do the same thing for speechtok
@nolanblew would appreciate if you can make the PR!
Might be a good idea to confirm if these changes cause any issues with Linux/OSX first. Also confirming the suggested changes are working on Windows 10. If you're running into issues and the error still pops up, check the cached version of inference.py
and make sure the changes are listed there (not just inference.py
in the repo.)
My cache file was in C:\user\.cache\torch\hub\Camb-ai_mars5-tts_master
.
# save and load text tokenize
self.texttok = RegexTokenizer(GPT4_SPLIT_PATTERN)
with tempfile.NamedTemporaryFile(suffix='texttok.model', delete=False, mode='w') as tmp:
tfn = tmp.name
Path(tfn).write_text(ar_ckpt['vocab']['texttok.model'])
self.texttok.load(tfn)
os.remove(tfn)
# save and load speech tokenizer
self.speechtok = CodebookTokenizer(GPT4_SPLIT_PATTERN)
with tempfile.NamedTemporaryFile(suffix='speechtok.model', delete=False, mode='w') as tmp:
sfn = tmp.name
Path(sfn).write_text(ar_ckpt['vocab']['speechtok.model'])
self.speechtok.load(sfn)
os.remove(sfn)
Hi @nolanblew , we're in the process of porting the checkpoints to a safetensors format and that should remove this issue you are facing (i.e. we won't be writing new tempfiles in the init function). Please check back in a few days and it should be fixed.
Perfect I'll hold off on a PR to see if the safetensors fix the issue.
@nolanblew This should be fixed now, we no longer safe any tempfiles in the init function. Let us know if it works now for you? Reminder you may need force_reload=True
in the torch.hub.load()
function to use the latest code.
@nolanblew safetensors are released!
Can confirm that this fixes the issue!
I've followed all the instructions, but on Windows I cannot get the model to load. It keeps getting stuck attempting to delete the temporary
.model
file and crashing.Stacktrace:
The crash seems to be happening here: https://github.com/Camb-ai/MARS5-TTS/blob/e5e92a9c62b8099a96cbe95cd11536a78dbf3c5d/inference.py#L85
When I inspect the user of this file, it's locked by
python.exe
, meaning the file is open somewhere in python and hasn't been closed yet.I'll do my best to debug and add anything more, but my knowledge and expertise is not in this area.
System Info
OS: Windows 11 Pro 23H2 build 22631.3593 Processor: Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz 3.79 GHz RAM: 64.0 GB Graphics Card: NVIDIA GeForce RTX 4090 Graphics VRAM: 24 GB Graphics Driver: 555.99 Python Version: 3.10.11 Torch Version: 2.3.1