translate icon indicating copy to clipboard operation
translate copied to clipboard

ONNX export not working

Open ykim362 opened this issue 5 years ago • 5 comments

pytorch_translate/examples/export_iwslt14.sh

This example doesn't work for me. Would you be able to help me to run the example script?

I tried to fix the errors one by one, by removing parameters, but couldn't succeed to export.

  1. onnx_component_export.py: error: unrecognized arguments: --batched-beam
  2. File "/data/repos/translate/pytorch_translate/rnn.py", line 526, in build_single_decoder fp16=args.fp16, AttributeError: 'Namespace' object has no attribute 'fp16'
  3. Exception has occurred: RuntimeError Error(s) in loading state_dict for RNNModel: Missing key(s) in state_dict: "encoder.bilstm.layers.0.weight_ih_l0", "encoder.bilstm.layers.0.weight_hh_l0", "encoder.bilstm.layers.0.bias_ih_l0", "encoder.bilstm.layers.0.bias_hh_l0", "encoder.bilstm.layers.0.weight_ih_l0_reverse", "encoder.bilstm.layers.0.weight_hh_l0_reverse", "encoder.bilstm.layers.0.bias_ih_l0_reverse", "encoder.bilstm.layers.0.bias_hh_l0_reverse", "encoder.bilstm.layers.1.weight_ih_l0", "encoder.bilstm.layers.1.weight_hh_l0", "encoder.bilstm.layers.1.bias_ih_l0", "encoder.bilstm.layers.1.bias_hh_l0". Unexpected key(s) in state_dict: "encoder.layers.0.weight_ih_l0", "encoder.layers.0.weight_hh_l0", "encoder.layers.0.bias_ih_l0", "encoder.layers.0.bias_hh_l0", "encoder.layers.0.weight_ih_l0_reverse", "encoder.layers.0.weight_hh_l0_reverse", "encoder.layers.0.bias_ih_l0_reverse", "encoder.layers.0.bias_hh_l0_reverse", "encoder.layers.1.weight_ih_l0", "encoder.layers.1.weight_hh_l0", "encoder.layers.1.bias_ih_l0", "encoder.layers.1.bias_hh_l0". File "\opt\conda\lib\python3.6\site-packages\torch\nn\modules\module.py", line 771, in load_state_dict File "\opt\conda\lib\python3.6\site-packages\fairseq\models\fairseq_model.py", line 66, in load_state_dict File "D:\repos\translate\pytorch_translate\ensemble_export.py", line 122, in load_models_from_checkpoints File "D:\repos\translate\pytorch_translate\ensemble_export.py", line 414, in build_from_checkpoints File "D:\repos\translate\pytorch_translate\onnx_component_export.py", line 116, in export File "D:\repos\translate\pytorch_translate\onnx_component_export.py", line 88, in main File "D:\repos\translate\pytorch_translate\onnx_component_export.py", line 156, in

ykim362 avatar Mar 20 '19 22:03 ykim362

I re-trained an RNN model instead of using the pre-trained model because of the name mismatch (version issue?). "encoder.bilstm.layers.0.weight_ih_l0 vs. encoder.layers.0.weight_ih_l0"

So, I got encoder and decoder pb files.

When I tried to build cpp, it generated error message that Caffe2 is not found. I installed Caffe2 (pytorch) as in https://caffe2.ai/docs/getting-started.html?platform=ubuntu&configuration=compile.

Could you help me to resolve this issue?


CMake Error at CMakeLists.txt:19 (find_package):
  By not providing "FindCaffe2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Caffe2", but
  CMake did not find one.

  Could not find a package configuration file provided by "Caffe2" with any
  of the following names:

    Caffe2Config.cmake
    caffe2-config.cmake

  Add the installation prefix of "Caffe2" to CMAKE_PREFIX_PATH or set
  "Caffe2_DIR" to a directory containing one of the above files.  If "Caffe2"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!

ykim362 avatar Mar 21 '19 17:03 ykim362

@ykim362, thanks for the report. I'm in the process of updating the examples. We will also replace the ONNX solution with a PyTorch native export.

jmp84 avatar Mar 21 '19 17:03 jmp84

@jmp84 Thanks for the information!

I have one more question.

Replacing ONNX solution with a PyTorch native export

Does this mean Torch Script? https://pytorch.org/tutorials/advanced/cpp_export.html

Or, another solution?

ykim362 avatar Mar 21 '19 17:03 ykim362

@ykim362, yes, I meant Torch Script.

jmp84 avatar Mar 21 '19 17:03 jmp84

Does the next update support export to Caffe2? How does export with Torch Script works with Caffe2

tsauri avatar Apr 02 '19 16:04 tsauri