Skip to content

Commit 6948c56

Browse files
committed
[fix] address linting errors reported by quick-checks
1 parent 6d925c9 commit 6948c56

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

examples/librispeech/s0/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ test other
365365
* dynamic batch size 120.000, 2 gpu, acc_grad 4, 200 epochs, dither 1.0
366366
* adamw, lr 1e-3, warmuplr, warmup_steps: 25000
367367
* specaug and speed perturb
368-
* Decoding info:
368+
* Decoding info:
369369
* ctc_weight 0.3, reverse weight 0.5, average_num 100, beam size 10
370370
* Chunk size, left context size, and right context size are represented as (c, l, r)
371371
* Results on test-clean / test other

wenet/chunkformer/attention.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def __init__(self, n_head, n_feat, dropout_rate):
2828
torch.nn.init.xavier_uniform_(self.pos_bias_v)
2929

3030
def rel_shift(self, x, left_context_size: int = 0, right_context_size: int = 0):
31-
"""Compute relative positional encoding. The position should capture both
31+
"""Compute relative positional encoding. The position should capture both
3232
left and right context.
3333
3434
Args:
@@ -88,8 +88,8 @@ def forward(self, query: torch.Tensor,
8888
q, k, v = self.forward_qkv(query, key, value)
8989
q = q.transpose(1, 2) # (batch, time1, head, d_k)
9090

91-
limited_context_attn = (chunk_size > 0
92-
and left_context_size > 0
91+
limited_context_attn = (chunk_size > 0
92+
and left_context_size > 0
9393
and right_context_size > 0)
9494

9595
# NOTE(xcsong):
@@ -121,7 +121,7 @@ def forward(self, query: torch.Tensor,
121121
# chunking query
122122
# [B, time1, head, d_k]
123123
q_size = q.size(1)
124-
n_frames_pad = (chunk_size - ((q_size - chunk_size) % chunk_size))
124+
n_frames_pad = (chunk_size - ((q_size - chunk_size) % chunk_size))
125125
n_frames_pad = n_frames_pad % chunk_size
126126
q = torch.nn.functional.pad(q, (0, 0, 0, 0, 0, n_frames_pad))
127127
# [B, n_chunks, head, d_k, q_size]
@@ -135,12 +135,12 @@ def forward(self, query: torch.Tensor,
135135
# (batch, head, time1, d_k * 2)
136136
kv = torch.cat([k, v], dim=-1)
137137
kv = torch.nn.functional.pad(
138-
kv,
138+
kv,
139139
(0, 0, left_context_size, n_frames_pad + right_context_size))
140140
# [B, head, n_chunks, d_k * 2, l + c + r]
141141
kv = kv.unfold(
142-
2,
143-
size=left_context_size + chunk_size + right_context_size,
142+
2,
143+
size=left_context_size + chunk_size + right_context_size,
144144
step=chunk_size)
145145
# [B, n_chunks, head, l + c + r, d_k * 2]
146146
kv = kv.permute(0, 2, 1, 4, 3)
@@ -158,12 +158,12 @@ def forward(self, query: torch.Tensor,
158158

159159
# Chunking mask for key and value
160160
mask_kv = torch.nn.functional.pad(
161-
mask,
161+
mask,
162162
(left_context_size, n_frames_pad + right_context_size))
163163
# [B, 1, n_chunks, chunk_size]
164164
mask_kv = mask_kv.unfold(
165-
-1,
166-
size=left_context_size + chunk_size + right_context_size,
165+
-1,
166+
size=left_context_size + chunk_size + right_context_size,
167167
step=chunk_size)
168168
# [B, * n_chunks, chunk_size]
169169
mask_kv = mask_kv.reshape(-1, mask_kv.size(3))

wenet/chunkformer/embedding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def forward(
109109
pos_emb = self.position_encoding(
110110
chunk_size=chunk_size,
111111
left_context_size=left_context_size,
112-
right_context_size=right_context_size,
112+
right_context_size=right_context_size,
113113
apply_dropout=False
114114
).to(device=x.device, dtype=x.dtype)
115115
return self.dropout(x), self.dropout(pos_emb)

wenet/chunkformer/encoder.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ def __init__(
183183

184184
def limited_context_selection(self):
185185
full_context_training = True
186-
if (self.dynamic_chunk_sizes is not None
187-
and self.dynamic_left_context_sizes is not None
186+
if (self.dynamic_chunk_sizes is not None
187+
and self.dynamic_left_context_sizes is not None
188188
and self.dynamic_right_context_sizes is not None):
189189
chunk_size = random.choice(self.dynamic_chunk_sizes)
190190
left_context_size = random.choice(self.dynamic_left_context_sizes)
@@ -274,12 +274,12 @@ def forward(self,
274274
Main forward function that dispatches to either the standard
275275
forward pass or the parallel chunk version based on the
276276
model's training mode.
277-
"""
277+
"""
278278
# for masked batch chunk context inference
279279
# should add a better flag to trigger
280280
if decoding_chunk_size > 0 and num_decoding_left_chunks > 0:
281281
# If both decoding_chunk_size and num_decoding_left_chunks
282-
# are set, use the parallel chunk decoding.
282+
# are set, use the parallel chunk decoding.
283283
return self.forward_parallel_chunk(
284284
xs=xs,
285285
xs_origin_lens=xs_lens,
@@ -290,8 +290,8 @@ def forward(self,
290290
**kwargs
291291
)
292292
else:
293-
(chunk_size,
294-
left_context_size,
293+
(chunk_size,
294+
left_context_size,
295295
right_context_size) = self.limited_context_selection()
296296
return self.forward_encoder(
297297
xs=xs,

wenet/chunkformer/subsampling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ def forward(self,
169169
else:
170170
x = x.transpose(1, 2)
171171
x, pos_emb = self.pos_enc(
172-
x,
173-
chunk_size=chunk_size,
172+
x,
173+
chunk_size=chunk_size,
174174
left_context_size=left_context_size,
175175
right_context_size=right_context_size)
176176
mask = ~make_pad_mask(lengths, x.size(1)).unsqueeze(1)

0 commit comments

Comments
 (0)