Skip to content
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

修正 PyTorch 1.8 兼容性问题 / PyTorch 1.8 compatability fix #519

Merged
merged 1 commit into from
Jun 28, 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
9 changes: 8 additions & 1 deletion ltp/data/utils/collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
# Author: Yunlong Feng <ylfeng@ir.hit.edu.cn>

import torch
from torch._six import int_classes, string_classes, container_abcs
from torch._six import string_classes
from torch.utils.data._utils.collate import np_str_obj_array_pattern, default_collate_err_msg_format

_TORCH_MAJOR, _TORCH_MINOR = map(int, torch.__version__.split('.')[0:2])

if _TORCH_MAJOR < 1 or (_TORCH_MAJOR == 1 and _TORCH_MINOR < 8):
from torch._six import int_classes, container_abcs
else:
int_classes = int
import collections.abc as container_abcs

def collate(batch):
r"""Puts each data field into a tensor with outer dimension batch size"""
Expand Down
8 changes: 7 additions & 1 deletion ltp/utils/convertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
# Author: Yunlong Feng <ylfeng@ir.hit.edu.cn>

import torch
from torch._six import container_abcs

_TORCH_MAJOR, _TORCH_MINOR = map(int, torch.__version__.split('.')[0:2])

if _TORCH_MAJOR < 1 or (_TORCH_MAJOR == 1 and _TORCH_MINOR < 8):
from torch._six import container_abcs
else:
import collections.abc as container_abcs


def map2device(batch, device=torch.device('cpu')):
Expand Down