[TVMC] Fix error while compile paddle model with tvmc (#11730)

The tvmc command will throw a error while the passed path of model is not exist, But for PaddlePaddle model, it contains 2 file model_name.pdmodel and model_name.pdiparams, we only pass the prefix like inference_model/model_name.

This pr is same with https://github.com/apache/tvm/pull/11108 
Since the origin PR didn't update for a long time, I send this new PR
This commit is contained in:
Jason
2022-06-16 01:02:04 +08:00
committed by GitHub
parent 3cb4597ed4
commit f942d19788
3 changed files with 46 additions and 3 deletions
+12 -2
View File
@@ -21,6 +21,7 @@ Frontend classes do lazy-loading of modules on purpose, to reduce time spent on
loading the tool.
"""
import logging
import os
import sys
import importlib
from abc import ABC
@@ -268,7 +269,7 @@ class PaddleFrontend(Frontend):
@staticmethod
def suffixes():
return ["pdmodel", "pdiparams"]
return ["pdmodel"]
def load(self, path, shape_dict=None, **kwargs):
# pylint: disable=C0415
@@ -277,9 +278,18 @@ class PaddleFrontend(Frontend):
paddle.enable_static()
paddle.disable_signal_handler()
if not os.path.exists(path):
raise TVMCException("File {} is not exist.".format(path))
if not path.endswith(".pdmodel"):
raise TVMCException("Path of model file should be endwith suffixes '.pdmodel'.")
prefix = "".join(path.strip().split(".")[:-1])
params_file_path = prefix + ".pdiparams"
if not os.path.exists(params_file_path):
raise TVMCException("File {} is not exist.".format(params_file_path))
# pylint: disable=E1101
exe = paddle.static.Executor(paddle.CPUPlace())
prog, _, _ = paddle.static.load_inference_model(path, exe)
prog, _, _ = paddle.static.load_inference_model(prefix, exe)
return relay.frontend.from_paddle(prog, shape_dict=shape_dict, **kwargs)