(test_case, v_level=0, ranks=None, max_py_stack_depth=2)
| 27 | |
| 28 | |
| 29 | def _graph_debug(test_case, v_level=0, ranks=None, max_py_stack_depth=2): |
| 30 | class DebugGraph(flow.nn.Graph): |
| 31 | def __init__(self): |
| 32 | super().__init__() |
| 33 | self.m = flow.nn.Linear(3, 3) |
| 34 | |
| 35 | def build(self, x): |
| 36 | return x |
| 37 | |
| 38 | d_g = DebugGraph() |
| 39 | d_g.debug(v_level, ranks=ranks, max_py_stack_depth=max_py_stack_depth) |
| 40 | |
| 41 | if ranks is None: |
| 42 | rank_list = [0] |
| 43 | elif isinstance(ranks, int): |
| 44 | rank_list = [ranks] |
| 45 | elif isinstance(ranks, list): |
| 46 | rank_list = ranks |
| 47 | |
| 48 | if ( |
| 49 | -1 in rank_list or rank in rank_list |
| 50 | ) and v_level >= 0: # v_level == -1 means debug mode is closed |
| 51 | test_case.assertTrue(d_g._debug) |
| 52 | test_case.assertTrue(d_g.m.to(GraphModule)._debug) |
| 53 | print(f"ranks {ranks} rank {rank} debug is opened.") |
| 54 | else: |
| 55 | test_case.assertTrue(not d_g._debug) |
| 56 | test_case.assertTrue(not d_g.m.to(GraphModule)._debug) |
| 57 | print(f"ranks {ranks} rank {rank} debug is closed.") |
| 58 | |
| 59 | |
| 60 | @unittest.skipIf(os.getenv("ONEFLOW_TEST_CPU_ONLY"), "only test cpu cases") |
no test coverage detected