Skip to content

1965 - register_backward_hook #1966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 7, 2021
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
11 changes: 11 additions & 0 deletions monai/handlers/parameter_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
from bisect import bisect_right
from typing import TYPE_CHECKING, Callable, Dict, List, Optional, Union
Expand Down
2 changes: 1 addition & 1 deletion monai/networks/blocks/crf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020 MONAI Consortium
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
11 changes: 11 additions & 0 deletions monai/optimizers/lr_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Copyright 2020 - 2021 MONAI Consortium
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from torch.optim import Optimizer
from torch.optim.lr_scheduler import _LRScheduler

Expand Down
10 changes: 8 additions & 2 deletions monai/visualize/class_activation_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import torch.nn.functional as F

from monai.transforms import ScaleIntensity
from monai.utils import ensure_tuple
from monai.utils import ensure_tuple, get_torch_version_tuple
from monai.visualize.visualizer import default_upsampler

__all__ = ["CAM", "GradCAM", "GradCAMpp", "ModelWithHooks", "default_normalizer"]
Expand Down Expand Up @@ -73,7 +73,13 @@ def __init__(
continue
_registered.append(name)
if self.register_backward:
mod.register_backward_hook(self.backward_hook(name))
if get_torch_version_tuple() < (1, 8):
mod.register_backward_hook(self.backward_hook(name))
else:
if "inplace" in mod.__dict__ and mod.__dict__["inplace"]:
# inplace=True causes errors for register_full_backward_hook
mod.__dict__["inplace"] = False
mod.register_full_backward_hook(self.backward_hook(name))
if self.register_forward:
mod.register_forward_hook(self.forward_hook(name))
if len(_registered) != len(self.target_layers):
Expand Down