diff --git a/.jenkins/rules/pylint/pylintrc b/.jenkins/rules/pylint/pylintrc index 83c78e98a8d6f3400d753c7c6eb4668c313cf50c..0a2d143d4b266f6b2a099d44158f7d329fdb6e41 100755 --- a/.jenkins/rules/pylint/pylintrc +++ b/.jenkins/rules/pylint/pylintrc @@ -7,9 +7,6 @@ # pygtk.require(). #init-hook= -# Profiled execution. -profile=no - # Add files or directories to the blacklist. They should be base names, not # paths. ignore=CVS @@ -21,7 +18,6 @@ persistent=yes # usually to register additional checkers. load-plugins= - [MESSAGES CONTROL] # Enable the message, report, category or checker with the given id(s). You can @@ -33,17 +29,12 @@ enable=indexing-exception,old-raise-syntax # can either give multiple identifiers separated by comma (,) or put this # option multiple times (only on the command line, not in the configuration # file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then re-enable specific checks. For example, if +# disable everything first and then reenable specific checks. For example, if # you want to run only the similarities checker, you can use "--disable=all # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager - - -# Set the cache size for astng objects. -cache-size=500 - +disable=design,similarities,no-self-use,attribute-defined-outside-init,locally-disabled,star-args,pointless-except,bad-option-value,global-statement,fixme,suppressed-message,useless-suppression,locally-enabled,no-member,no-name-in-module,import-error,unsubscriptable-object,unbalanced-tuple-unpacking,undefined-variable,not-context-manager,duplicate-code,consider-using-f-string,import-outside-toplevel,unnecessary-dunder-call,arguments-renamed,broad-exception-raised [REPORTS] @@ -52,29 +43,21 @@ cache-size=500 # mypackage.mymodule.MyReporterClass. output-format=text -# Put messages in a separate file for each module / package specified on the -# command line instead of printing them on stdout. Reports (if any) will be -# written in a file name "pylint_global.[txt|html]". -files-output=no - # Tells whether to display a full report or only the messages reports=no -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). +# Python expression which should return a score less than or equal to 10. You +# have access to the variables 'fatal', 'error', 'warning', 'refactor', +# 'convention', and 'info' which contain the number of messages in each +# category, as well as 'statement' which is the total number of statements +# analyzed. This score is used by the global evaluation report (RP0004). evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) -# Add a comment according to your evaluation note. This is used by the global -# evaluation report (RP0004). -comment=no - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - +# Set the output format. Available formats are: text, parseable, colorized, +# json2 (improved json format), json (old json format) and msvs (visual +# studio). You can also give a reporter class, e.g. +# mypackage.mymodule.MyReporterClass. +#output-format= [TYPECHECK] @@ -82,102 +65,112 @@ comment=no # mixin class is detected if its name ends with "mixin" (case insensitive). ignore-mixin-members=yes -# List of classes names for which member attributes should not be checked -# (useful for classes with attributes dynamically set). +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. ignored-classes=SQLObject -# When zope mode is activated, add a predefined set of Zope acquired attributes -# to generated-members. -zope=no +# List of decorators that produce context managers, such as # List of members which are set dynamically and missed by pylint inference # system, and so shouldn't trigger E0201 when accessed. Python regular # expressions are accepted. generated-members=REQUEST,acl_users,aq_parent -# List of decorators that create context managers from functions, such as -# contextlib.contextmanager. +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. contextmanager-decorators=contextlib.contextmanager,contextlib2.contextmanager - [VARIABLES] # Tells whether we should check for unused import in __init__ files. init-import=no -# A regular expression matching the beginning of the name of dummy variables -# (i.e. not used). +# A regular expression matching the name of dummy variables (i.e. expected to +# not be used). dummy-variables-rgx=^\*{0,2}(_$|unused_|dummy_) - # List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. +# you should avoid defining new builtins when possible. additional-builtins= - [BASIC] -# Required attributes for module, separated by a comma -required-attributes= - -# List of builtins function names that should not be used, separated by a comma -bad-functions=apply,input,reduce - - -# Disable the report(s) with the given id(s). -# All non-Google reports are disabled by default. -disable-report=R0001,R0002,R0003,R0004,R0101,R0102,R0201,R0202,R0220,R0401,R0402,R0701,R0801,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,R0915,R0921,R0922,R0923 - # Regular expression which should only match correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ -# Regular expression which should only match correct module level names +# style. If left empty, constant names will be checked with the set naming +# style. const-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$ -# Regular expression which should only match correct class names +# Regular expression matching correct class names. Overrides class-naming- +# style. If left empty, class names will be checked with the set naming style. class-rgx=^_?[A-Z][a-zA-Z0-9]*$ -# Regular expression which should only match correct function names +# Regular expression matching correct function names. Overrides function- +# naming-style. If left empty, function names will be checked with the set +# naming style. function-rgx=^(?:(?P_?[A-Z][a-zA-Z0-9]*)|(?P_?[a-z][a-z0-9_]*))$ -# Regular expression which should only match correct method names +# Regular expression matching correct method names. Overrides method-naming- +# style. If left empty, method names will be checked with the set naming style. method-rgx=^(?:(?P__[a-z0-9_]+__|next)|(?P_{0,2}[A-Z][a-zA-Z0-9]*)|(?P_{0,2}[a-z][a-z0-9_]*))$ -# Regular expression which should only match correct instance attribute names +# Regular expression matching correct attribute names. Overrides attr-naming- +# style. If left empty, attribute names will be checked with the set naming +# style. attr-rgx=^_{0,2}[a-z][a-z0-9_]*$ -# Regular expression which should only match correct argument names +# Regular expression matching correct argument names. Overrides argument- +# naming-style. If left empty, argument names will be checked with the set +# naming style. argument-rgx=^[a-z][a-z0-9_]*$ -# Regular expression which should only match correct variable names +# Regular expression matching correct variable names. Overrides variable- +# naming-style. If left empty, variable names will be checked with the set +# naming style. variable-rgx=^[a-z][a-z0-9_]*$ -# Regular expression which should only match correct attribute names in class -# bodies +# Regular expression matching correct class attribute names. Overrides class- +# attribute-naming-style. If left empty, class attribute names will be checked +# with the set naming style. class-attribute-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$ -# Regular expression which should only match correct list comprehension / -# generator expression variable names +# Regular expression matching correct inline iteration names. Overrides +# inlinevar-naming-style. If left empty, inline iteration names will be checked +# with the set naming style. inlinevar-rgx=^[a-z][a-z0-9_]*$ # Good variable names which should always be accepted, separated by a comma good-names=main,_ -# Bad variable names which should always be refused, separated by a comma +# Bad variable names which should always be refused, separated by a comma. bad-names= # Regular expression which should only match function or class names that do # not require a docstring. no-docstring-rgx=(__.*__|main) +# Regular expression matching correct constant names. Overrides const-naming- # Minimum line length for functions/classes that require docstrings, shorter # ones are exempt. docstring-min-length=10 +# Regular expression matching correct class constant names. Overrides class- +# const-naming-style. If left empty, class constant names will be checked with +# the set naming style. +#class-const-rgx= + +# Regular expression matching correct type alias names. If left empty, type +# alias names will be checked with the set naming style. +#typealias-rgx= + +# Regular expression matching correct type variable names. If left empty, type +# variable names will be checked with the set naming style. +#typevar-rgx= [FORMAT] # Maximum number of characters on a single line. -# mindspore: max-line-length=120 (Default: 80) max-line-length=120 # Regexp for a line that is allowed to be longer than the limit. @@ -197,63 +190,52 @@ ignore-long-lines=(?x) # else. single-line-if-stmt=y -# List of optional constructs for which whitespace checking is disabled -no-space-check= - -# Maximum number of lines in a module +# Maximum number of lines in a module. max-module-lines=99999 -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 # tab). -# mindspore: 4 spaces (Default: 2 spaces) indent-string=' ' - [SIMILARITIES] # Minimum lines number of a similarity. min-similarity-lines=4 -# Ignore comments when computing similarities. +# Comments are removed from the similarity computation ignore-comments=yes -# Ignore docstrings when computing similarities. +# Docstrings are removed from the similarity computation ignore-docstrings=yes -# Ignore imports when computing similarities. +# Imports are removed from the similarity computation ignore-imports=no - [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. notes= - [IMPORTS] # Deprecated modules which should not be used, separated by a comma deprecated-modules=regsub,TERMIOS,Bastion,rexec,sets -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) +# Output a graph (.gv or any supported image format) of all (i.e. internal and +# external) dependencies to the given file (report RP0402 must not be +# disabled). import-graph= -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) +# Output a graph (.gv or any supported image format) of external dependencies +# to the given file (report RP0402 must not be disabled). ext-import-graph= -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) +# Output a graph (.gv or any supported image format) of internal dependencies +# to the given file (report RP0402 must not be disabled). int-import-graph= - [CLASSES] -# List of interface methods to ignore, separated by a comma. This is used for -# instance to not check methods defines in Zope's Interface base class. -ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by - # List of method names used to declare (i.e. assign) instance attributes. defining-attr-methods=__init__,__new__,setUp @@ -263,7 +245,6 @@ valid-classmethod-first-arg=cls,class_ # List of valid names for the first argument in a metaclass class method. valid-metaclass-classmethod-first-arg=mcs - [DESIGN] # Maximum number of arguments for function / method @@ -287,7 +268,6 @@ max-statements=50 # Maximum number of parents for a class (see R0901). max-parents=7 - # Maximum number of attributes for a class (see R0902). max-attributes=7 @@ -297,41 +277,13 @@ min-public-methods=2 # Maximum number of public methods for a class (see R0904). max-public-methods=20 - [EXCEPTIONS] -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=Exception,StandardError,BaseException - - -[AST] - -# Maximum line length for lambdas -short-func-length=1 - -# List of module members that should be marked as deprecated. -# All of the string functions are listed in 4.1.4 Deprecated string functions -# in the Python 2.4 docs. -deprecated-members=string.atof,string.atoi,string.atol,string.capitalize,string.expandtabs,string.find,string.rfind,string.index,string.rindex,string.count,string.lower,string.split,string.rsplit,string.splitfields,string.join,string.joinfields,string.lstrip,string.rstrip,string.strip,string.swapcase,string.translate,string.upper,string.ljust,string.rjust,string.center,string.zfill,string.replace,sys.exitfunc - - -[DOCSTRING] - -# List of exceptions that do not need to be mentioned in the Raises section of -# a docstring. -ignore-exceptions=AssertionError,NotImplementedError,StopIteration,TypeError - - +# Exceptions that will emit a warning when caught. +overgeneral-exceptions=builtins.Exception,builtins.StandardError,builtins.BaseException [TOKENS] # Number of spaces of indent required when the last token on the preceding line # is an open (, [, or {. indent-after-paren=4 - - -[MINDSPORE LINES] - -# Regexp for a proper copyright notice. -copyright=Copyright \d{4} The MindSpore Authors\. +All [Rr]ights [Rr]eserved\. diff --git a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.LiteInfer.rst b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.LiteInfer.rst index 2cd516a013c9b676e87c6f45220b13c4e1c4c48f..a27f784ac93e584f0b107e0c423b48236027c440 100644 --- a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.LiteInfer.rst +++ b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.LiteInfer.rst @@ -1,7 +1,7 @@ mindspore_lite.LiteInfer ============================= -.. py:class:: mindspore_lite.LiteInfer(model_or_net, *net_inputs, context=None, model_group_id=None, config: dict = None) +.. py:class:: mindspore_lite.LiteInfer(model_or_net, *net_inputs, context=None, model_group_id=None, config=None) `LiteInfer` 类接受训练模型作为输入直接执行推理。 diff --git a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.Model.rst b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.Model.rst index c251164f09eb00290d66205e4c28c5058208cb11..6cd3171bdd0b498f0b0b86cbbf016652be608772 100644 --- a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.Model.rst +++ b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.Model.rst @@ -5,7 +5,7 @@ mindspore_lite.Model `Model` 类定义MindSpore Lite模型,便于计算图管理。 - .. py:method:: build_from_file(model_path, model_type, context=None, config_path="", config_dict: dict = None, dec_key=None, dec_mode="AES-GCM", dec_num_parallel=0) + .. py:method:: build_from_file(model_path, model_type, context=None, config_path="", config_dict=None, dec_key=None, dec_mode="AES-GCM", dec_num_parallel=0) 从文件加载并构建模型。 diff --git a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.ModelExecutor.rst b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.ModelExecutor.rst index f6255e3181077858f6e081f5f965bf8006c6be52..ea8a883fef562d7df7035925ddd711420cd69409 100644 --- a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.ModelExecutor.rst +++ b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.ModelExecutor.rst @@ -1,10 +1,13 @@ mindspore_lite.ModelExecutor ============================ -.. py:class:: mindspore_lite.ModelExecutor() +.. py:class:: mindspore_lite.ModelExecutor(executor=None) `ModelExecutor` 类包装多个mindspore_lite模型,并实现其推理调度。 + 参数: + - **executor** (_c_lite_wrapper.ModelExecBind, 可选) - pybind11包装的ModelExecutor类。默认值:``None``。 + .. py:method:: get_inputs() 获取模型的所有输入Tensor。 diff --git a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.MultiModelRunner.rst b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.MultiModelRunner.rst index b6e3036cf966d3f217e77fc1d0be67b12a5f1f05..a6c69781487bea330cc5da06aea3aec726987ea0 100644 --- a/docs/api/lite_api_python/mindspore_lite/mindspore_lite.MultiModelRunner.rst +++ b/docs/api/lite_api_python/mindspore_lite/mindspore_lite.MultiModelRunner.rst @@ -5,7 +5,7 @@ mindspore_lite.MultiModelRunner `MultiModelRunner` 用于创建包含多个Model的mindir,并提供调度多个模型的方式。 - .. py:method:: build_from_file(model_path, model_type, context=None, config_path="", config_dict: dict = None) + .. py:method:: build_from_file(model_path, model_type, context=None, config_path="", config_dict=None) 从文件加载并构建模型。 @@ -15,24 +15,13 @@ mindspore_lite.MultiModelRunner - **context** (Context,可选) - 定义上下文,用于在执行期间传递选项。默认值: ``None``,表示设置target为cpu的Context。 - **config_path** (str,可选) - 定义配置文件的路径,用于在构建模型期间传递用户定义选项。在以下场景中,用户可能需要设置参数。例如:"/home/user/config.txt"。默认值: ``""`` 。 - - **用法1** - 进行混合精度推理的设置,配置文件内容及说明如下: + 进行混合精度推理的设置,配置文件内容及说明如下: - .. code-block:: - - [execution_plan] - [op_name1]=data_type:float16(名字为op_name1的算子设置数据类型为float16) - [op_name2]=data_type:float32(名字为op_name2的算子设置数据类型为float32) - - - **用法2** - 在使用GPU推理时,进行TensorRT设置,配置文件内容及说明如下: - - .. code-block:: + .. code-block:: - [ms_cache] - serialize_path=[serialization model path](序列化模型的存储路径) - [gpu_context] - input_shape=input_name:[input_dim](模型输入维度,用于动态shape) - dynamic_dims=[min_dim~max_dim](模型输入的动态维度范围,用于动态shape) - opt_dims=[opt_dim](模型最优输入维度,用于动态shape) + [execution_plan] + [op_name1]=data_type:float16(名字为op_name1的算子设置数据类型为float16) + [op_name2]=data_type:float32(名字为op_name2的算子设置数据类型为float32) - **config_dict** (dict,可选) - 配置参数字典,当使用该字典配置参数时,优先级高于配置文件。默认值:``None``。 diff --git a/mindspore-lite/python/api/model.py b/mindspore-lite/python/api/model.py index a0cfbd1924729f5a17d08dc0a078c5f71705e8e0..9bf6eff4d2ec4f9ad9292aed31daffe32edeab6e 100644 --- a/mindspore-lite/python/api/model.py +++ b/mindspore-lite/python/api/model.py @@ -108,7 +108,7 @@ class Model(BaseModel): """ def __init__(self): - super(Model, self).__init__(_c_lite_wrapper.ModelBind()) + super().__init__(_c_lite_wrapper.ModelBind()) self.model_path_ = "" self.lora_name_map = {} self.provider = "" @@ -219,7 +219,7 @@ class Model(BaseModel): self.provider = context.ascend.provider if not os.path.exists(model_path): raise RuntimeError( - f"build_from_file failed, model_path does not exist!") + "build_from_file failed, model_path does not exist!") self.model_path_ = model_path model_type_ = _c_lite_wrapper.ModelType.kMindIR_Lite if model_type is ModelType.MINDIR: @@ -227,7 +227,7 @@ class Model(BaseModel): if config_path: if not os.path.exists(config_path): raise RuntimeError( - f"build_from_file failed, config_path does not exist!") + "build_from_file failed, config_path does not exist!") ret = self._model.load_config(config_path) if not ret.IsOk(): raise RuntimeError( @@ -276,7 +276,7 @@ class Model(BaseModel): list[TensorMeta], the output TensorMeta list of the model. """ # pylint: disable=useless-super-delegation - return super(Model, self).get_outputs() + return super().get_outputs() def get_inputs(self): """ @@ -292,7 +292,7 @@ class Model(BaseModel): >>> inputs = model.get_inputs() """ # pylint: disable=useless-super-delegation - return super(Model, self).get_inputs() + return super().get_inputs() def update_weights(self, weights): """ @@ -325,7 +325,7 @@ class Model(BaseModel): elif self.provider == "ge": name = _rename_variable_weight(tensor.name) tensor.name = name - return super(Model, self).update_weights(weights) + return super().update_weights(weights) def predict(self, inputs, outputs=None): """ @@ -418,7 +418,7 @@ class Model(BaseModel): inputs_tensor.append(in_tensor) else: raise TypeError("inputs element must be Tensor, of numpy.") - return super(Model, self).predict(inputs_tensor, outputs) + return super().predict(inputs_tensor, outputs) def resize(self, inputs, dims): """ @@ -461,7 +461,7 @@ class Model(BaseModel): After resize, the first input shape: [1, 3, 112, 112] """ # pylint: disable=useless-super-delegation - super(Model, self).resize(inputs, dims) + super().resize(inputs, dims) class ModelParallelRunner: @@ -486,8 +486,8 @@ class ModelParallelRunner: if hasattr(_c_lite_wrapper, "ModelParallelRunnerBind"): self._model = _c_lite_wrapper.ModelParallelRunnerBind() else: - raise RuntimeError(f"ModelParallelRunner init failed, If you want to use it, you need to build" - f"MindSpore Lite serving package by export MSLITE_ENABLE_CLOUD_INFERENCE=on.") + raise RuntimeError("ModelParallelRunner init failed, If you want to use it, you need to build" + "MindSpore Lite serving package by export MSLITE_ENABLE_CLOUD_INFERENCE=on.") self.model_path_ = "" def __str__(self): @@ -525,7 +525,7 @@ class ModelParallelRunner: check_isinstance("model_path", model_path, str) if not os.path.exists(model_path): raise RuntimeError( - f"ModelParallelRunner's build from file failed, model_path does not exist!") + "ModelParallelRunner's build from file failed, model_path does not exist!") self.model_path_ = model_path if context is None: ret = self._model.init(self.model_path_, None) @@ -680,7 +680,7 @@ class ModelParallelRunner: _outputs = self._model.predict(_inputs, _outputs, None, None) if not isinstance(_outputs, list) or len(_outputs) == 0: - raise RuntimeError(f"predict failed!") + raise RuntimeError("predict failed!") predict_outputs = [] for _output in _outputs: predict_outputs.append(Tensor(_output)) @@ -777,8 +777,8 @@ class ModelGroup: flags_inner = _c_lite_wrapper.ModelGroupFlag.kShareWeightAndWorkspace else: raise RuntimeError( - f"Parameter flags should be ModelGroupFlag.SHARE_WORKSPACE or ModelGroupFlag.SHARE_WEIGHT" - f" or ModelGroupFlag.kShareWeightAndWorkspace") + "Parameter flags should be ModelGroupFlag.SHARE_WORKSPACE or ModelGroupFlag.SHARE_WEIGHT" + " or ModelGroupFlag.kShareWeightAndWorkspace") self._model_group = _c_lite_wrapper.ModelGroupBind(flags_inner) def add_model(self, models): @@ -799,7 +799,7 @@ class ModelGroup: if not isinstance(models, (list, tuple)): raise TypeError(f"models must be list/tuple, but got {type(models)}") if not models: - raise RuntimeError(f"models cannot be empty") + raise RuntimeError("models cannot be empty") model0 = models[0] if isinstance(model0, str): for i, element in enumerate(models): @@ -818,7 +818,7 @@ class ModelGroup: raise TypeError(f"models element must be all str or Model, but got " f"{type(model0)} at index {0}.") if not ret.IsOk(): - raise RuntimeError(f"ModelGroup's add model failed.") + raise RuntimeError("ModelGroup's add model failed.") def cal_max_size_of_workspace(self, model_type, context): """ @@ -843,23 +843,13 @@ class ModelGroup: model_type_, context._context._inner_context) if not ret.IsOk(): raise RuntimeError( - f"ModelGroup's cal max size of workspace failed.") + "ModelGroup's cal max size of workspace failed.") class MultiModelRunner: """ The `MultiModelRunner` class is used to create mindir with multiple Models and provides a way to schedule multiple models. - Raises: - TypeError: `model_path` is not str. - TypeError: `model_type` is not ModelType. - TypeError: `context` is not Context or ``None`` . - TypeError: `config_path` is not str. - RuntimeError: `model_path` file path not exist. - RuntimeError: `config_path` file path not exist. - RuntimeError: load `config_path` failed. - RuntimeError: load and build MultiModelRunner failed. - Examples: >>> import mindspore_lite as mslite >>> import numpy as np @@ -903,26 +893,14 @@ class MultiModelRunner: options during build model. In the following scenarios, users may need to set the parameter. For example, "/home/user/config.txt". Default: ``""``. - - Usage 1: Set mixed precision inference. The content and description of the configuration file are as - follows: - - .. code-block:: - - [execution_plan] - [op_name1]=data_Type: float16 (The operator named op_name1 sets the data type as float16) - [op_name2]=data_Type: float32 (The operator named op_name2 sets the data type as float32) + Set mixed precision inference. The content and description of the configuration file are as + follows: - - Usage 2: When GPU inference, set the configuration of TensorRT. The content and description of the - configuration file are as follows: - - .. code-block:: + .. code-block:: - [ms_cache] - serialize_Path=[serialization model path](storage path of serialization model) - [gpu_context] - input_shape=input_Name: [input_dim] (Model input dimension, for dynamic shape) - dynamic_Dims=[min_dim~max_dim] (dynamic dimension range of model input, for dynamic shape) - opt_Dims=[opt_dim] (the optimal input dimension of the model, for dynamic shape) + [execution_plan] + [op_name1]=data_Type: float16 (The operator named op_name1 sets the data type as float16) + [op_name2]=data_Type: float32 (The operator named op_name2 sets the data type as float32) config_dict (dict, optional): When you set config in this dict, the priority is higher than the configuration items in config_path. @@ -941,6 +919,16 @@ class MultiModelRunner: config_dict = {"ascend_context" : {"rank_table_file" : "path_b"}} The the path_b from the config_dict will be used to compile the model. + + Raises: + TypeError: `model_path` is not str. + TypeError: `model_type` is not ModelType. + TypeError: `context` is not Context or ``None`` . + TypeError: `config_path` is not str. + RuntimeError: `model_path` file path not exist. + RuntimeError: `config_path` file path not exist. + RuntimeError: load `config_path` failed. + RuntimeError: load and build MultiModelRunner failed. """ check_isinstance("model_path", model_path, str) check_isinstance("model_type", model_type, ModelType) @@ -951,16 +939,16 @@ class MultiModelRunner: self.provider = context.ascend.provider if not os.path.exists(model_path): raise RuntimeError( - f"build_from_file failed, model_path does not exist!") + "build_from_file failed, model_path does not exist!") self.model_path_ = model_path model_type_ = _c_lite_wrapper.ModelType.kMindIR if model_type is not ModelType.MINDIR: raise RuntimeError( - f"build_from_file failed, model_type only support MINDIR!") + "build_from_file failed, model_type only support MINDIR!") if config_path: if not os.path.exists(config_path): raise RuntimeError( - f"build_from_file failed, config_path does not exist!") + "build_from_file failed, config_path does not exist!") ret = self._runner.load_config(config_path) if not ret.IsOk(): raise RuntimeError( @@ -983,6 +971,12 @@ class MultiModelRunner: raise RuntimeError( f"build_from_file failed! Error is {ret.ToString()}") def get_model_executor(self): + """ + Get ModelExecutors from MultiModelRunner. + + Returns: + list[ModelExecutor], all Executors in MultiModelRunner. + """ executors = [] for executor_ in self._runner.get_model_executor(): executors.append(ModelExecutor(executor_)) @@ -991,6 +985,10 @@ class MultiModelRunner: class ModelExecutor: """ The `ModelExecutor` class wraps multiple mindspore_lite models and implements their inference scheduling. + + Args: + executor (_c_lite_wrapper.ModelExecBind, optional): ModelExecutor class wrapped with pybind11. + Default: ``None``. """ def __init__(self, executor=None): if executor is None: @@ -1009,6 +1007,13 @@ class ModelExecutor: Returns: list[Tensor], the output Tensor list of the ModelExecutor. + + Raises: + TypeError: `inputs` is not a list. + TypeError: `outputs` is not a list. + TypeError: `inputs` is a list, but the elements are not Tensor. + TypeError: `outputs` is a list, but the elements are not Tensor. + RuntimeError: predict model failed. """ if not isinstance(inputs, (list, tuple)): raise TypeError( @@ -1040,7 +1045,7 @@ class ModelExecutor: _outputs.append(element._tensor) predict_result = self._executor.predict(_inputs, _outputs) if predict_result is None or len(predict_result) == 0: - raise RuntimeError(f"predict failed!") + raise RuntimeError("predict failed!") predict_outputs = [] for output_tensor in predict_result: predict_outputs.append(Tensor(output_tensor))