From 0ed682f20485b10fef6f07450c170ec415548e9d Mon Sep 17 00:00:00 2001 From: Takaaki-Saeki Date: Tue, 24 Oct 2023 15:27:25 +0900 Subject: [PATCH 1/3] Fix fairseq_alt to be compatible with older python versions --- speechmos/utmos22/fairseq_alt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/speechmos/utmos22/fairseq_alt.py b/speechmos/utmos22/fairseq_alt.py index d9702a5..283a94d 100644 --- a/speechmos/utmos22/fairseq_alt.py +++ b/speechmos/utmos22/fairseq_alt.py @@ -1,6 +1,7 @@ """W2V2 model optimized to UTMOS22 strong learner inference. Origin cloned from FairSeq under MIT license (Copyright Facebook, Inc. and its affiliates., https://github.com/facebookresearch/fairseq/blob/main/LICENSE).""" import math +from typing import List, Tuple, Optional import torch from torch import nn, Tensor @@ -43,7 +44,7 @@ def forward(self, source: Tensor): class ConvFeatureExtractionModel(nn.Module): """Feature Encoder.""" - def __init__(self, conv_layers: list[tuple[int, int, int]]): + def __init__(self, conv_layers: List[Tuple[int, int, int]]): super().__init__() # pyright: ignore [reportUnknownMemberType] def block(n_in: int, n_out: int, k: int, stride: int, is_group_norm: bool = False): @@ -137,7 +138,7 @@ def forward(self, x: Tensor) -> Tensor: return x[:, :, : -1] -def pad_to_multiple(x: Tensor | None, multiple: int, dim: int = -1, value: float = 0) -> tuple[Tensor | None, int]: +def pad_to_multiple(x: Optional[Tensor], multiple: int, dim: int = -1, value: float = 0) -> Tuple[Optional[Tensor], int]: """Tail padding.""" # Inspired from https://github.com/lucidrains/local-attention/blob/master/local_attention/local_attention.py#L41 if x is None: @@ -182,7 +183,7 @@ def __init__( self.self_attn_layer_norm = nn.LayerNorm(feat) self.final_layer_norm = nn.LayerNorm(feat) - def forward(self, x: Tensor, self_attn_padding_mask: Tensor | None): + def forward(self, x: Tensor, self_attn_padding_mask: Optional[Tensor]): # Res[Attn-Do]-LN residual = x x = self.self_attn(x, x, x, self_attn_padding_mask) @@ -214,7 +215,7 @@ def __init__(self, embed_dim: int, num_heads: int, dropout: float): self.v_proj = nn.Linear(embed_dim, embed_dim, bias=True) self.out_proj = nn.Linear(embed_dim, embed_dim, bias=True) - def forward(self, query: Tensor, key: Tensor, value: Tensor, key_padding_mask: Tensor | None) -> Tensor: + def forward(self, query: Tensor, key: Tensor, value: Tensor, key_padding_mask: Optional[Tensor]) -> Tensor: """ Args: query :: (T, B, Feat) From eff802b379069fc6bc0b0e9f4eaad2d04ac5e199 Mon Sep 17 00:00:00 2001 From: Takaaki-Saeki Date: Tue, 24 Oct 2023 16:19:35 +0900 Subject: [PATCH 2/3] add ci-related files --- .devcontainer/Dockerfile | 2 +- .github/workflows/test.yml | 32 ++++++++++++++++---------------- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index a685c31..67645c3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,5 @@ # derived from Microsoft Python dev container (https://github.com/microsoft/vscode-dev-containers/tree/main/containers/python-3) -FROM mcr.microsoft.com/vscode/devcontainers/python:3.10 +FROM mcr.microsoft.com/vscode/devcontainers/python:3.8 # Colab versions @2023-05-06 # Python: 3.10.11 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3313cc0..445cb24 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,19 +31,19 @@ jobs: run: | pytest - # test-py308: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v3 - # - name: Set up Python 3.8 - # uses: actions/setup-python@v3 - # with: - # python-version: "3.8" - # - name: Install dependencies - # run: | - # python -m pip install --upgrade pip - # pip install pytest - # pip install torch==2.0.0+cpu torchaudio==2.0.1+cpu -f https://download.pytorch.org/whl/torch_stable.html - # - name: Run tests - # run: | - # pytest \ No newline at end of file + test-py308: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.8 + uses: actions/setup-python@v3 + with: + python-version: "3.8" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + pip install torch==2.0.0+cpu torchaudio==2.0.1+cpu -f https://download.pytorch.org/whl/torch_stable.html + - name: Run tests + run: | + pytest \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 64041a2..3bd2f52 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ readme = "README.md" repository = "https://github.com/tarepan/SpeechMOS" [tool.poetry.dependencies] -python = "^3.10" +python = "^3.8" ## Poetry is not good for version control of PyTorch (it has many many variants for a version, so poetry become confused) ## torch = "2.0.0" ## torchaudio = "2.0.1" From f2c51d57901b339e77937c61545375f54a646596 Mon Sep 17 00:00:00 2001 From: Takaaki-Saeki Date: Tue, 24 Oct 2023 16:38:08 +0900 Subject: [PATCH 3/3] fix import order --- speechmos/utmos22/fairseq_alt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/speechmos/utmos22/fairseq_alt.py b/speechmos/utmos22/fairseq_alt.py index 283a94d..4c0fa5e 100644 --- a/speechmos/utmos22/fairseq_alt.py +++ b/speechmos/utmos22/fairseq_alt.py @@ -1,7 +1,7 @@ """W2V2 model optimized to UTMOS22 strong learner inference. Origin cloned from FairSeq under MIT license (Copyright Facebook, Inc. and its affiliates., https://github.com/facebookresearch/fairseq/blob/main/LICENSE).""" import math -from typing import List, Tuple, Optional +from typing import List, Optional, Tuple import torch from torch import nn, Tensor