MCPcopy
hub / github.com/dmlc/dgl / get_preferred_backend

Function get_preferred_backend

python/dgl/backend/__init__.py:95–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93
94
95def get_preferred_backend():
96 default_dir = None
97 if "DGLDEFAULTDIR" in os.environ:
98 default_dir = os.getenv("DGLDEFAULTDIR")
99 else:
100 default_dir = os.path.join(os.path.expanduser("~"), ".dgl")
101 config_path = os.path.join(default_dir, "config.json")
102 backend_name = None
103 if "DGLBACKEND" in os.environ:
104 backend_name = os.getenv("DGLBACKEND")
105 elif os.path.exists(config_path):
106 with open(config_path, "r") as config_file:
107 config_dict = json.load(config_file)
108 backend_name = config_dict.get("backend", "").lower()
109
110 if backend_name in ["tensorflow", "mxnet", "pytorch"]:
111 return backend_name
112 else:
113 print(
114 "DGL backend not selected or invalid. "
115 "Assuming PyTorch for now.",
116 file=sys.stderr,
117 )
118 set_default_backend(default_dir, "pytorch")
119 return "pytorch"
120
121
122load_backend(get_preferred_backend())

Callers 1

__init__.pyFile · 0.85

Calls 4

set_default_backendFunction · 0.90
joinMethod · 0.45
loadMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected