This is a
4-bit quantized version of
VibeVoice 7B using bitsandbytes NF4 quantization.
1pip install transformers bitsandbytes torch torchaudio
2pip install git+https://github.com/vibevoice-community/VibeVoice.git
1import torch
2from transformers import BitsAndBytesConfig
3from vibevoice.modular.modeling_vibevoice_inference import VibeVoiceForConditionalGenerationInference
4from vibevoice.processor.vibevoice_processor import VibeVoiceProcessor
5
6# Load quantized model
7model_id = "marksverdhai/vibevoice-7b-bnb-4bit"
8
9bnb_config = BitsAndBytesConfig(
10 load_in_4bit=True,
11 bnb_4bit_compute_dtype=torch.bfloat16,
12 bnb_4bit_use_double_quant=True,
13 bnb_4bit_quant_type="nf4",
14)
15
16model = VibeVoiceForConditionalGenerationInference.from_pretrained(
17 model_id,
18 device_map={"": 0}, # Load on GPU 0
19 quantization_config=bnb_config,
20 torch_dtype=torch.bfloat16,
21)
22processor = VibeVoiceProcessor.from_pretrained(model_id)
23
24model.eval()
25model.set_ddpm_inference_steps(num_steps=10)
26
27# Generate speech
28text = "Speaker 1: Hello! This is VibeVoice, a state-of-the-art text-to-speech model."
29
30inputs = processor(
31 text=[text],
32 padding=True,
33 return_tensors="pt",
34 return_attention_mask=True,
35)
36inputs = {k: v.to("cuda") for k, v in inputs.items() if torch.is_tensor(v)}
37
38with torch.no_grad():
39 outputs = model.generate(
40 **inputs,
41 max_new_tokens=None,
42 cfg_scale=1.3,
43 tokenizer=processor.tokenizer,
44 generation_config={"do_sample": False},
45 verbose=False,
46 is_prefill=False,
47 )
48
49# Get audio
50audio = outputs.speech_outputs[0].squeeze().cpu()
51sample_rate = 24000
52
53# Save to file
54import torchaudio
55torchaudio.save("output.wav", audio.unsqueeze(0), sample_rate)
1# With voice reference
2inputs = processor(
3 text=["Speaker 1: Hello, I can clone any voice!"],
4 voice_samples=[["path/to/reference.wav"]],
5 padding=True,
6 return_tensors="pt",
7 return_attention_mask=True,
8)
9inputs = {k: v.to("cuda") for k, v in inputs.items() if torch.is_tensor(v)}
10
11with torch.no_grad():
12 outputs = model.generate(
13 **inputs,
14 cfg_scale=1.3,
15 tokenizer=processor.tokenizer,
16 is_prefill=True, # Enable voice cloning
17 )
The quantization is applied to the Qwen2 LLM backbone while preserving full precision for:
1@misc{vibevoice2024,
2 title={VibeVoice: Emotion-Aware Text-to-Speech},
3 author={VibeVoice Team},
4 year={2024},
5 url={https://github.com/vibevoice-community/VibeVoice}
6}