Ludwig与llama_Chinese联动

172 阅读2分钟

第一llama2路线

报错中文库llama2

环境启动

. ~/.profile
conda activate base
cd /data1/liming/model/Ludwig/
pipenv shell

Windows10上使用llama-recipes(LoRA)来对llama-2-7b做fine-tune_lhf2112的博客-CSDN博客

说明:脸书的llamam没有配置文件不适用Ludwig
改为中文社区Llama2-Chinese-7b-Chat
可能需要转换文件为pytorch文件能识别模式
官方建议为transforms
  File "/data1/liming/model/Ludwig/.venv/lib/python3.8/site-packages/transformers/configuration_utils.py", line 675, in _get_config_dict
    resolved_config_file = cached_file(
  File "/data1/liming/model/Ludwig/.venv/lib/python3.8/site-packages/transformers/utils/hub.py", line 400, in cached_file
    raise EnvironmentError(
OSError: /data1/liming/model/llama_2_7b_chat/ does not appear to have a file named config.json. Checkout 'https://huggingface.co//data1/liming/model/llama_2_7b_chat//None' for available files.

ludwig train -h  获取参数

目录位置:与model同级的work文件,运行命令

 ludwig train --config /data1/liming/workspace/Ludwig_data.yaml --dataset '/data1/liming/data/alpaca_data.json' >./Ludwig_data_alpaca.logtop

ludwig train --config /data1/liming/workspace/model_2_input.yaml --dataset '/data1/liming/data/train_sft.json' >./train_sft_data.log


未走通
ludwig train --config /data1/liming/workspace/model.yaml --dataset '/data1/liming/data/new_example.json' >./example_data.log

/data1/liming/workspace/model.yaml:

(脸书不适配,改用中文7b)

model_type: llm
base_model: '/data1/liming/model/Llama2-Chinese-7b-Chat/'

quantization:
  bits: 4

adapter:
  type: lora

prompt:
  template: |
    ### Instruction:
    {instruction}

    ### Input:
    {input}

    ### Response:

input_features:
  - name: prompt
    type: text

output_features:
  - name: output
    type: text

trainer:
  type: finetune
  learning_rate: 0.0001
  batch_size: 1
  gradient_accumulation_steps: 16
  epochs: 3
  learning_rate_scheduler:
    warmup_fraction: 0.01

preprocessing:
  sample_ratio: 0.1

vim /data1/liming/model/Ludwig/ludwig/schema/llms/base_model.py

55行,环境模型存在检测

 if os.path.isdir(model_name):
                return model_name
                
 python
 import os
 os.path.isdir(model_name)

通过后,文件详细格式见:
config.json


数据文件格式报错解决

ludwig train --config /data1/liming/workspace/model.yaml --dataset '/data1/liming/data/example_train_data_3.5_turbo_SWMM1.json'

raise RuntimeError(f"Caught exception during model preprocessing: {str(e)}") from e
RuntimeError: Caught exception during model preprocessing: Trailing data


Ludwig源码官方接受alpaca_data.json,
读入json文件接受位置
位置:\model\Ludwig\ludwig\utils\data_utils.py
884,862行

alpaca_data.json格式参考如下

raw.githubusercontent.com/tatsu-lab/s…


中文官方参考train_sft.csv模式如下

raw.githubusercontent.com/FlagAlpha/L…


RuntimeError: Caught exception during model preprocessing: template invalid for zero-shot prompt: Prompt template must contain either the '__sample__' field or one of the columns from the dataset

注:数据最好在Linux上进行python转换,虽然都是一样的解码方式,但是Linux与widows系统的换行符号,一个为/n一个/r/n

此处指文件格式,非内容换行


传入数据后

报错 使用nltk时,报错Resource punkt not found - 知乎 (zhihu.com)

# 使用nltk时,报错Resource punkt not found
位置:
Ludwig/.venv/lib/python3.8/nltk_data
Ludwig/.venv/share/nltk_data