Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/networks/nets/test_dints_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@

from __future__ import annotations

import logging
import unittest

import numpy as np
import torch
import torch._dynamo
from parameterized import parameterized

from monai.networks.nets import DiNTS, TopologyInstance, TopologySearch
Expand Down Expand Up @@ -293,6 +295,32 @@ def test_eager_honours_caller_owned_arch_code_array(self):
self.assertFalse(bool(grid.arch_code_a[0, 0]))


@unittest.skipUnless(torch._dynamo.is_dynamo_supported(), "dynamo is unsupported on this platform")
class TestDintsGraphBreaks(unittest.TestCase):
def test_compiles_to_a_single_graph(self):
"""A deployed DiNTS traces into one graph, with no break on a topology branch."""
# Before https://github.com/Project-MONAI/MONAI/issues/9144 was fixed this grid reported
# 14 graphs / 13 breaks: one break per `node_a` / `arch_code_a` element read.
torch._dynamo.reset()
# dynamo logs thousands of DEBUG records while tracing; pytest replays them all on
# failure, burying the assertion message.
trace_logger = logging.getLogger("torch.__trace")
self.addCleanup(trace_logger.setLevel, trace_logger.level)
trace_logger.setLevel(logging.WARNING)
grid = TopologyInstance(
channel_mul=0.2, num_blocks=6, num_depths=3, use_downsample=True, spatial_dims=3, device="cpu"
)
net = DiNTS(dints_space=grid, in_channels=1, num_classes=2, spatial_dims=3, use_downsample=True).eval()

explanation = torch._dynamo.explain(net)(torch.randn(1, 1, 32, 32, 32))

self.assertEqual(
(explanation.graph_count, explanation.graph_break_count),
(1, 0),
"DiNTS no longer compiles to a single graph; a topology branch is reading a tensor again (#9144).",
)


class TestDintsTS(unittest.TestCase):
@parameterized.expand(TEST_CASES_3D + TEST_CASES_2D)
def test_script(self, dints_grid_params, dints_params, input_shape, _):
Expand Down
Loading