junrushao1994 commented on a change in pull request #8623:
URL: https://github.com/apache/tvm/pull/8623#discussion_r682758675
##########
File path: python/tvm/tir/schedule/schedule.py
##########
@@ -63,7 +63,37 @@ def __init__(self) -> None:
RAND_VAR_TYPE = Union[ExprRV, BlockRV, LoopRV] # pylint: disable=invalid-name
# Update to `Literal["detail", "fast", "none"]` once upgraded to python3.8
-ERROR_RENDER_LEVEL_CANDIDATES = Union[str] # pylint: disable=invalid-name
+_ERROR_RENDER_LEVEL = {
+ "detail": 0,
+ "fast": 1,
+ "none": 2,
+}
+
+
+def _preprocess_constructor_arguments(
+ mod: Union[PrimFunc, IRModule],
+ debug_mode: Union[bool, int] = False,
+ error_render_level: str = "detail",
+) -> Tuple[IRModule, int, int]:
+ # preprocess `mod`
+ if isinstance(mod, PrimFunc):
+ mod = IRModule({"main": mod})
+ # preprocess `debug_mode`
+ if isinstance(debug_mode, bool):
+ if debug_mode:
+ debug_mode = -1
Review comment:
To be more pythonic, I would prefer to use “on”/“off”/true/false as
user-facing interface, and do the type conversion internally
##########
File path: python/tvm/tir/schedule/schedule.py
##########
@@ -115,39 +139,49 @@ def __init__(
1) VerifySRefTree
2) VerifyCachedFlags
"""
- if isinstance(mod, PrimFunc):
- mod = IRModule({"main": mod})
- if isinstance(debug_mode, bool):
- if debug_mode:
- debug_mode = -1
- else:
- debug_mode = 0
- if not isinstance(debug_mode, int):
- raise TypeError(f"`debug_mode` should be integer or boolean, but
gets: {debug_mode}")
- if error_render_level not in Schedule.ERROR_RENDER_LEVEL:
- raise ValueError(
- 'error_render_level can be "detail", "fast", or "none", but
got: '
- + f"{error_render_level}"
- )
+ # call the constructor
self.__init_handle_by_constructor__(
- _ffi_api.ConcreteSchedule, # type: ignore # pylint:
disable=no-member
- mod,
- debug_mode,
- Schedule.ERROR_RENDER_LEVEL.get(error_render_level),
+ _ffi_api.TracedSchedule, # type: ignore # pylint:
disable=no-member
+ *_preprocess_constructor_arguments(
+ mod,
+ debug_mode,
+ error_render_level,
+ ),
+ )
+
+ @staticmethod
+ def _create_non_traced(
+ mod: Union[PrimFunc, IRModule],
+ *,
+ debug_mode: Union[bool, int] = False,
+ error_render_level: str = "detail",
+ ) -> "Schedule":
+ """Construct a non-traced TensorIR schedule class from an IRModule."""
+ return _ffi_api.ConcreteSchedule( # type: ignore # pylint:
disable=no-member
+ *_preprocess_constructor_arguments(
+ mod,
+ debug_mode,
+ error_render_level,
+ )
)
########## Utilities ##########
@property
def mod(self) -> IRModule:
"""Returns the AST of the module being scheduled"""
- return _ffi_api.ScheduleModule(self) # type: ignore # pylint:
disable=no-member
+ return _ffi_api.ScheduleGetMod(self) # type: ignore # pylint:
disable=no-member
Review comment:
Oh just some context here, we are using the "accessor pattern" here to
get the member, and in the accessor pattern, the convention is `get_x`,
`set_x`, so it is reasonable to go with `GetMod`
##########
File path: python/tvm/tir/schedule/schedule.py
##########
@@ -63,7 +63,37 @@ def __init__(self) -> None:
RAND_VAR_TYPE = Union[ExprRV, BlockRV, LoopRV] # pylint: disable=invalid-name
# Update to `Literal["detail", "fast", "none"]` once upgraded to python3.8
-ERROR_RENDER_LEVEL_CANDIDATES = Union[str] # pylint: disable=invalid-name
+_ERROR_RENDER_LEVEL = {
+ "detail": 0,
+ "fast": 1,
+ "none": 2,
+}
+
+
+def _preprocess_constructor_arguments(
+ mod: Union[PrimFunc, IRModule],
+ debug_mode: Union[bool, int] = False,
+ error_render_level: str = "detail",
+) -> Tuple[IRModule, int, int]:
+ # preprocess `mod`
+ if isinstance(mod, PrimFunc):
+ mod = IRModule({"main": mod})
+ # preprocess `debug_mode`
+ if isinstance(debug_mode, bool):
+ if debug_mode:
+ debug_mode = -1
Review comment:
Yeah the actual code is completely written in C++, and it is strongly
typed with only one type. The dynamically-typed syntactic sugar here is to just
make it more "pythonic". Therefore there is no actual logic here so we don't
need to worry at all :-)
BTW, it is super important that we write all the main logic in C++ if
possible, and the TensorIR/meta schedule project are implementing this rule :-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]