-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Audio streaming training with masking (#148)
* Audio streaming training with masking * ultravox_model test --------- Co-authored-by: Farzad Abdolhosseini <[email protected]>
- Loading branch information
1 parent
3866fd7
commit 9fc2732
Showing
6 changed files
with
156 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import pytest | ||
import torch | ||
from transformers import WhisperConfig | ||
|
||
from ultravox.model import ultravox_model | ||
|
||
|
||
@pytest.fixture | ||
def encoder(): | ||
config = WhisperConfig( | ||
max_source_positions=1500, | ||
d_model=256, | ||
encoder_attention_heads=4, | ||
encoder_layers=4, | ||
) | ||
return ultravox_model.ModifiedWhisperEncoder(config) | ||
|
||
|
||
def test_init_latency_mask_none(encoder): | ||
encoder.init_latency_mask(None, torch.float32) | ||
assert encoder.audio_streaming_mask is None | ||
|
||
|
||
def test_init_latency_mask_valid(encoder): | ||
block_size = 100 | ||
encoder.init_latency_mask(block_size, torch.float32) | ||
assert encoder.audio_streaming_mask is not None | ||
|
||
assert len(encoder.audio_streaming_mask.shape) == 4 | ||
assert encoder.audio_streaming_mask.shape[0] == 1 | ||
assert encoder.audio_streaming_mask.shape[1] == 1 | ||
|
||
mask = encoder.audio_streaming_mask[0, 0] | ||
# 100*30=3000 | ||
source_mask = ( | ||
torch.tril(torch.ones(30, 30), diagonal=0) | ||
.repeat_interleave(block_size, dim=0) | ||
.repeat_interleave(block_size, dim=1) | ||
) | ||
source_mask = (1.0 - source_mask) * torch.finfo(torch.float32).min | ||
print(mask.shape) | ||
assert torch.allclose(mask, source_mask) | ||
|
||
|
||
def test_init_latency_mask_invalid_block_size(encoder): | ||
invalid_block_size = 13 | ||
|
||
with pytest.raises(AssertionError, match="must divide .* evenly"): | ||
encoder.init_latency_mask(invalid_block_size, torch.float32) | ||
|
||
|
||
def test_init_latency_mask_different_dtypes(encoder): | ||
block_size = 50 | ||
for dtype in (torch.float32, torch.float16): | ||
encoder.init_latency_mask(block_size, dtype) | ||
assert encoder.audio_streaming_mask.min() == torch.finfo(dtype).min | ||
|
||
|
||
def test_init_latency_mask_persistence(encoder): | ||
block_size = 50 | ||
encoder.init_latency_mask(block_size, torch.float32) | ||
assert "audio_streaming_mask" in encoder._buffers |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
exp_name: "ultravox-streaming-experiments-1s" | ||
# Make sure to accept the license agreement on huggingface hub | ||
text_model: "meta-llama/Llama-3.2-1B-Instruct" | ||
audio_model: "openai/whisper-small" | ||
loss_config: | ||
# Choose from ["KL_Divergence", "CrossEntropy"], default is "KL_Divergence" | ||
loss_function: "KL_Divergence" | ||
train_sets: | ||
- name: librispeech-clean-continuation | ||
- name: librispeech-other-continuation | ||
- name: peoplespeech-clean-continuation | ||
weight: 4 | ||
- name: commonvoice-en-continuation | ||
weight: 4 | ||
- name: librispeech-clean-transcription | ||
weight: 4 | ||
- name: librispeech-other-transcription | ||
- name: peoplespeech-clean-transcription | ||
- name: commonvoice-en-transcription | ||
# Temporarily remove heysquad_human from val_sets as it causes the training to fail. | ||
val_sets: | ||
- name: peoplespeech | ||
batch_size: 24 | ||
max_steps: 10000 # x8x24 = 2,764,800 | ||
audio_latency_block_size: 100 # null for non-causal, 100 for 1s, 200 for 2s, and so on. |
This file contains 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