Tracing to torchscript
See original GitHub issueHas anyone been able to successfully convert the generator model to torchscript?
I receive a bizarre error: while tracing works
zero = torch.full((1, 80, 10), -11.52).cuda()
with open("hifi-gan/config.json") as f:
data = f.read()
h = env.AttrDict(json.loads(data))
vocoder = models.Generator(h).cuda()
vocoder.load_state_dict(
torch.load("hifi-gan/pretrained_universal/g_02500000")["generator"]
)
vocoder.remove_weight_norm()
vocoder.eval()
with torch.no_grad():
traced_vocoder = torch.jit.trace(vocoder, zero)
torch.jit.save(traced_vocoder, "vocoder.pth")
Trying to then load the model gives a weird error:
traced_vocoder = torch.jit.load("vocoder.pth")
/opt/conda/lib/python3.8/site-packages/torch/jit/_serialization.py in load(f, map_location, _extra_files)
159 cu = torch._C.CompilationUnit()
160 if isinstance(f, str) or isinstance(f, pathlib.Path):
--> 161 cpp_module = torch._C.import_ir_module(cu, f, map_location, _extra_files)
162 else:
163 cpp_module = torch._C.import_ir_module_from_buffer(
RuntimeError: Found character '45' in string, strings must be qualified Python identifiers
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14
Top Results From Across the Web
TorchScript — PyTorch 1.13 documentation
In many cases either tracing or scripting is an easier approach for converting a model to TorchScript. Tracing and scripting can be composed...
Read more >TorchScript: Tracing vs. Scripting - Yuxin's Blog
Export: refers to the process that turns a model written in eager-mode Python code into a graph that describes the computation. · Tracing:...
Read more >Mastering TorchScript: Tracing vs Scripting, Device Pinning ...
Tracing. When using torch.jit.trace you'll provide your model and sample input as arguments. The input will be fed through the model as ...
Read more >How to convert your PyTorch model to TorchScript | djl
There are two ways to convert your model to TorchScript: tracing and scripting. We will only demonstrate the first one, tracing, but you...
Read more >Export to TorchScript - Hugging Face
TorchScript is a way to create serializable and optimizable models from PyTorch code. There are two PyTorch modules, JIT and TRACE, that allow...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks! I was indeed using dashes and loading using
importlib, and when I instead just added those paths to the sys path the error goes away. Does seem like a weird Torchscript bug.I were able to convert to torchscript via jit.script after some slight modifications, can share the repo tonight