Skip to content

Commit

Permalink
Support --context-size=1 (#565)
Browse files Browse the repository at this point in the history
When --context-size is 1, there is no conv module at all.
  • Loading branch information
csukuangfj authored Apr 8, 2024
1 parent f01690b commit 98f9429
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sherpa/csrc/online-lstm-transducer-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ OnlineLstmTransducerModel::OnlineLstmTransducerModel(
joiner_.eval();

context_size_ =
decoder_.attr("conv").toModule().attr("weight").toTensor().size(2);
decoder_.hasattr("conv")
? decoder_.attr("conv").toModule().attr("weight").toTensor().size(2)
: 1;

// Use 5 here since the subsampling is ((len - 3) // 2 - 1) // 2.
int32_t pad_length = 5;
Expand Down
4 changes: 3 additions & 1 deletion sherpa/csrc/online-zipformer-transducer-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ OnlineZipformerTransducerModel::OnlineZipformerTransducerModel(
joiner_.eval();

context_size_ =
decoder_.attr("conv").toModule().attr("weight").toTensor().size(2);
decoder_.hasattr("conv")
? decoder_.attr("conv").toModule().attr("weight").toTensor().size(2)
: 1;

// Use 7 here since the subsampling is ((len - 7) // 2 + 1) // 2.
int32_t pad_length = 7;
Expand Down
4 changes: 3 additions & 1 deletion sherpa/csrc/online-zipformer2-transducer-model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ OnlineZipformer2TransducerModel::OnlineZipformer2TransducerModel(
joiner_ = model_.attr("joiner").toModule();

context_size_ =
decoder_.attr("conv").toModule().attr("weight").toTensor().size(2);
decoder_.hasattr("conv")
? decoder_.attr("conv").toModule().attr("weight").toTensor().size(2)
: 1;

int32_t pad_length = encoder_.attr("pad_length").toInt();

Expand Down

0 comments on commit 98f9429

Please sign in to comment.