Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
if: github.repository == 'Project-MONAI/MONAI'
strategy:
matrix:
container: ["pytorch:21.02", "pytorch:21.10", "pytorch:22.03"] # 21.02, 21.10 for backward comp.
container: ["pytorch:21.02", "pytorch:21.10", "pytorch:22.04"] # 21.02, 21.10 for backward comp.
container:
image: nvcr.io/nvidia/${{ matrix.container }}-py3 # testing with the latest pytorch base image
options: "--gpus all"
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
if: github.repository == 'Project-MONAI/MONAI'
strategy:
matrix:
container: ["pytorch:21.02", "pytorch:21.10", "pytorch:22.03"] # 21.02, 21.10 for backward comp.
container: ["pytorch:21.02", "pytorch:21.10", "pytorch:22.04"] # 21.02, 21.10 for backward comp.
container:
image: nvcr.io/nvidia/${{ matrix.container }}-py3 # testing with the latest pytorch base image
options: "--gpus all"
Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:
if: github.repository == 'Project-MONAI/MONAI'
needs: cron-gpu # so that monai itself is verified first
container:
image: nvcr.io/nvidia/pytorch:22.03-py3 # testing with the latest pytorch base image
image: nvcr.io/nvidia/pytorch:22.04-py3 # testing with the latest pytorch base image
options: "--gpus all --ipc=host"
runs-on: [self-hosted, linux, x64, common]
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pythonapp-gpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
base: "nvcr.io/nvidia/pytorch:21.10-py3"
- environment: PT111+CUDA116
# we explicitly set pytorch to -h to avoid pip install error
# 22.03: 1.12.0a0+2c916ef
# 22.04: 1.12.0a0+bd13bc6
pytorch: "-h"
base: "nvcr.io/nvidia/pytorch:22.03-py3"
base: "nvcr.io/nvidia/pytorch:22.04-py3"
- environment: PT110+CUDA102
pytorch: "torch==1.10.2 torchvision==0.11.3"
base: "nvcr.io/nvidia/cuda:10.2-devel-ubuntu18.04"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# To build with a different base image
# please run `docker build` using the `--build-arg PYTORCH_IMAGE=...` flag.
ARG PYTORCH_IMAGE=nvcr.io/nvidia/pytorch:22.03-py3
ARG PYTORCH_IMAGE=nvcr.io/nvidia/pytorch:22.04-py3
FROM ${PYTORCH_IMAGE}

LABEL maintainer="monai.contact@gmail.com"
Expand Down
2 changes: 1 addition & 1 deletion monai/data/meta_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def _copy_attr(self, attribute: str, input_objs: list[MetaObj], default_fn: Call
Returns:
Returns `None`, but `self` should be updated to have the copied attribute.
"""
attributes = [getattr(i, attribute) for i in input_objs]
attributes = [getattr(i, attribute) for i in input_objs if hasattr(i, attribute)]
if len(attributes) > 0:
val = attributes[0]
if deep_copy:
Expand Down
15 changes: 13 additions & 2 deletions monai/data/meta_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ def __torch_function__(cls, func, types, args=(), kwargs=None) -> Any:
kwargs = {}
ret = super().__torch_function__(func, types, args, kwargs)
# if `out` has been used as argument, metadata is not copied, nothing to do.
if "out" in kwargs:
return ret
# if "out" in kwargs:
# return ret
# we might have 1 or multiple outputs. Might be MetaTensor, might be something
# else (e.g., `__repr__` returns a string).
# Convert to list (if necessary), process, and at end remove list if one was added.
Expand Down Expand Up @@ -232,3 +232,14 @@ def affine(self) -> torch.Tensor:
def affine(self, d: torch.Tensor) -> None:
"""Set the affine."""
self.meta["affine"] = d

def new_empty(self, size, dtype=None, device=None, requires_grad=False):
"""
must be defined for deepcopy to work

See:
- https://pytorch.org/docs/stable/generated/torch.Tensor.new_empty.html#torch-tensor-new-empty
"""
return type(self)(
self.as_tensor().new_empty(size=size, dtype=dtype, device=device, requires_grad=requires_grad)
)
3 changes: 1 addition & 2 deletions tests/test_meta_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,14 +272,13 @@ def test_amp(self):
def test_out(self):
"""Test when `out` is given as an argument."""
m1, _ = self.get_im()
m1_orig = deepcopy(m1)
m2, _ = self.get_im()
m3, _ = self.get_im()
torch.add(m2, m3, out=m1)
m1_add = m2 + m3

assert_allclose(m1, m1_add)
self.check_meta(m1, m1_orig)
# self.check_meta(m1, m2) # meta is from first input tensor

@parameterized.expand(TESTS)
def test_collate(self, device, dtype):
Expand Down