Skip to content

Commit

Permalink
Use PyTorch 1.7 (openvinotoolkit#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
vshampor committed Dec 6, 2020
1 parent 4af1d9f commit 9875a54
Show file tree
Hide file tree
Showing 18 changed files with 675 additions and 654 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ See [third_party_integration](./third_party_integration) for examples of code mo
- Ubuntu\* 18.04 or later (64-bit)
- Python\* 3.6 or later
- NVidia CUDA\* Toolkit 10.2
- PyTorch\* 1.5.0
- PyTorch\* 1.7 or later.

## Installation
We suggest to install or use the package in the [Python virtual environment](https://docs.python.org/3/tutorial/venv.html).
Expand Down
2 changes: 1 addition & 1 deletion examples/classification/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ def accuracy(output, target, topk=(1,)):

res = []
for k in topk:
correct_k = correct[:k].view(-1).float().sum(0, keepdim=True)
correct_k = correct[:k].reshape(-1).float().sum(0, keepdim=True)
res.append(correct_k.mul_(100.0 / batch_size).item())
return res

Expand Down
1 change: 1 addition & 0 deletions examples/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def is_pretrained_model_requested(config: SampleConfig) -> bool:
class MockDataset(data.Dataset):
def __init__(self, img_size: Tuple[int, int] = (32, 32), num_images: int = 1000,
transform=None):
super().__init__()
self._img_size = img_size
self._num_images = num_images
self._transform = transform
Expand Down
1 change: 1 addition & 0 deletions examples/object_detection/datasets/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class COCODataset(data.Dataset):

def __init__(self, annotation_file, images_folder, transform=None, target_transform=None, scale_bboxes=True,
return_image_info=False, rgb=True):
super().__init__()
self.rgb = rgb
self.target_transform = target_transform
self.return_image_info = return_image_info
Expand Down
1 change: 1 addition & 0 deletions examples/object_detection/datasets/voc0712.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class VOCDetection(data.Dataset):
def __init__(self, root, image_sets=(('2007', 'trainval'), ('2012', 'trainval')), transform=None,
target_transform=VOCAnnotationTransform(keep_difficult=False), dataset_name='VOC2012',
return_image_info=False, rgb=True):
super().__init__()
self.rgb = rgb
self.root = root
self.image_set = image_sets
Expand Down
1 change: 1 addition & 0 deletions examples/semantic_segmentation/datasets/camvid.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(self,
image_set='train',
transforms=None,
loader=data_utils.pil_loader):
super().__init__()
self.root_dir = root
self.mode = image_set
self.transforms = transforms
Expand Down
1 change: 1 addition & 0 deletions examples/semantic_segmentation/datasets/cityscapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self,
image_set='train',
transforms=None,
loader=data_utils.pil_loader):
super().__init__()
self.root_dir = root
self.mode = image_set
self.transforms = transforms
Expand Down
1 change: 1 addition & 0 deletions examples/semantic_segmentation/datasets/mapillary.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(self,
image_set='train',
transforms=None,
loader=data_utils.pil_loader):
super().__init__()
self.root_dir = root
self.mode = image_set
self.transforms = transforms
Expand Down
3 changes: 2 additions & 1 deletion nncf/compression_method_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,8 @@ def export_model(self, filename, input_names: List[str] = None, output_names: Li
filename, input_names=input_names,
output_names=output_names,
enable_onnx_checker=False,
opset_version=10)
opset_version=10,
training=True) # Do not fuse Conv+BN in ONNX. May cause dropout nodes to appear in ONNX
model.forward = original_forward


Expand Down
11 changes: 11 additions & 0 deletions nncf/dynamic_graph/trace_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ def from_torch_tensor(tensor, tensor_meta: TensorMeta):
tensor.__class__ = TracedTensor
return tensor

def as_subclass(self, cls: 'TracedTensor') -> 'TracedTensor':
"""Required for PyTorch 1.7.0 compatibility - the handle_torch_function and __torch_function__
API in general calls this after a wrapped function call; need to preserve the tensor_meta extensions"""

return self

# NOTE: This disables the __torch_function__ API altogether when using NNCF.
# TODO: make NNCF utilize the __torch_function__ API instead.
#pylint:disable=protected-access
__torch_function__ = torch._C._disabled_torch_function_impl


def is_iterable(item):
non_iterable_types = (str, bytes, bytearray, torch.Tensor, np.ndarray)
Expand Down
18 changes: 9 additions & 9 deletions nncf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
limitations under the License.
"""
from collections import OrderedDict
from contextlib import contextmanager
from typing import Dict, Callable, Any, Mapping, Sequence, Set, List

import numpy as np
Expand All @@ -23,6 +22,7 @@

from nncf.dynamic_graph.graph_builder import GraphBuilder, ModelInputInfo, create_dummy_forward_fn
from nncf.layer_utils import _NNCFModuleMixin
from contextlib import contextmanager

def scopes_matched(scope_stack_0, scope_stack_1):
from nncf.layers import NNCF_MODULES_MAP
Expand Down Expand Up @@ -198,15 +198,15 @@ def is_tracing_state():
return torch._C._get_tracing_state()


@contextmanager
def no_jit_trace():
# pylint: disable=protected-access
disable_tracing = torch.jit._disable_tracing()
disable_tracing.__enter__()
yield disable_tracing
disable_tracing.__exit__()

class no_jit_trace:
def __enter__(self):
# pylint: disable=protected-access
self.state = torch._C._get_tracing_state()
torch._C._set_tracing_state(None)

def __exit__(self, *args):
torch._C._set_tracing_state(self.state)
self.state = None


def sum_like(tensor_to_sum, ref_tensor):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ def find_version(*file_paths):

INSTALL_REQUIRES.extend(["torch", "torchvision"])

TORCH_VERSION = "1.5.0"
TORCHVISION_VERSION = "0.6.0"
TORCH_VERSION = "1.7.0"
TORCHVISION_VERSION = "0.8.1"
CUDA_VERSION = "102"
IS_CUDA_VER_DEFAULT_FOR_CURRENT_TORCH_VER = True

Expand Down
Loading

0 comments on commit 9875a54

Please sign in to comment.