MCPcopy Create free account
hub / github.com/pytorch/pytorch / arg_scope

Function arg_scope

caffe2/python/helpers/arg_scope.py:12–28  ·  view source on GitHub ↗
(single_helper_or_list, **kwargs)

Source from the content-addressed store, hash-verified

10
11@contextlib.contextmanager
12def arg_scope(single_helper_or_list, **kwargs):
13 global _threadlocal_scope
14 if not isinstance(single_helper_or_list, list):
15 assert callable(single_helper_or_list), \
16 "arg_scope is only supporting single or a list of helper functions."
17 single_helper_or_list = [single_helper_or_list]
18 old_scope = copy.deepcopy(get_current_scope())
19 for helper in single_helper_or_list:
20 assert callable(helper), \
21 "arg_scope is only supporting a list of callable helper functions."
22 helper_key = helper.__name__
23 if helper_key not in old_scope:
24 _threadlocal_scope.current_scope[helper_key] = {}
25 _threadlocal_scope.current_scope[helper_key].update(kwargs)
26
27 yield
28 _threadlocal_scope.current_scope = old_scope
29
30
31def get_current_scope():

Callers

nothing calls this directly

Calls 3

isinstanceFunction · 0.85
get_current_scopeFunction · 0.85
updateMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…