Fix encoder causality in TransformerASR (see issue #2182) - #2262
Merged
Merged
Conversation
Collaborator
|
I will take a look when I have some time. I'll try to use some of my streaming check tools to see if there isn't any further bug in causal mode. |
Collaborator
|
We started writing streaming-related things a while back and ended up stopping in the middle because we did not have the resources ... so more things might be missing. Maybe @s1zhang can help a bit as well if he sees weird things while exploring streaming with SB. |
asumagic
approved these changes
Nov 28, 2023
asumagic
left a comment
Collaborator
There was a problem hiding this comment.
Using the following code, with the streaming test functions taken from the streaming PR #2140:
import torch
from speechbrain.lobes.models.transformer.TransformerASR import TransformerASR
from speechbrain.utils.streaming import infer_dependency_matrix, plot_dependency_matrix
from matplotlib import pyplot as plt
model = TransformerASR(
tgt_vocab=100,
input_size=32,
d_model=64,
nhead=4,
num_encoder_layers=2,
num_decoder_layers=2,
d_ffn=64*4,
causal=True
)
model.eval()
input_shape = (4, 50, 32) # (batch_size, seq_len, input_size)
with torch.no_grad():
dep_matrix = infer_dependency_matrix(model.encode, seq_shape=input_shape)
plot_dependency_matrix(dep_matrix)
plt.show()I can confirm that TransformerASR.encode looks to be truly causal now. This is not the case if I do not use the causal fixes from this PR.
Collaborator
Collaborator
|
Thank you @lucadellalib for the fix and @asumagic for the review! |
This was referenced Jul 10, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


No description provided.