Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions extension/audio/mel_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,15 @@ def export_processor(model=None, output_file="whisper_preprocess.pte"):
if model is None:
model = WhisperAudioProcessor()

audio_tensor = torch.randn(93680)
if model.streaming:
# Streaming processes small windows per step. 2 seconds gives
# comfortable headroom while keeping the memory plan tight.
max_samples = 2 * model.sampling_rate
else:
max_samples = model.max_audio_len * model.sampling_rate
audio_tensor = torch.randn(min(93680, max_samples))
shapes_collection = torch.export.ShapesCollection()
max_n_chunks = int(model.max_audio_len * model.n_samples)
shapes_collection[audio_tensor] = {0: Dim.DYNAMIC(max=max_n_chunks)}
shapes_collection[audio_tensor] = {0: Dim.DYNAMIC(max=max_samples)}
with torch.no_grad(), torch.fx.experimental._config.patch(
backed_size_oblivious=True
):
Expand Down
Loading