Skip to content

flow转换onnx报错 #4

Description

@AlexiAlp

python convert_flow_to_onnx.py --device cpu --model_path ../CosyVoice/pretrained_models/CosyVoice2-0.5B/ --output_path ../CosyVoice/pretrained_models/CosyVoice2-0.5B --int32_token --add_speed_control
/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/diffusers/models/lora.py:391: FutureWarning: LoRACompatibleLinear is deprecated and will be removed in version 1.0.0. Use of LoRACompatibleLinear is deprecated. Please switch to PEFT backend by installing PEFT: pip install peft.
deprecate("LoRACompatibleLinear", "1.0.0", deprecation_message)
/Users/yangkun/Documents/yangkun/code/CosyVoiceForOnnx/cosyvoice/utils/mask.py:233: TracerWarning: Converting a tensor to a Python number might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if (chunk_masks.sum(dim=-1) == 0).sum().item() != 0:
/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/diffusers/models/attention_processor.py:730: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if current_length != target_length:
/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/diffusers/models/attention_processor.py:745: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
if attention_mask.shape[0] < batch_size * head_size:
/Users/yangkun/Documents/yangkun/code/CosyVoiceForOnnx/convert_flow_to_onnx.py:64: UserWarning: Exporting a model while it is in training mode. Please ensure that this is intended, as it may lead to different behavior during inference. Calling model.eval() before export is recommended.
torch.onnx.export(
/Users/yangkun/Documents/yangkun/code/CosyVoiceForOnnx/convert_flow_to_onnx.py:64: UserWarning: # 'dynamic_axes' is not recommended when dynamo=True, and may lead to 'torch._dynamo.exc.UserError: Constraints violated.' Supply the 'dynamic_shapes' argument instead if export is unsuccessful.
torch.onnx.export(
W0414 16:52:21.532000 4194 site-packages/torch/onnx/_internal/exporter/_compat.py:133] Setting ONNX exporter to use operator set version 18 because the requested opset_version 17 is a lower version than we have implementations for. Automatic version conversion will be performed, which may not be successful at converting to the requested version. If version conversion is unsuccessful, the opset version of the exported model will be kept at 18. Please consider setting opset_version >=18 to leverage latest ONNX features
W0414 16:52:21.816000 4194 site-packages/torch/onnx/_internal/exporter/_registration.py:110] torchvision is not installed. Skipping torchvision::nms
W0414 16:52:21.816000 4194 site-packages/torch/onnx/_internal/exporter/_registration.py:110] torchvision is not installed. Skipping torchvision::roi_align
W0414 16:52:21.816000 4194 site-packages/torch/onnx/_internal/exporter/_registration.py:110] torchvision is not installed. Skipping torchvision::roi_pool
[torch.onnx] Obtain model graph for RecursiveScriptModule([...] with torch.export.export(..., strict=False)...
[torch.onnx] Obtain model graph for RecursiveScriptModule([...] with torch.export.export(..., strict=False)... ❌
[torch.onnx] Obtain model graph for RecursiveScriptModule([...] with torch.export.export(..., strict=True)...
[torch.onnx] Obtain model graph for RecursiveScriptModule([...] with torch.export.export(..., strict=True)... ❌
Traceback (most recent call last):
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_capture_strategies.py", line 121, in call
exported_program = self._capture(model, args, kwargs, dynamic_shapes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_capture_strategies.py", line 219, in _capture
return torch.export.export(
^^^^^^^^^^^^^^^^^^^^
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/export/init.py", line 164, in export
raise ValueError(
ValueError: Exporting a ScriptModule is not supported. Maybe try converting your ScriptModule to an ExportedProgram using TS2EPConverter(mod, args, kwargs).convert() instead.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/yangkun/Documents/yangkun/code/CosyVoiceForOnnx/convert_flow_to_onnx.py", line 112, in
main()
File "/Users/yangkun/Documents/yangkun/code/CosyVoiceForOnnx/convert_flow_to_onnx.py", line 108, in main
run_onnx_export(config_path, flow_path, args.output_path, device, dtype, args.int32_token, args.add_speed_control)
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 124, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/yangkun/Documents/yangkun/code/CosyVoiceForOnnx/convert_flow_to_onnx.py", line 64, in run_onnx_export
torch.onnx.export(
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/onnx/init.py", line 291, in export
return _compat.export_compat(
^^^^^^^^^^^^^^^^^^^^^^
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_compat.py", line 161, in export_compat
onnx_program = _core.export(
^^^^^^^^^^^^^
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_flags.py", line 27, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/opt/miniconda3/envs/cosy-onnx/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_core.py", line 1428, in export
raise _errors.TorchExportError(
torch.onnx._internal.exporter._errors.TorchExportError: Failed to export the model with torch.export. This is step 1/3 of exporting the model to ONNX. Next steps:

  • Modify the model code for torch.export.export to succeed. Refer to https://pytorch.org/docs/stable/generated/exportdb/index.html for more information.
  • Debug torch.export.export and submit a PR to PyTorch.
  • Create an issue in the PyTorch GitHub repository against the torch.export component and attach the full error stack as well as reproduction scripts.

Exception summary

<class 'ValueError'>: Exporting a ScriptModule is not supported. Maybe try converting your ScriptModule to an ExportedProgram using TS2EPConverter(mod, args, kwargs).convert() instead.

(Refer to the full stack trace above for more information.)

按照requirments.txt安装的依赖,使用的是mac进行推理的

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions