6
from typing import Any, Dict
10
log = logging.getLogger(__name__)
18
if torch._running_with_deploy():
24
if os.path.basename(os.path.dirname(__file__)) == "shared":
25
torch_parent = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
27
torch_parent = os.path.dirname(os.path.dirname(__file__))
30
def get_file_path(*path_components: str) -> str:
31
return os.path.join(torch_parent, *path_components)
34
def get_file_path_2(*path_components: str) -> str:
35
return os.path.join(*path_components)
38
def get_writable_path(path: str) -> str:
39
if os.access(path, os.W_OK):
41
return tempfile.mkdtemp(suffix=os.path.basename(path))
44
def prepare_multiprocessing_environment(path: str) -> None:
48
def resolve_library_path(path: str) -> str:
49
return os.path.realpath(path)
52
def throw_abstract_impl_not_imported_error(opname, module, context):
53
if module in sys.modules:
54
raise NotImplementedError(
55
f"{opname}: We could not find the abstract impl for this operator. "
58
raise NotImplementedError(
59
f"{opname}: We could not find the abstract impl for this operator. "
60
f"The operator specified that you may need to import the '{module}' "
61
f"Python module to load the abstract impl. {context}"
78
def signpost_event(category: str, name: str, parameters: Dict[str, Any]):
79
log.info("%s %s: %r", category, name, parameters)
82
def log_compilation_event(metrics):
83
log.info("%s", metrics)
86
def upload_graph(graph):
90
def set_pytorch_distributed_envs_from_justknobs():
94
def log_export_usage(**kwargs):
98
def justknobs_check(name: str) -> bool:
100
This function can be used to killswitch functionality in FB prod,
101
where you can toggle this value to False in JK without having to
102
do a code push. In OSS, we always have everything turned on all
103
the time, because downstream users can simply choose to not update
104
PyTorch. (If more fine-grained enable/disable is needed, we could
105
potentially have a map we lookup name in to toggle behavior. But
106
the point is that it's all tied to source code in OSS, since there's
107
no live server to query.)
109
This is the bare minimum functionality I needed to do some killswitches.
110
We have a more detailed plan at
111
https://docs.google.com/document/d/1Ukerh9_42SeGh89J-tGtecpHBPwGlkQ043pddkKb3PU/edit
112
In particular, in some circumstances it may be necessary to read in
113
a knob once at process start, and then use it consistently for the
114
rest of the process. Future functionality will codify these patterns
115
into a better high level API.
117
WARNING: Do NOT call this function at module import time, JK is not
118
fork safe and you will break anyone who forks the process and then
124
@functools.lru_cache(None)
126
from triton.testing import nvsmi
128
return nvsmi(["clocks.max.sm"])[0]
131
TEST_MASTER_ADDR = "127.0.0.1"
132
TEST_MASTER_PORT = 29500
135
USE_GLOBAL_DEPS = True
138
USE_RTLD_GLOBAL_WITH_LIBTORCH = False