Skip to content

Commit

Permalink
[ssl] refine forward args to dict (#2244)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mddct authored Dec 15, 2023
1 parent a1e1ce9 commit 3d73821
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions wenet/ssl/bestrq/bestrq_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Optional, Tuple
from typing import Dict, Optional, Tuple
import torch

from wenet.ssl.bestrq.mask import compute_mask_indices_v2
Expand Down Expand Up @@ -164,11 +164,11 @@ def _reset_parameter(module: torch.nn.Module):

def forward(
self,
xs: torch.Tensor,
xs_lens: torch.Tensor,
text: Optional[torch.Tensor] = None,
text_length: Optional[torch.Tensor] = None,
batch: Dict,
device: torch.device,
):
xs = batch['feats'].to(device)
xs_lens = batch['feats_lengths'].to(device)
# force global cmvn
xs = xs - self.signal_mean
if self.signal_norm_var:
Expand Down
13 changes: 6 additions & 7 deletions wenet/ssl/w2vbert/w2vbert_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Optional, Tuple, Union
from typing import Dict, Optional, Tuple, Union
import torch

from wenet.ssl.bestrq.mask import compute_mask_indices_v2
Expand Down Expand Up @@ -161,13 +161,12 @@ def _reset_parameter(module: torch.nn.Module):
@torch.jit.ignore(drop=True)
def forward(
self,
xs: torch.Tensor,
xs_lens: torch.Tensor,
text: Optional[torch.Tensor] = None,
text_length: Optional[torch.Tensor] = None,
steps: Optional[int] = None,
batch: Dict,
device: torch.device,
):

steps = batch.get('steps', None)
xs = batch['feats'].to(device)
xs_lens = batch['feats_lengths'].to(device)
assert xs.size(0) == xs_lens.size(0)
assert steps is not None

Expand Down
13 changes: 6 additions & 7 deletions wenet/ssl/wav2vec2/wav2vec2_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import math
from typing import Optional, Tuple, Union
from typing import Dict, Optional, Tuple, Union
import torch

import torch.nn.functional as F
Expand Down Expand Up @@ -220,13 +220,12 @@ def _reset_parameter(module: torch.nn.Module):
@torch.jit.ignore(drop=True)
def forward(
self,
xs: torch.Tensor,
xs_lens: torch.Tensor,
text: Optional[torch.Tensor] = None,
text_length: Optional[torch.Tensor] = None,
steps: Optional[int] = None,
batch: Dict,
device: torch.device,
):

steps = batch.get('steps', None)
xs = batch['feats'].to(device)
xs_lens = batch['feats_lengths'].to(device)
assert xs.size(0) == xs_lens.size(0)
assert steps is not None

Expand Down

0 comments on commit 3d73821

Please sign in to comment.