提交 97563d5a 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!5831 raise ValueError when call hook function in graph mode

Merge pull request !5831 from zhangbuxue/check_mode_for_hook_function
......@@ -17,18 +17,21 @@
"""The module of parser python object, called by c++."""
import ast
import types
import inspect
import hashlib
from textwrap import dedent
import inspect
import types
from dataclasses import is_dataclass
from textwrap import dedent
import asttokens
import mindspore.nn as nn
from mindspore import log as logger
from mindspore import Tensor as MsTensor
from mindspore import context
from mindspore import log as logger
from mindspore import nn
from mindspore import ops
from mindspore.common.dtype import pytype_to_dtype
from mindspore.common.api import _MindSporeFunction
from mindspore.common.dtype import pytype_to_dtype
from .namespace import CellNamespace, ClosureNamespace, ClassMemberNamespace
from .resources import parse_object_map, convert_object_map, trope_ns, SYMBOL_UNDEFINE, NO_IMPLEMENT
......@@ -100,6 +103,8 @@ def get_parse_method_of_class(obj, parse_method=None):
else:
if isinstance(obj, nn.Cell):
if obj.enable_hook:
if context.get_context("mode") == context.GRAPH_MODE:
raise ValueError("The graph mode does not support hook function.")
method_name = "_hook_construct"
else:
method_name = "construct"
......
......@@ -241,6 +241,8 @@ class Cell:
if kwargs:
raise ValueError("For 'graph' mode, the outermost network does not support passing "
"key-value pair parameters and variable key-value pair parameters.")
if self.enable_hook:
raise ValueError("The graph mode does not support hook function.")
out = self.compile_and_run(*inputs)
return out
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册