You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用HuggingFace训练约鲁巴语变音模型后,如何获取输出文件用于部署?

问题排查:HuggingFace run_translation.py 模型输出文件缺失

核心问题分析

使用官方run_translation.py完成训练、评估、预测全流程后,无法找到模型输出文件,需定位问题并获取可部署的模型资源。

训练命令核对

你的训练命令如下:

CUDA_VISIBLE_DEVICES=0 python run_translation.py --model_name_or_path Davlan/oyo-t5-small --do_train --do_eval --source_lang unyo --target_lang dcyo --source_prefix "<unyo2dcyo>: " --train_file data_prep_eng/output_data/bible_train.json --validation_file data_prep_eng/output_data/dev.json --test_file data_prep_eng/output_data/test.json --output_dir oyot5_small_unyo_dcyo_bible --max_source_length 512 --max_target_length 512 --per_device_train_batch_size=24 --per_device_eval_batch_size=24 --num_train_epochs 3 --overwrite_output_dir --predict_with_generate --save_steps 10000 --num_beams 10 --do_predict

可能的遗漏点与解决方案

  • 检查输出目录结构
    模型文件默认会保存在指定的--output_dir(即oyot5_small_unyo_dcyo_bible)下,正常训练完成后,该目录应包含:

    • pytorch_model.bin或model.safetensors(模型权重文件)
    • config.json(模型配置文件)
    • tokenizer_config.json、vocab.json、merges.txt(T5分词器相关文件)
    • training_args.bin(训练参数记录)
    • 开启do_predict后,还会生成generated_predictions.txt或predictions.json(预测结果文件)

    若目录下无上述文件,先确认训练过程中是否有隐性报错,或因--save_steps=10000设置过大(若训练总步数不足10000,仅会在训练结束时保存一次模型)。

  • 强化模型保存逻辑
    你的命令未显式指定--save_strategy,可添加--save_strategy epoch强制每个epoch结束后保存模型,确保至少生成一份模型文件:

    CUDA_VISIBLE_DEVICES=0 python run_translation.py --model_name_or_path Davlan/oyo-t5-small --do_train --do_eval --source_lang unyo --target_lang dcyo --source_prefix "<unyo2dcyo>: " --train_file data_prep_eng/output_data/bible_train.json --validation_file data_prep_eng/output_data/dev.json --test_file data_prep_eng/output_data/test.json --output_dir oyot5_small_unyo_dcyo_bible --max_source_length 512 --max_target_length 512 --per_device_train_batch_size=24 --per_device_eval_batch_size=24 --num_train_epochs 3 --overwrite_output_dir --predict_with_generate --save_steps 10000 --save_strategy epoch --num_beams 10 --do_predict
    
  • 排查权限问题
    确认运行命令的用户对output_dir所在路径有读写权限,避免因权限不足导致模型文件无法写入。

  • 预测输出文件定位
    若需获取预测结果而非模型权重,do_predict开启后,结果默认保存为output_dir/generated_predictions.txt,JSON格式数据集可能同步生成predictions.json。

部署注意事项

获取模型文件后,部署到Web服务器时需将output_dir下的模型权重、分词器文件、配置文件全部上传,使用HuggingFace的pipeline或AutoModelForSeq2SeqLM+AutoTokenizer即可加载部署。

内容的提问来源于stack exchange,提问作者Akindele Michael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 00:39:58