使用TRL微调LLM时出现无效十进制字面量错误的原因及解决方法
错误原因及修复方法:SyntaxError: invalid decimal literal
问题场景
在Colab中运行以下代码时触发语法错误:
#install trl !pip install trl # clone the repo for the script git clone https://github.com/lvwerra/trl # start training ! python trl/examples/scripts/sft_trainer.py \ --model_name meta-llama/Llama-2-7b-hf \ --dataset_name timdettmers/openassistant-guanaco \ --use_peft \ --batch_size 4 \ --gradient_accumulation_steps 2
报错信息:
File "<ipython-input-11-c07a8b5c25f5>", line 8 --model_name meta-llama/Llama-2-7b-hf \ ^ SyntaxError: invalid decimal literal
错误原因
Colab的代码单元格默认解析为Python代码,你写的git clone和python开头的命令是Shell命令,却没有添加Colab要求的!前缀,导致这些命令被当作Python代码解析,进而触发语法错误。比如--model_name在Python中属于非法语法,Llama-2-7b-hf里的数字组合也会被Python误判为无效的十进制字面量。
修复方法
给所有Shell命令添加!前缀,修改后的代码如下:
# install trl !pip install trl # clone the repo for the script !git clone https://github.com/lvwerra/trl # start training ! !python trl/examples/scripts/sft_trainer.py \ --model_name meta-llama/Llama-2-7b-hf \ --dataset_name timdettmers/openassistant-guanaco \ --use_peft \ --batch_size 4 \ --gradient_accumulation_steps 2
添加!后,Colab会将这些命令识别为Shell命令执行,而非Python代码,即可正常运行。
内容的提问来源于stack exchange,提问作者qwe123
相关产品推荐
相关产品推荐

