admin管理员组

文章数量:1590153

目录

1、基础环境配置

2、临时更改当前环境

3、安装chatglm的使用环境

1.安装 Python 3.8

2.安装各种包

4、跑通原本的chatglm:

5、p-tuning微调:

6、lora 微调


1、基础环境配置

下载anaconda版本:Index of /anaconda/archive/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

使用的是Anaconda3-2020.02-Linux-x86_64.sh

chmod +x Anaconda3-2020.02-Linux-x86_64.sh
sh Anaconda3-2020.02-Linux-x86_64.sh

安装过程中 一直enter 键,出现 More 展示协议,输入【yes】统一协议。之后一直enter 键即可,尤其遇到 让更改PATH 路径,选择默认的[no]即可,这样之后用conda单独建立想用的python 版本或者环境。

2、临时更改当前环境

export PATH="/home/anaconda3/bin:$PATH"

此时 ~/.bashrc 目录的path 并无变化

更改 PATH 环境变量后,可以通过以下步骤验证是否成功:

  1. 打开一个终端窗口(Terminal)。

  2. 输入以下命令来激活 Anaconda 环境:

    source anaconda3/bin/activate

    假设Anaconda 安装在 "/home/user/anaconda" 目录下,那么需要使用上面的命令来激活 Anaconda 环境。

  3. 输入以下命令来检查 Anaconda 环境是否激活成功:

    which python

    如果输出的是 Anaconda 中安装的 Python 的路径(例如:/home/user/anaconda/bin/python),则说明 Anaconda 环境已经成功激活了。

  4. 输入以下命令来退出 Anaconda 环境:

    conda deactivate

    这样就可以将环境还原回系统默认环境了。​

  5. 然后conda 命令就可以用了

验证步骤尽量实验一下,有时直接conda 命令显示-bash: conda: command not found

3、安装chatglm的使用环境

1.安装 Python 3.8

先修改anaconda 的安装channels:channels 指的是软件包仓库的源地址

sudo vim ~/.condarc

# 将下面信息粘贴进去:
channels:
 - http://大家设置自家的源/cloud/conda-forge
 - http://大家设置自家的源/cloud/pytorch
 - http://大家设置自家的源/pkgs/main/
 - http://大家设置自家的源/pkgs/free/
show_channel_urls: true

创建python 3.8环境详细步骤

  1. 使用上一个终端环境,千万别关闭。

  2. 输入以下命令来创建一个 Python 3.8 的临时环境:

    conda create --name tmp_py38 python=3.8

    这个命令会在 Anaconda 中创建一个名为 "tmp_py38" 的新环境,并安装 Python 3.8 版本。

  3. 输入以下命令来激活这个新环境:

    conda activate tmp_py38

  4. 在这个环境下,可以按照需求安装所需要的 Python 包和依赖。

  5. 完成后,可以使用以下命令退出这个临时环境:

    conda deactivate

2.安装各种包

先安装chatglm需要的基础包:

ChatGLM-6B/requirements.txt at main · THUDM/ChatGLM-6B · GitHub

pip install --retries 0 -r requirements.txt

然后按照微调需要的包:

ChatGLM-6B/ptuning at main · THUDM/ChatGLM-6B · GitHub

pip install  --retries 0 rouge_chinese nltk jieba datasets

安装完之后 torch 应该是1.13版本的,此时运行代码出现【libcublas.so.11: symbol cublasLtHSHMatmulAlgoInit, version libcublasLt.so.11 not defined in file libcublasLt.so.11 with link time reference】

参考:解决libcublas.so.11: symbol cublasLtHSHMatmulAlgoInit_be_humble的博客-CSDN博客

pip uninstall nvidia_cublas_cu11

4、跑通原本的chatglm:

将chatglm的源码下载下来,修改模型路径,运行cli_demo.py

修改模型路径

7 tokenizer = AutoTokenizer.from_pretrained("./pretrained_models", trust_remote_code=True)

8 model = AutoModel.from_pretrained("./pretrained_models", trust_remote_code=True).half().cuda()

9 model = model.eval()

使用案例

欢迎使用 ChatGLM-6B 模型,输入内容即可进行对话,clear 清空对话历史,stop 终止程序

用户:你好啊

ChatGLM-6B:你好👋!我是人工智能助手 ChatGLM-6B,很高兴见到你,欢迎问我任何问题。

用户:what is your name?

ChatGLM-6B:my name is ChatGLM-6B.

用户:你都会做什么?

ChatGLM-6B:我是一台人工智能助手,可以回答各种各样的问题,例如学术、语言、文化等方面的问题,提供有关历史、地理、科学、技术、社会和文化等各个领域的信息和知识,帮助用户解决问题和获取信息。同时,我也可以进行文本生成、语言翻译、自动摘要、情感分析等任务,可以帮助用户完成各种自动化操作。

用户:你会写代码吗?

ChatGLM-6B:虽然我是由清华大学 KEG 实验室和智谱 AI 公司于 2023年 共同训练的语言模型,但是我并没有编程能力,无法编写自己的代码。我的功能是基于预先训练的大规模语言模型,通过对输入文本的响应来回答问题或完成任务。

用户:用python写一个从1加到10的代码

ChatGLM-6B:以下是使用 Python 编写的从 1 加到 10 的代码:

```python

sum = 0

for i in range(1, 11):

sum += i

print("The sum of", range(1, 11), "is", sum)

```

代码解释:

1. 定义变量 `sum` 初始值为 0。

2. 使用 `for` 循环从 1 加到 10,循环变量 `i` 的范围为 1 到 10。

3. 在每个循环迭代中,将当前数字 `i` 加到变量 `sum` 中。

4. 循环结束后,`sum` 的值会等于 range(1, 11) 中所有数字的总和,即 `sum = sum + range(1, 11)`。

5. 使用 `print` 函数输出结果。

输出结果:

```

The sum of 1 to 10 is 55

```

用户:stop

5、p-tuning微调:

chatglm的微调有没有保姆式的教程?? - 知乎

6、lora 微调

GitHub - mymusise/ChatGLM-Tuning: 一种平价的chatgpt实现方案, 基于ChatGLM-6B + LoRA

pip install -r requirements.txt

peft类的导入

peft的git库:GitHub - huggingface/peft: 🤗 PEFT: State-of-the-art Parameter-Efficient Fine-Tuning.

将git库中src/peft目录复制出来,放在.../ChatGLM-Tuning目录下即可

遇到新问题:/usr/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found

​
===================================BUG REPORT===================================

Welcome to bitsandbytes. For bug reports, please run

python -m bitsandbytes

and submit this information together with your error trace to: Issues · TimDettmers/bitsandbytes · GitHub

================================================================================

bin /home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cuda110.so

/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:145: UserWarning: /home/anaconda3/envs/tmp_py38 did not contain ['libcudart.so', 'libcudart.so.11.0', 'libcudart.so.12.0'] as expected! Searching further paths...

warn(msg)

/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/cuda_setup/main.py:145: UserWarning: WARNING: The following directories listed in your path were found to be non-existent: {PosixPath('/usr/local/nvidia/lib'), PosixPath('/usr/local/cuda/extras/CUPTI/lib64'), PosixPath('/usr/local/nvidia/lib64')}

warn(msg)

CUDA SETUP: CUDA runtime path found: /usr/local/cuda/lib64/libcudart.so

CUDA SETUP: Highest compute capability among GPUs detected: 8.0

CUDA SETUP: Detected CUDA version 110

CUDA SETUP: Loading binary /home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cuda110.so...

/usr/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/libbitsandbytes_cuda110.so)

CUDA SETUP: Something unexpected happened. Please compile from source:

git clone git@github:TimDettmers/bitsandbytes.git

cd bitsandbytes

CUDA_VERSION=110 make cuda110

python setup.py install

Traceback (most recent call last):

File "finetune.py", line 8, in <module>

from peft import get_peft_model, LoraConfig, TaskType

File "./ChatGLM-Tuning/peft/__init__.py", line 22, in <module>

from .mapping import MODEL_TYPE_TO_PEFT_MODEL_MAPPING, PEFT_TYPE_TO_CONFIG_MAPPING, get_peft_config, get_peft_model

File "./ChatGLM-Tuning/peft/mapping.py", line 16, in <module>

from .peft_model import (

File "./ChatGLM-Tuning/peft/peft_model.py", line 31, in <module>

from .tuners import (

File "./ChatGLM-Tuning/peft/tuners/__init__.py", line 21, in <module>

from .lora import LoraConfig, LoraModel

File "./ChatGLM-Tuning/peft/tuners/lora.py", line 40, in <module>

import bitsandbytes as bnb

File "/home//anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/__init__.py", line 6, in <module>

from . import cuda_setup, utils, research

File "/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/research/__init__.py", line 1, in <module>

from . import nn

File "/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/research/nn/__init__.py", line 1, in <module>

from .modules import LinearFP8Mixed, LinearFP8Global

File "/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/research/nn/modules.py", line 8, in <module>

from bitsandbytes.optim import GlobalOptimManager

File "/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/optim/__init__.py", line 6, in <module>

from bitsandbytes.cextension import COMPILED_WITH_CUDA

File "/home/anaconda3/envs/tmp_py38/lib/python3.8/site-packages/bitsandbytes/cextension.py", line 20, in <module>

raise RuntimeError('''

RuntimeError:

CUDA Setup failed despite GPU being available. Please run the following command to get more information:

python -m bitsandbytes

Inspect the output of the command and see if you can locate CUDA libraries. You might need to add them

to your LD_LIBRARY_PATH. If you suspect a bug, please take the information from python -m bitsandbytes

and open an issue at: Issues · TimDettmers/bitsandbytes · GitHub

​

需要将当前python 环境的lib库加进来:

export LD_LIBRARY_PATH=/home//anaconda3/envs/tmp_py38/lib

基于tensorboard 查看训练进程:

需要指定端口:

tensorboard --logdir=./ChatGLM-Tuning/runs/May19_14-46-33_set-zw04-kubernetes-pc189.mt --port 8000

本文标签: 模型业务行业LoRA垂类大