Skip to content

Commit

Permalink
Merge pull request espnet#1840 from kamo-naoyuki/ci
Browse files Browse the repository at this point in the history
Add test for torch>1.1
  • Loading branch information
kamo-naoyuki authored Apr 17, 2020
2 parents 8004ebd + 34b21ca commit 7825783
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 85 deletions.
42 changes: 25 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ jobs:
docker:
- image: circleci/buildpack-deps:18.04
environment:
# NOTE(kan-bayashi): Use 3.7.3 to avoid sentencepiece installation error
ESPNET_PYTHON_VERSION: 3.7.3
TH_VERSION: 1.1.0
CHAINER_VERSION: 5.0.0
ESPNET_PYTHON_VERSION: 3.6
TH_VERSION: 1.4.0
CHAINER_VERSION: 6.0.0
USE_CONDA: true
CC: gcc-7
CXX: g++-7
# To avoid UnicodeEncodeError for python<=3.6
LC_ALL: en_US.UTF-8
working_directory: ~/repo

steps:
Expand All @@ -34,6 +35,7 @@ jobs:
command: |
sudo apt-get update -qq
sudo apt-get install -qq -y cmake g++-7 libsndfile1-dev bc
sudo localedef -f UTF-8 -i en_US en_US
- run:
name: install espnet
command: |
Expand Down Expand Up @@ -66,13 +68,14 @@ jobs:
docker:
- image: circleci/buildpack-deps:16.04
environment:
# NOTE(kan-bayashi): Use 3.7.3 to avoid sentencepiece installation error
ESPNET_PYTHON_VERSION: 3.7.3
TH_VERSION: 1.1.0
CHAINER_VERSION: 5.0.0
ESPNET_PYTHON_VERSION: 3.6
TH_VERSION: 1.4.0
CHAINER_VERSION: 6.0.0
USE_CONDA: true
CC: gcc-7
CXX: g++-7
# To avoid UnicodeEncodeError for python<=3.6
LC_ALL: en_US.UTF-8
working_directory: ~/repo

steps:
Expand All @@ -85,6 +88,7 @@ jobs:
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update -qq
sudo apt-get install -qq -y cmake g++-7 libsndfile1-dev bc
sudo localedef -f UTF-8 -i en_US en_US
- run:
name: install espnet
command: |
Expand Down Expand Up @@ -117,13 +121,14 @@ jobs:
docker:
- image: centos:7
environment:
# NOTE(kan-bayashi): Use 3.7.3 to avoid sentencepiece installation error
ESPNET_PYTHON_VERSION: 3.7.3
TH_VERSION: 1.1.0
CHAINER_VERSION: 5.0.0
ESPNET_PYTHON_VERSION: 3.6
TH_VERSION: 1.4.0
CHAINER_VERSION: 6.0.0
USE_CONDA: true
CC: /opt/rh/devtoolset-7/root/usr/bin/gcc
CXX: /opt/rh/devtoolset-7/root/usr/bin/g++
# To avoid UnicodeEncodeError for python<=3.6
LC_ALL: en_US.UTF-8
working_directory: ~/repo

steps:
Expand All @@ -133,6 +138,7 @@ jobs:
yum install -y git centos-release-scl cmake libsndfile make bzip2 wget which unzip bc
yum-config-manager --enable rhel-server-rhscl-7-rpms
yum install -y devtoolset-7-gcc-c++
localedef -f UTF-8 -i en_US en_US
- checkout
- run:
name: install espnet
Expand Down Expand Up @@ -173,13 +179,14 @@ jobs:
docker:
- image: debian:9
environment:
# NOTE(kan-bayashi): Use 3.7.3 to avoid sentencepiece installation error
ESPNET_PYTHON_VERSION: 3.7.3
TH_VERSION: 1.1.0
CHAINER_VERSION: 5.0.0
ESPNET_PYTHON_VERSION: 3.6
TH_VERSION: 1.4.0
CHAINER_VERSION: 6.0.0
USE_CONDA: true
CC: gcc-6
CXX: g++-6
# To avoid UnicodeEncodeError for python<=3.6
LC_ALL: en_US.UTF-8
working_directory: ~/repo

steps:
Expand All @@ -188,7 +195,8 @@ jobs:
name: install dependencies
command: |
apt-get update -qq
apt-get install -qq -y git cmake g++-6 libsndfile1-dev unzip bzip2 wget curl bc
apt-get install -qq -y git cmake g++-6 libsndfile1-dev unzip bzip2 wget curl bc locales
localedef -f UTF-8 -i en_US en_US
- run:
name: install espnet
command: |
Expand Down
19 changes: 15 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@ jobs:
strategy:
max-parallel: 20
matrix:
os: [ubuntu-16.04, ubuntu-18.04]
python-version: [3.7]
pytorch-version: [1.0.1, 1.1]
# os: [ubuntu-16.04, ubuntu-18.04]
os: [ubuntu-18.04]
python-version: [3.7, 3.8]
pytorch-version: [1.0.1, 1.1.0, 1.2.0, 1.3.1, 1.4.0]
chainer-version: [6.0.0]
use-conda: [true, false]
# NOTE(kamo): Conda is tested by Circle-CI
use-conda: [false]
exclude:
- python-version: 3.8
pytorch-version: 1.0.1
- python-version: 3.8
pytorch-version: 1.1.0
- python-version: 3.8
pytorch-version: 1.2.0
- python-version: 3.8
pytorch-version: 1.3.1
steps:
- uses: actions/checkout@master
- uses: actions/setup-python@v1
Expand Down
10 changes: 4 additions & 6 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ pull_request_rules:
- name: automatic merge if label=auto-merge
conditions:
- "label=auto-merge"
- "status-success=linter_and_test (ubuntu-16.04, 3.7, 1.0.1, 6.0.0, true)"
- "status-success=linter_and_test (ubuntu-16.04, 3.7, 1.0.1, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-16.04, 3.7, 1.1, 6.0.0, true)"
- "status-success=linter_and_test (ubuntu-16.04, 3.7, 1.1, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.0.1, 6.0.0, true)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.0.1, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.1, 6.0.0, true)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.1, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.2, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.3.1, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-18.04, 3.7, 1.4.0, 6.0.0, false)"
- "status-success=linter_and_test (ubuntu-18.04, 3.8, 1.4.0, 6.0.0, false)"
- "status-success=ci/circleci: test-centos7"
- "status-success=ci/circleci: test-debian9"
- "status-success=ci/circleci: test-ubuntu16"
Expand Down
17 changes: 8 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dist: xenial
language: python
python:
- "3.7"
- "3.8"

cache:
- pip
Expand All @@ -20,25 +20,24 @@ addons:
- bc

env:
# NOTE(kan-bayashi): Use 3.7.3 to avoid sentencepiece installation error
- USE_CONDA=false ESPNET_PYTHON_VERSION=3.7.3 TH_VERSION=1.0.1 CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7
- USE_CONDA=false ESPNET_PYTHON_VERSION=3.7.3 TH_VERSION=1.1.0 CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7
- USE_CONDA=false ESPNET_PYTHON_VERSION=3.8 TH_VERSION=1.4.0 CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7
# torch nightly
- USE_CONDA=false ESPNET_PYTHON_VERSION=3.7.3 TH_VERSION=nightly CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7
# - USE_CONDA=false ESPNET_PYTHON_VERSION=3.7.3 TH_VERSION=nightly CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7

matrix:
allow_failures:
# torch nightly
- env: USE_CONDA=false ESPNET_PYTHON_VERSION=3.7.3 TH_VERSION=nightly CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7
# - env: USE_CONDA=false ESPNET_PYTHON_VERSION=3.7.3 TH_VERSION=nightly CHAINER_VERSION=6.0.0 CC=gcc-7 CXX=g++-7

install:
- travis_retry ./ci/install.sh
- travis_retry ./ci/install_kaldi.sh
# - travis_retry ./ci/install_kaldi.sh

script:
- ./ci/test_shell.sh
# NOTE(kamo): Codecov and build documentation only
# - ./ci/test_shell.sh
- ./ci/test_python.sh
- ./ci/test_integration.sh
# - ./ci/test_integration.sh
- ./ci/doc.sh

sudo: false
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@

# ESPnet: end-to-end speech processing toolkit

[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)
[![Build Status](https://travis-ci.org/espnet/espnet.svg?branch=master)](https://travis-ci.org/espnet/espnet)
[![CircleCI](https://circleci.com/gh/espnet/espnet.svg?style=svg)](https://circleci.com/gh/espnet/espnet)
|system/pytorch ver.|1.0.1|1.1.0|1.2.0|1.3.1|1.4.0|
| :---: | :---: | :---: | :---: | :---: | :---: |
|ubuntu18/python3.8/pip|||||[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)|
|ubuntu18/python3.7/pip|[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)|[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)|[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)|[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)|[![Github Actions](https://github.com/espnet/espnet/workflows/CI/badge.svg)](https://github.com/espnet/espnet/actions)|
|ubuntu18/python3.6/conda|||||[![CircleCI](https://circleci.com/gh/espnet/espnet.svg?style=svg)](https://circleci.com/gh/espnet/espnet)|
|ubuntu16/python3.6/conda|||||[![CircleCI](https://circleci.com/gh/espnet/espnet.svg?style=svg)](https://circleci.com/gh/espnet/espnet)|
|debian9/python3.6/conda|||||[![CircleCI](https://circleci.com/gh/espnet/espnet.svg?style=svg)](https://circleci.com/gh/espnet/espnet)|
|centos7/python3.6/conda|||||[![CircleCI](https://circleci.com/gh/espnet/espnet.svg?style=svg)](https://circleci.com/gh/espnet/espnet)|
|[docs/coverage] python3.8|||||[![Build Status](https://travis-ci.org/espnet/espnet.svg?branch=master)](https://travis-ci.org/espnet/espnet)|

[![codecov](https://codecov.io/gh/espnet/espnet/branch/master/graph/badge.svg)](https://codecov.io/gh/espnet/espnet)
[![Mergify Status](https://img.shields.io/endpoint.svg?url=https://gh.mergify.io/badges/espnet/espnet&style=flat)](https://mergify.io)
[![Gitter](https://badges.gitter.im/espnet-en/community.svg)](https://gitter.im/espnet-en/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
Expand Down
6 changes: 4 additions & 2 deletions ci/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if ${USE_CONDA}; then
if [[ ${TH_VERSION} == nightly ]]; then
conda install -q -y pytorch-nightly-cpu -c pytorch
else
conda install -q -y pytorch-cpu="${TH_VERSION}" -c pytorch
conda install -q -y pytorch="${TH_VERSION}" cpuonly -c pytorch
fi
conda install -c conda-forge ffmpeg
else
Expand All @@ -29,8 +29,10 @@ else

if [[ ${TH_VERSION} == nightly ]]; then
pip install torch_nightly -f https://download.pytorch.org/whl/nightly/cpu/torch_nightly.html
else
elif [[ ${TH_VERSION} == 1.0.1 ]] || [[ ${TH_VERSION} == 1.1.0 ]]; then
pip install --quiet torch=="${TH_VERSION}" -f https://download.pytorch.org/whl/cpu/stable
else
pip install --quiet torch=="${TH_VERSION}+cpu" -f https://download.pytorch.org/whl/torch_stable.html
fi
fi

Expand Down
8 changes: 5 additions & 3 deletions espnet/nets/pytorch_backend/frontends/dnn_beamformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
from espnet.nets.pytorch_backend.frontends.mask_estimator import MaskEstimator
from torch_complex.tensor import ComplexTensor

is_torch_1_2_plus = LooseVersion(torch.__version__) >= LooseVersion('1.2')
is_torch_1_2_plus = LooseVersion(torch.__version__) >= LooseVersion('1.2.0')
is_torch_1_3_plus = LooseVersion(torch.__version__) >= LooseVersion('1.3.0')


class DNN_Beamformer(torch.nn.Module):
Expand Down Expand Up @@ -146,9 +147,10 @@ def forward(self, psd_in: ComplexTensor, ilens: torch.LongTensor,
B, _, C = psd_in.size()[:3]
assert psd_in.size(2) == psd_in.size(3), psd_in.size()
# psd_in: (B, F, C, C)
datatype = torch.bool if is_torch_1_2_plus else torch.uint8
datatype = torch.bool if is_torch_1_3_plus else torch.uint8
datatype2 = torch.bool if is_torch_1_2_plus else torch.uint8
psd = psd_in.masked_fill(torch.eye(C, dtype=datatype,
device=psd_in.device), 0)
device=psd_in.device).type(datatype2), 0)
# psd: (B, F, C, C) -> (B, C, F)
psd = (psd.sum(dim=-1) / (C - 1)).transpose(-1, -2)

Expand Down
2 changes: 1 addition & 1 deletion espnet/nets/pytorch_backend/frontends/mask_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def forward(self, xs: ComplexTensor, ilens: torch.LongTensor) \
# Calculate amplitude: (B, C, T, F) -> (B, C, T, F)
xs = (xs.real ** 2 + xs.imag ** 2) ** 0.5
# xs: (B, C, T, F) -> xs: (B * C, T, F)
xs = xs.view(-1, xs.size(-2), xs.size(-1))
xs = xs.contiguous().view(-1, xs.size(-2), xs.size(-1))
# ilens: (B,) -> ilens_: (B * C)
ilens_ = ilens[:, None].expand(-1, C).contiguous().view(-1)

Expand Down
11 changes: 9 additions & 2 deletions espnet/nets/pytorch_backend/transformer/mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import torch

is_torch_1_2_plus = LooseVersion(torch.__version__) >= LooseVersion('1.2.0')
# LooseVersion('1.2.0') == LooseVersion(torch.__version__) can't include e.g. 1.2.0+aaa
is_torch_1_2 = LooseVersion('1.3') > LooseVersion(torch.__version__) >= LooseVersion('1.2')
datatype = torch.bool if is_torch_1_2_plus else torch.uint8


Expand All @@ -25,8 +27,13 @@ def subsequent_mask(size, device="cpu", dtype=datatype):
[1, 1, 0],
[1, 1, 1]]
"""
ret = torch.ones(size, size, device=device, dtype=dtype)
return torch.tril(ret, out=ret)
if is_torch_1_2 and dtype == torch.bool:
# torch=1.2 doesn't support tril for bool tensor
ret = torch.ones(size, size, device=device, dtype=torch.uint8)
return torch.tril(ret, out=ret).type(dtype)
else:
ret = torch.ones(size, size, device=device, dtype=dtype)
return torch.tril(ret, out=ret)


def target_mask(ys_in_pad, ignore_id):
Expand Down
9 changes: 6 additions & 3 deletions espnet2/torch_utils/recursive_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import torch

if LooseVersion(torch.__version__) > LooseVersion("1.0.1"):
from torch.distributed import ReduceOp
if torch.distributed.is_available():
if LooseVersion(torch.__version__) > LooseVersion("1.0.1"):
from torch.distributed import ReduceOp
else:
from torch.distributed import reduce_op as ReduceOp
else:
from torch.distributed import reduce_op as ReduceOp
ReduceOp = None


def recursive_sum(obj, weight: torch.Tensor, distributed: bool = False):
Expand Down
9 changes: 6 additions & 3 deletions espnet2/train/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@
from torch.utils.tensorboard import SummaryWriter
else:
from tensorboardX import SummaryWriter
if LooseVersion(torch.__version__) > LooseVersion("1.0.1"):
from torch.distributed import ReduceOp
if torch.distributed.is_available():
if LooseVersion(torch.__version__) > LooseVersion("1.0.1"):
from torch.distributed import ReduceOp
else:
from torch.distributed import reduce_op as ReduceOp
else:
from torch.distributed import reduce_op as ReduceOp
ReduceOp = None


@dataclasses.dataclass
Expand Down
4 changes: 1 addition & 3 deletions espnet2/utils/fileio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import collections.abc
from io import StringIO
import logging
Expand Down Expand Up @@ -38,7 +36,7 @@ def __init__(self, p: Union[Path, str]):
def __enter__(self):
return self

def __getitem__(self, key: str) -> DatadirWriter:
def __getitem__(self, key: str) -> "DatadirWriter":
assert check_argument_types()
if self.fd is not None:
raise RuntimeError("This writer points out a file")
Expand Down
2 changes: 1 addition & 1 deletion test/espnet2/utils/test_sized_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

def test_get_size():
d = {}
size1 = get_size(d)
x = np.random.randn(10)
d["a"] = x
size1 = sys.getsizeof(d)
assert size1 + get_size(x) + get_size("a") == get_size(d)


Expand Down
17 changes: 10 additions & 7 deletions test/test_recog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
# Copyright 2018 Hiroshi Seki
# Apache 2.0 (http://www.apache.org/licenses/LICENSE-2.0)

import torch
import argparse
from distutils.version import LooseVersion
import importlib

import espnet.nets.pytorch_backend.lm.default as lm_pytorch
import numpy
import pytest
import torch

import espnet.lm.chainer_backend.lm as lm_chainer
import espnet.lm.pytorch_backend.extlm as extlm_pytorch
import espnet.nets.pytorch_backend.lm.default as lm_pytorch

import argparse
import importlib
import numpy

import pytest
is_torch_1_2_plus = LooseVersion(torch.__version__) >= LooseVersion('1.2.0')


def make_arg(**kwargs):
Expand Down Expand Up @@ -80,6 +81,7 @@ def init_chainer_weight_const(m, val):
p.data[:] = val


@pytest.mark.skipif(is_torch_1_2_plus, reason='pytestskip')
@pytest.mark.parametrize(("etype", "dtype", "m_str", "text_idx1"), [
("blstmp", "lstm", "espnet.nets.chainer_backend.e2e_asr", 0),
("blstmp", "lstm", "espnet.nets.pytorch_backend.e2e_asr", 1),
Expand Down Expand Up @@ -130,6 +132,7 @@ def test_recognition_results(etype, dtype, m_str, text_idx1):
assert seq_hat_text == seq_true_text


@pytest.mark.skipif(is_torch_1_2_plus, reason='pytestskip')
@pytest.mark.parametrize(("etype", "dtype", "m_str", "text_idx1"), [
("blstmp", "lstm", "espnet.nets.chainer_backend.e2e_asr", 0),
("blstmp", "lstm", "espnet.nets.pytorch_backend.e2e_asr", 1),
Expand Down
Loading

0 comments on commit 7825783

Please sign in to comment.