Support for torch 1.9.0 (#12224)

* Support for torch 1.9.0

* Torch scatter for 1.9.0

* Github Actions run on 1.9.0
This commit is contained in:
Lysandre Debut
2021-06-17 17:29:01 +02:00
committed by GitHub
parent afdd9e3663
commit 3a960c4857
5 changed files with 27 additions and 14 deletions

View File

@@ -80,9 +80,8 @@ jobs:
- v0.4-{{ checksum "setup.py" }} - v0.4-{{ checksum "setup.py" }}
- run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev - run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev
- run: pip install --upgrade pip - run: pip install --upgrade pip
- run: pip install .[sklearn,tf-cpu,testing,sentencepiece,speech,vision] - run: pip install .[sklearn,tf-cpu,torch,testing,sentencepiece,speech,vision]
- run: pip install -U torch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 - run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html
- run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cpu.html
- save_cache: - save_cache:
key: v0.4-{{ checksum "setup.py" }} key: v0.4-{{ checksum "setup.py" }}
paths: paths:
@@ -112,8 +111,7 @@ jobs:
- run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev - run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev
- run: pip install --upgrade pip - run: pip install --upgrade pip
- run: pip install .[sklearn,flax,torch,testing,sentencepiece,speech,vision] - run: pip install .[sklearn,flax,torch,testing,sentencepiece,speech,vision]
- run: pip install -U torch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 - run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html
- run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cpu.html
- save_cache: - save_cache:
key: v0.4-{{ checksum "setup.py" }} key: v0.4-{{ checksum "setup.py" }}
paths: paths:
@@ -142,8 +140,7 @@ jobs:
- run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev - run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev
- run: pip install --upgrade pip - run: pip install --upgrade pip
- run: pip install .[sklearn,torch,testing,sentencepiece,speech,vision,timm] - run: pip install .[sklearn,torch,testing,sentencepiece,speech,vision,timm]
- run: pip install -U torch==1.8.1 torchaudio==0.8.1 torchvision==0.9.1 - run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html
- run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cpu.html
- save_cache: - save_cache:
key: v0.4-torch-{{ checksum "setup.py" }} key: v0.4-torch-{{ checksum "setup.py" }}
paths: paths:
@@ -227,8 +224,7 @@ jobs:
- run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev - run: sudo apt-get -y update && sudo apt-get install -y libsndfile1-dev
- run: pip install --upgrade pip - run: pip install --upgrade pip
- run: pip install .[sklearn,torch,testing,sentencepiece,speech,vision] - run: pip install .[sklearn,torch,testing,sentencepiece,speech,vision]
- run: pip install -U torch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 - run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.9.0+cpu.html
- run: pip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cpu.html
- save_cache: - save_cache:
key: v0.4-torch-{{ checksum "setup.py" }} key: v0.4-torch-{{ checksum "setup.py" }}
paths: paths:

View File

@@ -23,7 +23,7 @@ jobs:
run_tests_torch_gpu: run_tests_torch_gpu:
runs-on: [self-hosted, docker-gpu, single-gpu] runs-on: [self-hosted, docker-gpu, single-gpu]
container: container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-runtime image: pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime
options: --gpus 0 --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ options: --gpus 0 --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
steps: steps:
- name: Launcher docker - name: Launcher docker
@@ -107,7 +107,7 @@ jobs:
run_tests_torch_multi_gpu: run_tests_torch_multi_gpu:
runs-on: [self-hosted, docker-gpu, multi-gpu] runs-on: [self-hosted, docker-gpu, multi-gpu]
container: container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-runtime image: pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime
options: --gpus all --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ options: --gpus all --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
steps: steps:
- name: Launcher docker - name: Launcher docker

View File

@@ -19,7 +19,7 @@ jobs:
run_all_tests_torch_gpu: run_all_tests_torch_gpu:
runs-on: [self-hosted, docker-gpu, single-gpu] runs-on: [self-hosted, docker-gpu, single-gpu]
container: container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-runtime image: pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime
options: --gpus 0 --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ options: --gpus 0 --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
steps: steps:
- name: Launcher docker - name: Launcher docker
@@ -141,7 +141,7 @@ jobs:
run_all_tests_torch_multi_gpu: run_all_tests_torch_multi_gpu:
runs-on: [self-hosted, docker-gpu, multi-gpu] runs-on: [self-hosted, docker-gpu, multi-gpu]
container: container:
image: pytorch/pytorch:1.8.0-cuda11.1-cudnn8-runtime image: pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime
options: --gpus all --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/ options: --gpus all --shm-size "16gb" --ipc host -v /mnt/cache/.cache/huggingface:/mnt/cache/
steps: steps:
- name: Launcher docker - name: Launcher docker

View File

@@ -252,6 +252,8 @@ PRESET_MIRROR_DICT = {
"bfsu": "https://mirrors.bfsu.edu.cn/hugging-face-models", "bfsu": "https://mirrors.bfsu.edu.cn/hugging-face-models",
} }
# This is the version of torch required to run torch.fx features.
TORCH_FX_REQUIRED_VERSION = version.parse("1.8")
_is_offline_mode = True if os.environ.get("TRANSFORMERS_OFFLINE", "0").upper() in ENV_VARS_TRUE_VALUES else False _is_offline_mode = True if os.environ.get("TRANSFORMERS_OFFLINE", "0").upper() in ENV_VARS_TRUE_VALUES else False
@@ -275,7 +277,11 @@ def is_torch_cuda_available():
_torch_fx_available = False _torch_fx_available = False
if _torch_available: if _torch_available:
_torch_fx_available = version.parse(_torch_version) >= version.parse("1.8") torch_version = version.parse(importlib_metadata.version("torch"))
_torch_fx_available = (torch_version.major, torch_version.minor) == (
TORCH_FX_REQUIRED_VERSION.major,
TORCH_FX_REQUIRED_VERSION.minor,
)
def is_torch_fx_available(): def is_torch_fx_available():

View File

@@ -4,10 +4,13 @@ import inspect
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Union
import torch import torch
from packaging import version
from torch import nn from torch import nn
from torch.fx import Graph, GraphModule, Node, Proxy, Tracer from torch.fx import Graph, GraphModule, Node, Proxy, Tracer
from torch.fx.node import Argument from torch.fx.node import Argument
from transformers.file_utils import TORCH_FX_REQUIRED_VERSION, importlib_metadata, is_torch_fx_available
from . import ( from . import (
MODEL_FOR_CAUSAL_LM_MAPPING, MODEL_FOR_CAUSAL_LM_MAPPING,
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING, MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
@@ -144,6 +147,14 @@ class HFTracer(Tracer):
def __init__(self, batch_size=1, sequence_length=[128, 128], num_choices=-1): def __init__(self, batch_size=1, sequence_length=[128, 128], num_choices=-1):
super().__init__() super().__init__()
if not is_torch_fx_available():
torch_version = version.parse(importlib_metadata.version("torch"))
raise ImportError(
f"Found an incompatible version of torch. Found version {torch_version}, but only version "
f"{TORCH_FX_REQUIRED_VERSION} is supported."
)
encoder_sequence_length = sequence_length[0] if isinstance(sequence_length, (list, tuple)) else sequence_length encoder_sequence_length = sequence_length[0] if isinstance(sequence_length, (list, tuple)) else sequence_length
decoder_sequence_length = ( decoder_sequence_length = (
sequence_length[1] if isinstance(sequence_length, (list, tuple)) else encoder_sequence_length sequence_length[1] if isinstance(sequence_length, (list, tuple)) else encoder_sequence_length