raiseValueError(f"Invalid quantization mode {mode} needs to be one of [int8, int4, int4-gpptq]")
quantize_path=dir_name/new_base_name
print(f"Writing quantized weights to {quantize_path}")
quantize_path.unlink(missing_ok=True)# remove existing file if one already there
torch.save(quantized_state_dict,quantize_path)
print(f"Quantization complete took {time.time()-t0:.02f} seconds")
return
if__name__=='__main__':
importargparse
parser=argparse.ArgumentParser(description='Quantize a model.')
parser.add_argument('--checkpoint_path',type=Path,default=Path("checkpoints/meta-llama/Llama-2-7b-chat-hf/model.pth"),help='Path to the model checkpoint to be quantized.')
parser.add_argument('--mode','-q',type=str,default='int8',choices=['int8','int4','int4-gptq'],help='type of quantization to perform')
parser.add_argument('--groupsize',type=int,default=32,help='Group size for int4 quantization.')
parser.add_argument('--calibration_tasks',type=str,nargs='+',default=['wikitext'],help='tasks to do gptq calibration on, if doing gptq')
parser.add_argument('--calibration_limit',type=int,default=1000,help='number of samples to use for gptq calibration')
parser.add_argument('--calibration_seq_length',type=int,default=100,help='length of sequences to use for gptq calibration')
parser.add_argument('--pad_calibration_inputs',type=bool,default=False,help='pads sequences shorter than calibration_seq_length to that length, yielding more calibration inputs but running much slower')
text_hint+=f"[ERROR] The style {style} is not supported for English, which should be in ['default', 'whispering', 'shouting', 'excited', 'cheerful', 'terrified', 'angry', 'sad', 'friendly']\n"
gr.Warning(f"The style {style} is not supported for English, which should be in ['default', 'whispering', 'shouting', 'excited', 'cheerful', 'terrified', 'angry', 'sad', 'friendly']")
return(
text_hint,
None,
None,
)
speaker_wav=audio_file_pth
iflen(prompt)<2:
text_hint+=f"[ERROR] Please give a longer prompt text \n"
gr.Warning("Please give a longer prompt text")
return(
text_hint,
None,
None,
)
iflen(prompt)>200:
text_hint+=f"[ERROR] Text length limited to 200 characters for this demo, please try shorter text. You can clone our open-source repo and try for your usage \n"
gr.Warning(
"Text length limited to 200 characters for this demo, please try shorter text. You can clone our open-source repo for your usage"
)
return(
text_hint,
None,
None,
)
# note diffusion_conditioning not used on hifigan (default mode), it will be empty but need to pass it to model.inference
We introduce OpenVoice, a versatile instant voice cloning approach that requires only a short audio clip from the reference speaker to replicate their voice and generate speech in multiple languages. OpenVoice enables granular control over voice styles, including emotion, accent, rhythm, pauses, and intonation, in addition to replicating the tone color of the reference speaker. OpenVoice also achieves zero-shot cross-lingual voice cloning for languages not included in the massive-speaker training set.
**Join the Community** | [](https://discord.gg/myshell) |
</div>
"""
content="""
<div>
<strong>If the generated voice does not sound like the reference voice, please refer to <a href='https://github.com/myshell-ai/OpenVoice/blob/main/docs/QA.md'>this QnA</a>.</strong> <strong>For multi-lingual & cross-lingual examples, please refer to <a href='https://github.com/myshell-ai/OpenVoice/blob/main/demo_part2.ipynb'>this jupyter notebook</a>.</strong>
This online demo mainly supports <strong>English</strong>. The <em>default</em> style also supports <strong>Chinese</strong>. But OpenVoice can adapt to any other language as long as a base speaker is provided.
"This audio is generated by open voice with a half-performance model.",
'whispering',
"resources/demo_speaker2.mp3",
True,
],
[
"He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick, peppered, flour-fattened sauce.",
info="One or two sentences at a time is better. Up to 200 text characters.",
value="He hoped there would be stew for dinner, turnips and carrots and bruised potatoes and fat mutton pieces to be ladled out in thick, peppered, flour-fattened sauce.",
)
style_gr=gr.Dropdown(
label="Style",
info="Select a style of output audio for the synthesised speech. (Chinese only support 'default' now)",