Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
KMnO4-zx committed Feb 19, 2024
2 parents da4ea1e + f8a89a3 commit c2e6ed0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions ChatGLM/06-ChatGLM3-6B-Lora微调.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"outputs": [],
"source": [
"# 将JSON文件转换为CSV文件\n",
"df = pd.read_json('../dataset/huanhuan.jsonl')\n",
"df = pd.read_json('../dataset/huanhuan.json')\n",
"ds = Dataset.from_pandas(df)"
]
},
Expand Down Expand Up @@ -112,7 +112,7 @@
}
],
"source": [
"tokenizer = AutoTokenizer.from_pretrained(\"/CV/xhr/xhr_project/LLM_learn/transformers-code-master/model/chatglm3-6b\", trust_remote_code=True)\n",
"tokenizer = AutoTokenizer.from_pretrained(\"/root/autodl-tmp/ZhipuAI/chatglm3-6b\", trust_remote_code=True)\n",
"tokenizer"
]
},
Expand Down Expand Up @@ -313,7 +313,7 @@
}
],
"source": [
"model = AutoModelForCausalLM.from_pretrained(\"/CV/xhr/xhr_project/LLM_learn/transformers-code-master/model/chatglm3-6b\", trust_remote_code=True, low_cpu_mem_usage=True)"
"model = AutoModelForCausalLM.from_pretrained(\"/root/autodl-tmp/ZhipuAI/chatglm3-6b\", trust_remote_code=True, low_cpu_mem_usage=True)"
]
},
{
Expand Down Expand Up @@ -357,7 +357,7 @@
"source": [
"from peft import LoraConfig, TaskType, get_peft_model\n",
"\n",
"# model = AutoModelForCausalLM.from_pretrained(\"/CV/xhr/xhr_project/LLM_learn/transformers-code-master/model/chatglm3-6b\", low_cpu_mem_usage=True)\n",
"# model = AutoModelForCausalLM.from_pretrained(\"/root/autodl-tmp/ZhipuAI/chatglm3-6b\", low_cpu_mem_usage=True)\n",
"config = LoraConfig(task_type=TaskType.CAUSAL_LM, target_modules={\"query_key_value\"}, r=8, lora_alpha=32)\n",
"config"
]
Expand Down
6 changes: 3 additions & 3 deletions ChatGLM/06-ChatGLM3-6B-Lora微调.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def process_func(example):

if "__main__" == __name__:
# 将JSON文件转换为CSV文件,处理数据集
df = pd.read_json('../dataset/huanhuan.jsonl')
df = pd.read_json('../dataset/huanhuan.json')
ds = Dataset.from_pandas(df)
# 加载tokenizer
tokenizer = AutoTokenizer.from_pretrained("./model/chatglm3-6b", trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained("/root/autodl-tmp/ZhipuAI/chatglm3-6b", trust_remote_code=True)
# 将数据集变化为token形式
tokenized_ds = ds.map(process_func, remove_columns=ds.column_names)

# 创建模型
model = AutoModelForCausalLM.from_pretrained("./model/chatglm3-6b",torch_dtype=torch.half, trust_remote_code=True, low_cpu_mem_usage=True)
model = AutoModelForCausalLM.from_pretrained("/root/autodl-tmp/ZhipuAI/chatglm3-6b",torch_dtype=torch.half, trust_remote_code=True, low_cpu_mem_usage=True)

# 创建loRA参数
config = LoraConfig(task_type=TaskType.CAUSAL_LM, target_modules={"query_key_value"}, r=8, lora_alpha=32)
Expand Down
8 changes: 4 additions & 4 deletions Qwen/05-Qwen-7B-Chat Ptuning 微调.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ def process_func(example):


if "__main__" == __name__:
os.chdir('/CV/xhr/xhr_project/LLM_learn/transformers-code-master/self-llm')
os.chdir('/root/self-llm') # /root/self-llm 需改成自己 self-llm 项目的绝对路径
# 处理数据集
# 将JSON文件转换为CSV文件
df = pd.read_json('./huanhuan.json')
df = pd.read_json('./dataset/huanhuan.json')
ds = Dataset.from_pandas(df)
# 加载tokenizer
tokenizer = AutoTokenizer.from_pretrained('/CV/xhr/xhr_project/LLM_learn/transformers-code-master/model/Qwen-7B-Chat', use_fast=False, trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained('/root/autodl-tmp/qwen/Qwen-7B-Chat', use_fast=False, trust_remote_code=True)
tokenizer.pad_token_id = tokenizer.eod_id
# 将数据集变化为token形式
tokenized_id = ds.map(process_func, remove_columns=ds.column_names)

# 创建模型并以半精度形式加载
model = AutoModelForCausalLM.from_pretrained('/CV/xhr/xhr_project/LLM_learn/transformers-code-master/model/Qwen-7B-Chat', trust_remote_code=True, torch_dtype=torch.half, device_map="auto")
model = AutoModelForCausalLM.from_pretrained('/root/autodl-tmp/qwen/Qwen-7B-Chat', trust_remote_code=True, torch_dtype=torch.half, device_map="auto")
# model.enable_input_require_grads() # 开启梯度检查点时,要执行该方法
# 加载lora参数
model = get_peft_model(model, config)
Expand Down

0 comments on commit c2e6ed0

Please sign in to comment.