MCPcopy Index your code
hub / github.com/pytorch/pytorch / scope_wrapper

Method scope_wrapper

caffe2/python/brew.py:91–115  ·  view source on GitHub ↗
(*args, **kwargs)

Source from the content-addressed store, hash-verified

89 )
90
91 def scope_wrapper(*args, **kwargs):
92 new_kwargs = {}
93 if helper_name != 'arg_scope':
94 if len(args) > 0 and isinstance(args[0], ModelHelper):
95 model = args[0]
96 elif 'model' in kwargs:
97 model = kwargs['model']
98 else:
99 raise RuntimeError(
100 "The first input of helper function should be model. " \
101 "Or you can provide it in kwargs as model=<your_model>.")
102 new_kwargs = copy.deepcopy(model.arg_scope)
103 func = self._registry[helper_name]
104 var_names, _, varkw, _= inspect.getargspec(func)
105 if varkw is None:
106 # this helper function does not take in random **kwargs
107 new_kwargs = {
108 var_name: new_kwargs[var_name]
109 for var_name in var_names if var_name in new_kwargs
110 }
111
112 cur_scope = get_current_scope()
113 new_kwargs.update(cur_scope.get(helper_name, {}))
114 new_kwargs.update(kwargs)
115 return func(*args, **new_kwargs)
116
117 scope_wrapper.__name__ = helper_name
118 return scope_wrapper

Callers

nothing calls this directly

Calls 5

isinstanceFunction · 0.85
get_current_scopeFunction · 0.85
funcFunction · 0.70
updateMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected