Conversation
TopologyConstruction.__init__ called torch.from_numpy() on arch_code, so architecture codes loaded as tensors (e.g. search checkpoints re-saved so that they load with torch.load(weights_only=True)) raised TypeError: expected np.ndarray (got Tensor). Use torch.as_tensor(), which keeps the zero-copy numpy path and additionally accepts tensors and nested lists. Add tests for the accepted input types and for a tensor search checkpoint round-trip through weights_only=True. Also fix the DiNTS.node_a docstring shape, which was written transposed. Signed-off-by: 12yuuuu <yu1inge2@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: Project-MONAI/MONAI/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughDiNTS now accepts NumPy arrays, tensors, and nested lists for architecture codes. Tests verify equivalent topology construction across these input forms and check construction from tensor values loaded with Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The change expands supported architecture-code inputs and tests tensor checkpoint loading. No actionable merge-blocking risk is identified; legacy NumPy checkpoint conversion remains a separate follow-up. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Linked Issues checkExplanation Issue [
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Companion model-zoo PR: Project-MONAI/model-zoo#791 (bundle configs load the search code with numpy.asarray / torch.as_tensor and map_location='cpu'; search.py saves tensors). |
Fixes #9025.
Description
TopologyConstruction.__init__(base ofTopologyInstance/TopologySearch) calledtorch.from_numpy()on both entries ofarch_code, so architecture codes that arrive astorch.TensorraisedTypeError: expected np.ndarray (got Tensor).This matters for #9025: the
search_code_18590.ptfiles shipped with thepancreas_ct_dints_segmentation/multi_organ_segmentationbundles storenumpy.ndarrayobjects (
node_a,arch_code_a,arch_code_c,arch_code_a_max— the raw return values ofTopologySearch.decode()), whichtorch.load(weights_only=True)— the default since PyTorch 2.6 —refuses (
Unsupported global: GLOBAL numpy.core.multiarray._reconstruct). Re-saving those files astensors is the right fix on the bundle side, but MONAI must accept tensors first.
Changes:
torch.from_numpy(x)->torch.as_tensor(x, device=self.device)forarch_code_a/arch_code_c. Numpy inputs keep the same zero-copy semantics; tensors and nested lists(e.g. from JSON/YAML configs) now work too. Fully backward compatible.
DiNTS.node_ashape, which was written transposed).test_dints_arch_code_types(numpy / tensor / list give identicalarch_code_a,arch_code_c,cell_tree) andtest_dints_search_code_weights_only_roundtrip(save tensors ->
torch.load(weights_only=True)-> buildTopologyInstance+DiNTS).TopologySearch.decode()still returns numpy arrays; changing its return type is a publicAPI change and is left for a separate discussion. A companion model-zoo PR (save tensors in
search.py, load withnumpy.asarray/torch.as_tensorandmap_location='cpu'in the bundleconfigs) follows and will be linked here.
Types of changes
python -m unittest tests.networks.nets.test_dints_network(9 tests, CPU only — I don't have a CUDA machine).