-
Notifications
You must be signed in to change notification settings - Fork 136
Open
Labels
Description
Description
As discussed in pymc-devs/pymc#7212 (comment) it's not clear what the signature / type is.
Besides a Mode object there is a set of strings that are allowed:
pytensor/pytensor/compile/mode.py
Lines 484 to 534 in a76172e
def get_mode(orig_string): | |
if orig_string is None: | |
string = config.mode | |
else: | |
string = orig_string | |
if not isinstance(string, str): | |
return string # it is hopefully already a mode... | |
global instantiated_default_mode | |
# The default mode is cached. However, config.mode can change | |
# If instantiated_default_mode has the right class, use it. | |
if orig_string is None and instantiated_default_mode: | |
if string in predefined_modes: | |
default_mode_class = predefined_modes[string].__class__.__name__ | |
else: | |
default_mode_class = string | |
if instantiated_default_mode.__class__.__name__ == default_mode_class: | |
return instantiated_default_mode | |
if string in ("Mode", "DebugMode", "NanGuardMode"): | |
if string == "DebugMode": | |
# need to import later to break circular dependency. | |
from .debugmode import DebugMode | |
# DebugMode use its own linker. | |
ret = DebugMode(optimizer=config.optimizer) | |
elif string == "NanGuardMode": | |
# need to import later to break circular dependency. | |
from .nanguardmode import NanGuardMode | |
# NanGuardMode use its own linker. | |
ret = NanGuardMode(True, True, True, optimizer=config.optimizer) | |
else: | |
# TODO: Can't we look up the name and invoke it rather than using eval here? | |
ret = eval(string + "(linker=config.linker, optimizer=config.optimizer)") | |
elif string in predefined_modes: | |
ret = predefined_modes[string] | |
else: | |
raise Exception(f"No predefined mode exist for string: {string}") | |
if orig_string is None: | |
# Build and cache the default mode | |
if config.optimizer_excluding: | |
ret = ret.excluding(*config.optimizer_excluding.split(":")) | |
if config.optimizer_including: | |
ret = ret.including(*config.optimizer_including.split(":")) | |
if config.optimizer_requiring: | |
ret = ret.requiring(*config.optimizer_requiring.split(":")) | |
instantiated_default_mode = ret | |
return ret |