qwen3-8b 模型导出错误
使用最新的代码,先安装依赖 然后python3 llmexport.py --path Qwen3-8B --export mnn --dst_path Qwen3-8B-mnn导出模型的时候有如下的报错
💥 Failed export onnx model to
Traceback (most recent call last):
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_capture_strategies.py", line 118, in call
exported_program = self._capture(model, args, kwargs, dynamic_shapes)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_capture_strategies.py", line 210, in _capture
return torch.export.export(
^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/init.py", line 311, in export
raise e
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/init.py", line 277, in export
return _export(
^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1163, in wrapper
raise e
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1129, in wrapper
ep = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 2255, in _export
ep = _export_for_training(
^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1163, in wrapper
raise e
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1129, in wrapper
ep = fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/exported_program.py", line 124, in wrapper
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 2071, in _export_for_training
export_artifact = export_func(
^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 2002, in _non_strict_export
aten_export_artifact = _to_aten_func( # type: ignore[operator]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1793, in _export_to_aten_ir_make_fx
gm, graph_signature = transform(_make_fx_helper)(
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1922, in _aot_export_non_strict
gm, sig = aot_export(wrapped_mod, args, kwargs=kwargs, **flags)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/export/_trace.py", line 1706, in _make_fx_helper
gm = make_fx(
^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 2429, in wrapped
return make_fx_tracer.trace(f, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 2356, in trace
return self._trace_inner(f, *args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 2318, in _trace_inner
t = dispatch_trace(
^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/_compile.py", line 53, in inner
return disable_fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/_dynamo/eval_frame.py", line 1044, in _fn
return fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1303, in dispatch_trace
graph = tracer.trace(root, concrete_args) # type: ignore[arg-type]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1908, in trace
res = super().trace(root, concrete_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/_symbolic_trace.py", line 868, in trace
(self.create_arg(fn(*args)),),
^^^^^^^^^
File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/fx/experimental/proxy_tensor.py", line 1361, in wrapped
out = f(*tensors) # type:ignore[call-arg]
^^^^^^^^^^^
File "
Caused by: (_export/non_strict_utils.py:1066 in torch_function) For more information, run with TORCH_LOGS="dynamic" For extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u0" If you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1 For more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing
For C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
The following call raised this error: File "/data/sw-build/andy.tian/MNN/transformers/llm/export/llmexport.py", line 413, in forward hidden_states = hidden_states[:, logits_index:, :]
The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your export() call with draft_export().
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "/data/sw-build/andy.tian/MNN/transformers/llm/export/utils/spinner.py", line 18, in wrapper result = func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/data/sw-build/andy.tian/MNN/transformers/llm/export/llmexport.py", line 840, in export_onnx torch.onnx.export( File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/onnx/init.py", line 296, in export return _compat.export_compat( ^^^^^^^^^^^^^^^^^^^^^^ File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_compat.py", line 143, in export_compat onnx_program = _core.export( ^^^^^^^^^^^^^ File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_flags.py", line 23, in wrapper return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "/data/sw-build/andy.tian/miniforge3/envs/mnn_llm_quant/lib/python3.12/site-packages/torch/onnx/_internal/exporter/_core.py", line 1385, 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.exportto succeed. Refer to https://pytorch.org/docs/stable/generated/exportdb/index.html for more information. - Debug
torch.export.exportand 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 'torch.fx.experimental.symbolic_shapes.GuardOnDataDependentSymNode'>: Could not extract specialized integer from data-dependent expression u0 (unhinted: u0). (Size-like symbols: none)
Caused by: (_export/non_strict_utils.py:1066 in torch_function) For more information, run with TORCH_LOGS="dynamic" For extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u0" If you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1 For more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing
For C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
The following call raised this error: File "/data/sw-build/andy.tian/MNN/transformers/llm/export/llmexport.py", line 413, in forward hidden_states = hidden_states[:, logits_index:, :]
The error above occurred when calling torch.export.export. If you would like to view some more information about this error, and get a list of all other errors that may occur in your export call, you can replace your export() call with draft_export().
(Refer to the full stack trace above for more information.)
更新一下代码再试一下吧