Views
No views yet

pip install "transformers>=5.3.0"1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4processor = AutoProcessor.from_pretrained(model_id)
5model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id)1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4processor = AutoProcessor.from_pretrained(model_id)
5model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, device_map="auto")
6print(f"Model loaded on {model.device} with dtype {model.dtype}")
7
8# Prepare inputs using `apply_transcription_request`
9inputs = processor.apply_transcription_request(
10 audio="https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/example_output/VibeVoice-1.5B_output.wav",
11).to(model.device, model.dtype)
12
13# Apply model
14output_ids = model.generate(**inputs)
15generated_ids = output_ids[:, inputs["input_ids"].shape[1] :]
16transcription = processor.decode(generated_ids)[0]
17print("\n" + "=" * 60)
18print("RAW OUTPUT")
19print("=" * 60)
20print(transcription)
21
22transcription = processor.decode(generated_ids, return_format="parsed")[0]
23print("\n" + "=" * 60)
24print("TRANSCRIPTION (list of dicts)")
25print("=" * 60)
26for speaker_transcription in transcription:
27 print(speaker_transcription)
28
29# Remove speaker labels, only get raw transcription
30transcription = processor.decode(generated_ids, return_format="transcription_only")[0]
31print("\n" + "=" * 60)
32print("TRANSCRIPTION ONLY")
33print("=" * 60)
34print(transcription)
35
36"""
37============================================================
38RAW OUTPUT
39============================================================
40<|im_start|>assistant
41[{"Start":0,"End":15.43,"Speaker":0,"Content":"Hello everyone and welcome to the Vibe Voice podcast. I'm your host, Alex, and today we're getting into one of the biggest debates in all of sports: who's the greatest basketball player of all time? I'm so excited to have Sam here to talk about it with me."},{"Start":15.43,"End":21.05,"Speaker":1,"Content":"Thanks so much for having me, Alex. And you're absolutely right. This question always brings out some seriously strong feelings."},{"Start":21.05,"End":31.66,"Speaker":0,"Content":"Okay, so let's get right into it. For me, it has to be Michael Jordan. Six trips to the finals, six championships. That kind of perfection is just incredible."},{"Start":31.66,"End":40.93,"Speaker":1,"Content":"Oh man, the first thing that always pops into my head is that shot against the Cleveland Cavaliers back in '89. Jordan just rises, hangs in the air forever, and just sinks it."}]<|im_end|>
42<|endoftext|>
43
44============================================================
45TRANSCRIPTION (list of dicts)
46============================================================
47{'Start': 0, 'End': 15.43, 'Speaker': 0, 'Content': "Hello everyone and welcome to the Vibe Voice podcast. I'm your host, Alex, and today we're getting into one of the biggest debates in all of sports: who's the greatest basketball player of all time? I'm so excited to have Sam here to talk about it with me."}
48{'Start': 15.43, 'End': 21.05, 'Speaker': 1, 'Content': "Thanks so much for having me, Alex. And you're absolutely right. This question always brings out some seriously strong feelings."}
49{'Start': 21.05, 'End': 31.66, 'Speaker': 0, 'Content': "Okay, so let's get right into it. For me, it has to be Michael Jordan. Six trips to the finals, six championships. That kind of perfection is just incredible."}
50{'Start': 31.66, 'End': 40.93, 'Speaker': 1, 'Content': "Oh man, the first thing that always pops into my head is that shot against the Cleveland Cavaliers back in '89. Jordan just rises, hangs in the air forever, and just sinks it."}
51
52============================================================
53TRANSCRIPTION ONLY
54============================================================
55Hello everyone and welcome to the Vibe Voice podcast. I'm your host, Alex, and today we're getting into one of the biggest debates in all of sports: who's the greatest basketball player of all time? I'm so excited to have Sam here to talk about it with me. Thanks so much for having me, Alex. And you're absolutely right. This question always brings out some seriously strong feelings. Okay, so let's get right into it. For me, it has to be Michael Jordan. Six trips to the finals, six championships. That kind of perfection is just incredible. Oh man, the first thing that always pops into my head is that shot against the Cleveland Cavaliers back in '89. Jordan just rises, hangs in the air forever, and just sinks it.
56"""return_format="parsed" tries to return the generated output as a list of dicts, while return_format="transcription_only" tries to extract only the transcribed audio. If they fail, the generated output is returned as-is.1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4processor = AutoProcessor.from_pretrained(model_id)
5model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, device_map="auto")
6print(f"Model loaded on {model.device} with dtype {model.dtype}")
7
8# Without context
9inputs = processor.apply_transcription_request(
10 audio="https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
11).to(model.device, model.dtype)
12output_ids = model.generate(**inputs)
13generated_ids = output_ids[:, inputs["input_ids"].shape[1] :]
14transcription = processor.decode(generated_ids, return_format="transcription_only")[0]
15print(f"WITHOUT CONTEXT: {transcription}")
16
17# With context
18inputs = processor.apply_transcription_request(
19 audio="https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
20 prompt="About VibeVoice",
21).to(model.device, model.dtype)
22output_ids = model.generate(**inputs)
23generated_ids = output_ids[:, inputs["input_ids"].shape[1] :]
24transcription = processor.decode(generated_ids, return_format="transcription_only")[0]
25print(f"WITH CONTEXT : {transcription}")
26
27"""
28WITHOUT CONTEXT: Revevoices is a novel framework designed for generating expressive, long-form, multi-speaker conversational audio.
29WITH CONTEXT : VibeVoice is this novel framework designed for generating expressive, long-form, multi-speaker, conversational audio.
30"""1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4audio = [
5 "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
6 "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/example_output/VibeVoice-1.5B_output.wav"
7]
8prompts = ["About VibeVoice", None]
9
10processor = AutoProcessor.from_pretrained(model_id)
11model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, device_map="auto")
12print(f"Model loaded on {model.device} with dtype {model.dtype}")
13
14inputs = processor.apply_transcription_request(audio, prompt=prompts).to(model.device, model.dtype)
15output_ids = model.generate(**inputs)
16generated_ids = output_ids[:, inputs["input_ids"].shape[1] :]
17transcription = processor.decode(generated_ids, return_format="transcription_only")
18
19print(transcription)tokenizer_chunk_size argument passed to generate can be adjusted. Note it should be a multiple of the hop length (3200 for the original acoustic tokenizer).1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3tokenizer_chunk_size = 64000 # default is 1440000 (60s @ 24kHz)
4model_id = "microsoft/VibeVoice-ASR-HF"
5audio = [
6 "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
7 "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/example_output/VibeVoice-1.5B_output.wav"
8]
9prompts = ["About VibeVoice", None]
10
11processor = AutoProcessor.from_pretrained(model_id)
12model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, device_map="auto")
13print(f"Model loaded on {model.device} with dtype {model.dtype}")
14
15inputs = processor.apply_transcription_request(audio, prompt=prompts).to(model.device, model.dtype)
16output_ids = model.generate(**inputs, tokenizer_chunk_size=tokenizer_chunk_size)
17generated_ids = output_ids[:, inputs["input_ids"].shape[1] :]
18transcription = processor.decode(generated_ids, return_format="transcription_only")
19print(transcription)apply_transcription_request is actually a wrapper for apply_chat_template for convenience):1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4processor = AutoProcessor.from_pretrained(model_id)
5model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, device_map="auto")
6
7chat_template = [
8 [
9 {
10 "role": "user",
11 "content": [
12 {"type": "text", "text": "About VibeVoice"},
13 {
14 "type": "audio",
15 "path": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
16 },
17 ],
18 }
19 ],
20 [
21 {
22 "role": "user",
23 "content": [
24 {
25 "type": "audio",
26 "path": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/example_output/VibeVoice-1.5B_output.wav",
27 },
28 ],
29 }
30 ],
31]
32
33inputs = processor.apply_chat_template(
34 chat_template,
35 tokenize=True,
36 return_dict=True,
37).to(model.device, model.dtype)
38
39output_ids = model.generate(**inputs)
40generated_ids = output_ids[:, inputs["input_ids"].shape[1] :]
41transcription = processor.decode(generated_ids, return_format="transcription_only")
42print(transcription)1from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4processor = AutoProcessor.from_pretrained(model_id)
5model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, device_map="auto")
6model.train()
7
8# Prepare batch of 2
9# -- NOTE: the original model is trained to output transcription, speaker ID, and timestamps in JSON-like format. Below we are only using the transcription text as the label
10chat_template = [
11 [
12 {
13 "role": "user",
14 "content": [
15 {"type": "text", "text": "VibeVoice is this novel framework designed for generating expressive, long-form, multi-speaker, conversational audio."},
16 {
17 "type": "audio",
18 "path": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
19 },
20 ],
21 }
22 ],
23 [
24 {
25 "role": "user",
26 "content": [
27 {"type": "text", "text": "Hello everyone and welcome to the VibeVoice podcast. I'm your host, Alex, and today we're getting into one of the biggest debates in all of sports: who's the greatest basketball player of all time? I'm so excited to have Sam here to talk about it with me. Thanks so much for having me, Alex. And you're absolutely right. This question always brings out some seriously strong feelings. Okay, so let's get right into it. For me, it has to be Michael Jordan. Six trips to the finals, six championships. That kind of perfection is just incredible. Oh man, the first thing that always pops into my head is that shot against the Cleveland Cavaliers back in '89. Jordan just rises, hangs in the air forever, and just sinks it."},
28 {
29 "type": "audio",
30 "path": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/example_output/VibeVoice-1.5B_output.wav",
31 },
32 ],
33 }
34 ],
35]
36inputs = processor.apply_chat_template(
37 chat_template,
38 tokenize=True,
39 return_dict=True,
40 output_labels=True,
41).to(model.device, model.dtype)
42
43loss = model(**inputs).loss
44print("Loss:", loss.item())
45loss.backward()1import time
2import torch
3from transformers import AutoProcessor, VibeVoiceAsrForConditionalGeneration
4
5model_id = "microsoft/VibeVoice-ASR-HF"
6
7num_warmup = 5
8num_runs = 20
9
10# Load processor + model
11processor = AutoProcessor.from_pretrained(model_id)
12model = VibeVoiceAsrForConditionalGeneration.from_pretrained(model_id, torch_dtype=torch.bfloat16,).to("cuda")
13
14# Prepare static inputs
15chat_template = [
16 [
17 {
18 "role": "user",
19 "content": [
20 {
21 "type": "text",
22 "text": "VibeVoice is this novel framework designed for generating expressive, long-form, multi-speaker, conversational audio.",
23 },
24 {
25 "type": "audio",
26 "path": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
27 },
28 ],
29 }
30 ],
31] * 4 # batch size 4
32inputs = processor.apply_chat_template(
33 chat_template,
34 tokenize=True,
35 return_dict=True,
36).to("cuda", torch.bfloat16)
37
38# Benchmark without compile
39print("Warming up without compile...")
40with torch.no_grad():
41 for _ in range(num_warmup):
42 _ = model(**inputs)
43
44torch.cuda.synchronize()
45
46print("\nBenchmarking without torch.compile...")
47torch.cuda.synchronize()
48start = time.time()
49with torch.no_grad():
50 for _ in range(num_runs):
51 _ = model(**inputs)
52torch.cuda.synchronize()
53no_compile_time = (time.time() - start) / num_runs
54print(f"Average time without compile: {no_compile_time:.4f}s")
55
56# Benchmark with compile
57print("\nCompiling model...")
58model = torch.compile(model)
59
60print("Warming up with compile (includes graph capture)...")
61with torch.no_grad():
62 for _ in range(num_warmup):
63 _ = model(**inputs)
64
65torch.cuda.synchronize()
66
67print("\nBenchmarking with torch.compile...")
68torch.cuda.synchronize()
69start = time.time()
70with torch.no_grad():
71 for _ in range(num_runs):
72 _ = model(**inputs)
73torch.cuda.synchronize()
74compile_time = (time.time() - start) / num_runs
75print(f"Average time with compile: {compile_time:.4f}s")
76
77speedup = no_compile_time / compile_time
78print(f"\nSpeedup: {speedup:.2f}x")1from transformers import pipeline
2
3model_id = "microsoft/VibeVoice-ASR-HF"
4pipe = pipeline("any-to-any", model=model_id, device_map="auto")
5chat_template = [
6 {
7 "role": "user",
8 "content": [
9 {"type": "text", "text": "About VibeVoice"},
10 {
11 "type": "audio",
12 "path": "https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav",
13 },
14 ],
15 }
16]
17outputs = pipe(text=chat_template, return_full_text=False)
18
19print("\n" + "=" * 60)
20print("RAW PIPELINE OUTPUT")
21print("=" * 60)
22print(outputs)
23
24"""
25============================================================
26RAW PIPELINE OUTPUT
27============================================================
28[{'input_text': [{'role': 'user', 'content': [{'type': 'text', 'text': 'About VibeVoice'}, {'type': 'audio', 'path': 'https://huggingface.co/datasets/bezzam/vibevoice_samples/resolve/main/realtime_model/vibevoice_tts_german.wav'}]}], 'generated_text': 'assistant\n[{"Start":0.0,"End":7.56,"Speaker":0,"Content":"VibeVoice is this novel framework designed for generating expressive, long-form, multi-speaker conversational audio."}]\n'}]
29"""


| Dataset | WER (%) |
|---|---|
| ami_test | 17.20 |
| earnings22_test | 13.17 |
| gigaspeech_test | 9.67 |
| librispeech_test.clean | 2.20 |
| librispeech_test.other | 5.51 |
| spgispeech_test | 3.80 |
| tedlium_test | 2.57 |
| voxpopuli_test | 8.01 |
| Average | 7.77 |
| RTFx | 51.80 |
