MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / name_struct

Function name_struct

python/paddle/base/framework.py:1343–1378  ·  view source on GitHub ↗

Note: This should only used in Paddle/python/paddle/nn/layer/layers.py to record the call path for the operators in Static Graph of AutoParallel. Args: prefix(str, optional): prefix. Default is none.

(prefix=None)

Source from the content-addressed store, hash-verified

1341
1342@signature_safe_contextmanager
1343def name_struct(prefix=None):
1344 """
1345 Note: This should only used in Paddle/python/paddle/nn/layer/layers.py
1346 to record the call path for the operators in Static Graph of AutoParallel.
1347
1348 Args:
1349 prefix(str, optional): prefix. Default is none.
1350 """
1351 # TODO(panyx0718): Only [0-9a-z].
1352 # in dygraph we don't need namescope since it will cause mem leak
1353 if in_dygraph_mode():
1354 yield
1355 else:
1356 assert prefix, "namescope prefix can not be empty."
1357 global _name_struct
1358 _name_struct = _name_struct.child(prefix)
1359 if in_pir_mode():
1360 op_num_before = len(
1361 paddle.static.default_main_program().global_block().ops
1362 )
1363 try:
1364 yield
1365 finally:
1366 if in_pir_mode():
1367 all_ops = (
1368 paddle.static.default_main_program().global_block().ops
1369 )
1370 op_num = len(all_ops)
1371
1372 for idx in reversed(range(op_num_before, op_num)):
1373 op = all_ops[idx]
1374 if op.has_attr("struct_name"):
1375 continue
1376 op.set_str_attr("struct_name", _full_name_struct())
1377
1378 _name_struct = _name_struct.parent()
1379
1380
1381def _full_name_struct():

Callers 1

innerMethod · 0.90

Calls 8

in_dygraph_modeFunction · 0.85
in_pir_modeFunction · 0.85
rangeFunction · 0.85
_full_name_structFunction · 0.85
global_blockMethod · 0.80
has_attrMethod · 0.80
childMethod · 0.45
parentMethod · 0.45

Tested by

no test coverage detected