-
Notifications
You must be signed in to change notification settings - Fork 19
fix: Added magpieTTS #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,9 +64,9 @@ def export_model(model, cfg, args, artifacts, metadata): | |
| export_filename = cfg.export_file | ||
| export_file = os.path.join(tmpdir, export_filename) | ||
|
|
||
| if cfg.export_format in ["ONNX", "TS"]: | ||
| if cfg.export_format in ["ONNX", "TS"] and (model.__class__.__name__ == "MagpieTTSModel" and args.submodel == "encoder"): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in the latest commit
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @virajkarandikar good to resolve? |
||
| # Export the model, get the descriptions. | ||
| if not isinstance(model, Exportable): | ||
| if not isinstance(model, Exportable) and not model.__class__.__name__ == "MagpieTTSModel": | ||
| logging.error("Your NeMo model class ({}) is not Exportable.".format(metadata['obj_cls'])) | ||
| sys.exit(1) | ||
|
|
||
|
|
@@ -86,15 +86,38 @@ def export_model(model, cfg, args, artifacts, metadata): | |
| if cfg.max_dim is not None: | ||
| in_args["max_dim"] = cfg.max_dim | ||
|
|
||
| input_example = model.input_module.input_example(**in_args) | ||
| _, descriptions = model.export( | ||
| export_file, | ||
| input_example=input_example, | ||
| check_trace=args.runtime_check, | ||
| onnx_opset_version=args.onnx_opset, | ||
| verbose=bool(args.verbose), | ||
| ) | ||
| del model | ||
| if model.__class__.__name__ == "MagpieTTSModel" and cfg.export_format == "ONNX": | ||
| from nemo2riva.patches.tts.magpietts import EncoderOnnxModel | ||
| with torch.no_grad(): | ||
| model.eval() | ||
| model = model.half() | ||
| encoder_model = EncoderOnnxModel(model) | ||
| input_args, dynamic_axes, output_names, input_names = encoder_model._prepare_for_export() | ||
|
|
||
| torch.onnx.export(encoder_model, | ||
| input_args, | ||
| export_file, | ||
| input_names=input_names, | ||
| output_names=output_names, | ||
| dynamic_axes=dynamic_axes, | ||
| opset_version=17) | ||
|
|
||
| enc_gs = gs.import_onnx(onnx.load(export_file)) | ||
| outputs = enc_gs.outputs | ||
| fix_outputs = [outputs[0]] | ||
| enc_gs.outputs = fix_outputs | ||
| onnx.save(gs.export_onnx(enc_gs), export_file) | ||
| del model, encoder_model | ||
| else: | ||
| input_example = model.input_module.input_example(**in_args) | ||
| _, descriptions = model.export( | ||
| export_file, | ||
| input_example=input_example, | ||
| check_trace=args.runtime_check, | ||
| onnx_opset_version=args.onnx_opset, | ||
| verbose=bool(args.verbose), | ||
| ) | ||
| del model | ||
| if cfg.export_format == 'ONNX': | ||
| o_list = os.listdir(tmpdir) | ||
| save_as_external_data = len(o_list) > 1 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Decoder | ||
| Command to export decoder: | ||
| `nemo2riva <model.ckpt path> --load_ckpt --model_config <hparams_file> --audio_codecpath <codec .nemo ckpt> --key tlt_encode --out magpie_decoder.riva --submodel decoder` | ||
|
|
||
| # Encoder | ||
| Command to export encoder: | ||
| `nemo2riva <model.ckpt path> --load_ckpt --model_config <hparams_file> --audio_codecpath <codec .nemo ckpt> --key tlt_encode --out magpie_encoder.riva --submodel encoder` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove this code block if commented and use context manager for file operation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@styagi130 could you review this comment and update as needed?