MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / wraped_fn

Function wraped_fn

imperative/python/megengine/traced_module/traced_module.py:249–279  ·  view source on GitHub ↗
(self, name)

Source from the content-addressed store, hash-verified

247def _wrap_mnode_getattr(orig_getattr):
248 @functools.wraps(orig_getattr)
249 def wraped_fn(self, name):
250 if is_tracing_module() and _graph_surgery_mode():
251 obj = self.owner
252 current_graph = active_module_tracer().current_scope()
253 if self.top_graph is not None:
254 current_graph._add_input(self)
255 attr = getattr(obj, name)
256 node = attr
257 if not isinstance(attr, TracedModuleBuilder):
258 if isinstance(attr, Module):
259 attr = TracedModuleBuilder(attr)
260 setattr(obj, name, attr)
261
262 if isinstance(attr, (NodeMixin, RawTensor)):
263 NodeMixin.wrap(
264 attr,
265 lambda: GetAttr.make(
266 self,
267 type=NodeMixin.get_wrapped_type(attr),
268 attr_name=name,
269 name="",
270 ),
271 )
272 if isinstance(attr, (NodeMixin, RawTensor)):
273 node = NodeMixin.get(attr)
274 if isinstance(node, ModuleNode) and isinstance(attr, (NodeMixin, Module)):
275 node._owner = weakref.ref(attr)
276 return node
277 else:
278 node = object.__getattribute__(self, name)
279 return node
280
281 return wraped_fn
282

Callers

nothing calls this directly

Calls 10

_graph_surgery_modeFunction · 0.85
active_module_tracerFunction · 0.85
TracedModuleBuilderClass · 0.85
current_scopeMethod · 0.80
_add_inputMethod · 0.80
get_wrapped_typeMethod · 0.80
__getattribute__Method · 0.80
wrapMethod · 0.45
makeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected