如何通过命令行将whisper-small.pt转换为HuggingFace格式?
正确的Whisper模型转换命令行步骤
第一步:将OpenAI格式的whisper-small.pt转为HuggingFace格式
有两种可靠方式,选其一即可:
方式1:使用OpenAI Whisper官方转换脚本
确保你已获取convert_openai_to_hf.py脚本(可从Whisper仓库提取),执行命令:
python convert_openai_to_hf.py --checkpoint_path "/path/to/your/whisper-small.pt" --dump_path "/path/to/output/whisper-small-hf"
- 替换
/path/to/your/whisper-small.pt为本地模型文件的实际路径 /path/to/output/whisper-small-hf是生成的HuggingFace格式模型的输出目录
方式2:使用Transformers官方转换工具
无需单独下载脚本,直接用transformers-cli命令:
transformers-cli convert --model_type whisper --checkpoint "/path/to/your/whisper-small.pt" --output "/path/to/output/whisper-small-hf"
第二步:将HuggingFace格式转为CTranslate2(Faster Whisper兼容)格式
执行ctranslate2转换命令:
ct2-transformers-converter --model "/path/to/output/whisper-small-hf" --output_dir "/path/to/output/whisper-small-ct2" --copy_files tokenizer.json vocab.json --quantization float16
--copy_files必须添加,否则Faster Whisper无法加载tokenizer相关文件--quantization float16适合GPU推理,仅用CPU可改为int8以节省内存
常见错误排查
- 确认依赖版本达标:transformers≥4.26.0、ctranslate2≥3.16.0、whisper≥20230314
- 所有路径需填写正确,避免相对路径导致的文件找不到问题
- Windows系统下路径需用反斜杠(
\)或双引号包裹绝对路径
内容的提问来源于stack exchange,提问作者sophie
相关产品推荐
相关产品推荐

