OBS上传到对象:https://support.huaweicloud.com/utiltg-obs/obs_11_0004.html 最近参加一个华为云大模型AI微调比赛,比赛链接:https://competition.huaweicloud.com/information/1000041979/introduction
根据自己的linux版本:
uname -m
我的是 Linux 系统是基于 ARM 64 位架构的。 下载和安装obsutil:https://support.huaweicloud.com/utiltg-obs/obs_11_0003.html
先下载obsutil_linux_arm64.tar.gz压缩包,解压,增加可执行权限:
tar -xzvf obsutil_linux_arm64.tar.gz
chmod 755 obsutil
继续在目录中执行以下命令,如果能顺利返回obsutil版本号,说明安装成功。
./obsutil version
使用永久AK、SK进行初始化配置: 这里的AK和SK需要去华为云平台**创建访问密钥,**创建访问密钥的操作步骤如下:
- 在控制台单击页面右上角的用户名,并选择“我的凭证”。
- 在“我的凭证”页面,单击左侧导航栏的“访问密钥”。
- 在“访问密钥”页面,单击“新增访问密钥”。
会下载一个csv表格,打开就要AK和SK 使用下列命令配置:
./obsutil config -i=ak -k=sk -e=endpoint
endpoint表示连接OBS的服务地址,可以去这里查看当前开通的区域和终端节点地址:https://developer.huaweicloud.com/endpoint?OBS 比如我要下载的桶在西南-贵阳一,则-e=https://obs.cn-southwest-2.myhuaweicloud.com
./obsutil config -i=UELP7EYDQSBGK5D5PGG7 -k=7ksycdTe9l4BSozqciWCwIE4sUG4VoUorUFaQhFK -e=https://obs.cn-southwest-2.myhuaweicloud.com
显示以下信息则说明配置成功: 还可以使用下述命令检查连通性:
./obsutil ls -s
- 如果返回结果中包含“Bucket number :”,表明配置正确。
- 如果返回结果中包含“Http status [403]”,表明访问密钥配置有误。
- 如果返回结果中包含“A connection attempt failed”,表明无法连接OBS服务,请检查网络环境是否正常。
最后就可以从华为云OBS桶中复制大模型微调代码和预训练权重,进入obsutil文件所在目录,执行下述命令:
./obsutil cp obs://dtse-models-guiyang1/competition/glm2/chatglm2_6b_lora ../ -f -r
./obsutil cp obs://llm-mindspore-ei/wxp/chatglm2-6b/glm2_6b_ms.ckpt ../chatglm2_6b_loraglm2_6b.ckpt
然后就可以上传数据集到notebook,然后跟着步骤进行训练就可以啦。
百模千态开源大模型AI挑战赛指导手册https://developer.huaweicloud.com/develop/aigallery/article/detail?id=3a8fdf15-915f-45da-b2ec-4a6292725524
physician_val_1.jsonl: 不是选择题格式
physician_val.jsonl 选择题格式 physician_test_1.jsonl:非选择题格式
基准模型的评估: processed_test_datasets.jsonl
./obsutil cp ../mindformers/scripts/mf_standalone/output/checkpoint/rank_0/glm2-6b-lora_rank_0-1250_4.ckpt obs://llm-mindspore-ei/wxp/chatglm2-6b/glm2_6b_ms.ckpt obs://chatglm-3df5/checkpoint/glm2_6b.ckpt
最近用的一个训练模型评估结果:
processed_sampled_train_data.jsonl processed_test_datasets.jsonl
这里挑选数据用的代码:
import json
import random
def adjust_output_length(output, reference_output, max_difference=20):
output_words = output.split()
reference_words = reference_output.split()
# Adjust output length
if len(output_words) > len(reference_words) + max_difference:
output_words = output_words[:len(reference_words) + max_difference]
elif len(output_words) < len(reference_words) - max_difference:
output_words += reference_words[len(output_words) - max_difference:]
return ' '.join(output_words)
def random_sample(input_data, output_data, sample_size):
# Create a list of indices
indices = list(range(len(input_data)))
# Randomly shuffle the indices
random.shuffle(indices)
# Select a random subset of indices
selected_indices = indices[:sample_size]
# Create a new list to store sampled data
sampled_data = []
for index in selected_indices:
input_text = input_data[index]['input']
output_text = adjust_output_length(output_data[index]['output'], reference_output, max_difference=20)
sampled_data.append({'input': input_text, 'output': output_text})
return sampled_data
def save_to_jsonl(data, output_path):
with open(output_path, 'w', encoding='utf-8') as file:
for entry in data:
file.write(json.dumps(entry, ensure_ascii=False) + '\n')
# Load data from train_datasets.jsonl
with open('train_datasets.jsonl', 'r', encoding='utf-8') as file:
train_data = [json.loads(line) for line in file]
# Reference output for adjusting length
reference_output = "癫痫是一组由大脑神经元异常放电所引起的短暂中枢神经系统功能失常为特征的慢性脑部疾病,具有突然发生反复发作的特征。根据所侵犯神经原的部位和发放扩散的范围,功能失常可表现为运动感觉意识行为自主神经功能等不同障碍,或兼而有之。大多数的癫痫病人经过正规治疗都是可以治好的。癫痫是一种临床综合症,它的特征是大脑神经细胞反复发作的异常放电大脑功能失调导致癫痫发作。想要彻底杜绝癫痫发作就必须修复受损脑神经元细胞,平衡异常放电。只要病人积极配合,会达到较高的治愈率和理想的疗效。引发癫痫的因素有很多,最常见的就是头部受到巨大伤害,极有可能会造成癫痫疾病的发作,其次就是感冒高烧长时间不退,也有肯能会导致癫痫,还有就是饮食不规律,有一顿没一顿的吃,太饱了或者是太饿了都是会引发癫痫疾病的发生的,还有如果挑食或者是偏食,身体上面的营养跟不上就会造成营养不良,也是会引发癫痫的发生,同时长时间的熬夜,没有好的作息时间,同样的也是会引发癫痫疾病的。可以多方面的了解一些治疗信息以便更好的治疗,积极地面对病情,及时选择有效的治疗措施,积极的治疗,合理的用药,选择科学的治疗方案,癫痫病人应积极的面对病情,早日的摆脱癫痫疾病发作以及先兆带来的困扰,对于癫痫来说,最可靠的预防就是按时按量地服用抗癫痫药物。癫痫是一种临床综合症,它的特征是大脑神经细胞反复发作的异常放电,导致大脑功能失调。在治疗之前首先要查明原因分清类型对症治疗盲目的治疗是治不好病的癫痫本是一种慢性脑部疾病应选择一家专业的癫痫医院进行治疗。"
# Randomly sample 8000 data points and adjust output length
sampled_data = random_sample(train_data, train_data, 8000)
# Save the sampled data to a new JSONL file
save_to_jsonl(sampled_data, 'sampled_train_data.jsonl')
#删除停用词
import json
import jieba
def remove_stopwords(text, stopwords):
words = jieba.cut(text)
filtered_words = [word for word in words if word not in stopwords]
return ' '.join(filtered_words)
def remove_stopwords_from_jsonl(input_file, output_file, stopwords):
with open(input_file, 'r', encoding='utf-8') as infile, open(output_file, 'w', encoding='utf-8') as outfile:
for line in infile:
data_entry = json.loads(line)
input_text = data_entry.get('input', '').strip()
output_text = data_entry.get('output', '').strip()
if input_text and output_text:
input_text = remove_stopwords(input_text, stopwords)
output_text = remove_stopwords(output_text, stopwords)
updated_entry = {'input': input_text, 'output': output_text}
outfile.write(json.dumps(updated_entry, ensure_ascii=False) + '\n')
# Load stopwords from cn_stopwords.txt
with open('cn_stopwords.txt', 'r', encoding='utf-8') as stopwords_file:
cn_stopwords = set(stopwords_file.read().splitlines())
# Remove stopwords from sampled_train_data.jsonl and save to a new file
remove_stopwords_from_jsonl('sampled_train_data.jsonl', 'processed_test_datasets.jsonl', cn_stopwords)
print("Stopwords removal completed. Processed data saved to processed_sampled_train_data.jsonl.")
报错: 解决办法: 去终端输入: npu-smi info 显示现在正在进行的进程: 使用kill命令终止这个进程: kill -9 3257
最终提交判分系统为58.03分。