Skip to content

Commit

Permalink
Minor fixes for torch.jit.script support (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
JinZr authored Oct 23, 2023
1 parent 902dc23 commit 92ef561
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions egs/aishell/ASR/transducer_stateless/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def __init__(
groups=embedding_dim,
bias=False,
)
else:
# To avoid `RuntimeError: Module 'Decoder' has no attribute 'conv'`
# when inference with torch.jit.script and context_size == 1
self.conv = nn.Identity()

def forward(self, y: torch.Tensor, need_pad: bool = True) -> torch.Tensor:
"""
Expand Down
4 changes: 4 additions & 0 deletions egs/libriheavy/ASR/zipformer_prompt_asr/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ def __init__(
max_abs=1.0,
prob=0.05,
)
else:
# To avoid `RuntimeError: Module 'Decoder' has no attribute 'conv'`
# when inference with torch.jit.script and context_size == 1
self.conv = nn.Identity()

def forward(self, y: torch.Tensor, need_pad: bool = True) -> torch.Tensor:
"""
Expand Down
4 changes: 4 additions & 0 deletions egs/librispeech/ASR/pruned_transducer_stateless/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def __init__(
groups=embedding_dim,
bias=False,
)
else:
# To avoid `RuntimeError: Module 'Decoder' has no attribute 'conv'`
# when inference with torch.jit.script and context_size == 1
self.conv = nn.Identity()
self.output_linear = nn.Linear(embedding_dim, vocab_size)

def forward(self, y: torch.Tensor, need_pad: bool = True) -> torch.Tensor:
Expand Down
4 changes: 4 additions & 0 deletions egs/librispeech/ASR/transducer_stateless/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ def __init__(
groups=embedding_dim,
bias=False,
)
else:
# To avoid `RuntimeError: Module 'Decoder' has no attribute 'conv'`
# when inference with torch.jit.script and context_size == 1
self.conv = nn.Identity()

def forward(self, y: torch.Tensor, need_pad: bool = True) -> torch.Tensor:
"""
Expand Down
5 changes: 4 additions & 1 deletion egs/librispeech/ASR/zipformer/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import torch
import torch.nn as nn
import torch.nn.functional as F

from scaling import Balancer


Expand Down Expand Up @@ -95,6 +94,10 @@ def __init__(
max_abs=1.0,
prob=0.05,
)
else:
# To avoid `RuntimeError: Module 'Decoder' has no attribute 'conv'`
# when inference with torch.jit.script and context_size == 1
self.conv = nn.Identity()

def forward(self, y: torch.Tensor, need_pad: bool = True) -> torch.Tensor:
"""
Expand Down

0 comments on commit 92ef561

Please sign in to comment.