安装Baichuan2百川智能大模型

下载模型和预安装

git clone https://github.com/baichuan-inc/Baichuan2



python3.9 -V

/usr/local/python3.9/bin/python3.9 -m pip install --upgrade pip

python3.9 -m venv baichuan2

 source baichuan2/bin/activate
 
 python -V
 
python3.9 -m pip install --upgrade pip

pip install -r requirements.txt  -i https://mirrors.aliyun.com/pypi/simple/


vim cli_demo.py 

运行和报错处理

执行python3.9 cli_demo.py

报错:urllib3 v2.0 only supports OpenSSL 1.1.1+

ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips  26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168

排查:

python3.9 
Python 3.9.15 (main, Mar 22 2023, 18:27:52) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> print(ssl.OPENSSL_VERSION)
OpenSSL 1.0.2k-fips  26 Jan 2017
>>> exit()

确认问题:python版本和ssl版本不匹配

解决:

echo "urllib3>=1.26.6,<2.0" > r.txt

pip install -r r.txt  -i https://mirrors.aliyun.com/pypi/simple/

执行python3.9 cli_demo.py

报错: hostname ‘huggingface.co’ doesn’t match ‘api.twitter.com’

init model ...
报错:
    raise CertificateError("hostname %r doesn't match %r" % (hostname, dnsnames[0]))
urllib3.util.ssl_match_hostname.CertificateError: hostname 'huggingface.co' doesn't match 'api.twitter.com'

....

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /baichuan-inc/Baichuan2-7B-Chat/resolve/main/config.json (Caused by SSLError(CertificateError("hostname 'huggingface.co' doesn't match 'api.twitter.com'")))

排查:

 wget "https://huggingface.co/"
Connecting to huggingface.co (huggingface.co)|75.126.124.162|:443... ^C

处理:

执行python3.9 cli_demo.py

报错:This modeling file requires the following packages that were not found in your environment: bitsandbytes

init model ...

dynamic_module_utils.py", line 179, in check_imports
    raise ImportError(
ImportError: This modeling file requires the following packages that were not found in your environment: bitsandbytes. Run `pip install bitsandbytes`

排查:

pip3.9 install bitsandbytes 
Requirement already satisfied: bitsandbytes in ./baichuan2/lib/python3.9/
Python 3.9.15 (main, Mar 22 2023, 18:27:52) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bitsandbytes
  ...
  File "/data/Baichuan2/baichuan2/lib/python3.9/site-packages/bitsandbytes/functional.py", line 12, in <module>
    from scipy.stats import norm
ModuleNotFoundError: No module named 'scipy'
>>> import scipy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'scipy'
>>> exit()

确认问题,缺少scipy库

处理:

 pip3.9 install scipy

Successfully installed scipy-1.11.2

执行python3.9 cli_demo.py

克隆项目

# 安装 git-lfs
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.rpm.sh | sudo bash
yum install git-lfs



git clone https://github.com/Vision-CAIR/MiniGPT-4.git
git clone https://huggingface.co/lmsys/vicuna-13b-delta-v0
mv vicuna-13b-delta-v0 /data/MiniGPT-4/vicuna_weights

安装补丁

cd /data/MiniGPT-4/
cd ckp/
#https://drive.google.com/file/d/1a4zLvaiDBr-36pasffmgpvH5P7CKmpze/view
#https://drive.google.com/u/0/uc?id=1a4zLvaiDBr-36pasffmgpvH5P7CKmpze&export=download
wget https://doc-0s-08-docs.googleusercontent.com/docs/securesc/dbq4d7c2ha9354fqj5612le3gl157ov5/pcnbepjp7icjk54rrfgio602v738i398/1681803150000/09448752369347632296/09178445193473466964/1a4zLvaiDBr-36pasffmgpvH5P7CKmpze?e=download&ax=ALy03A4aDltm3f1TddEAJesIj7YsB_KKlm56C61-M72rzjuPpluLCR3UOUv28FXMkNc3q5s


## 修改配置
vim /data/MiniGPT-4/eval_configs/minigpt4_eval.yaml
 ckpt: '/data/MiniGPT-4/ckp/'

vim /data/MiniGPT-4/minigpt4/configs/models/minigpt4.yaml 
  llama_model: "/data/MiniGPT-4/vicuna_weights/"

安装依赖

pip3.9 install omegaconf
#1681803684
yum install xz-devel -y
yum install python-backports-lzma -y
pip3.9 install backports.lzma
yum install python-backports-lzma -y
yum install -y xz-devel mesa-libGL python-backports-lzma
vim /usr/local/python3.9/lib/python3.9/lzma.py

pip3.9 install iopath
pip3.9 install timm
pip3.9 install cv2



pip3.9 install  opencv-python  -i https://pypi.tuna.tsinghua.edu.cn/simple


pip3.9 install webdataset  -i https://pypi.tuna.tsinghua.edu.cn/simple

pip3.9 install sentencepiece #  -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3.9 install  transformers
python3.9  -c "from transformers import pipeline; print(pipeline('sentiment-analysis')('we love you'))"
conda install -c huggingface transformers

cd ..

git clone https://github.com/huggingface/transformers.git

cd transformers
pip3.9 install -e .  -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3.9 install decord
pip3.9 install decord  -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3.9 install accelerate
pip3.9 install  bitsandbytes  -i https://pypi.tuna.tsinghua.edu.cn/simple

修复 /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found 报错

strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX 
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_DEBUG_MESSAGE_LENGTH
wget http://ftp.tsukuba.wide.ad.jp/software/gcc/releases/gcc-5.2.0/gcc-5.2.0.tar.bz2
tar -xf gcc-5.2.0.tar.bz2
cd gcc-5.2.0
./contrib/download_prerequisites
mkdir gcc-temp
cd gcc-temp
../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
make && make install
mv /usr/bin/gcc /usr/bin/gcc.bak
 /usr/sbin/update-alternatives --install  /usr/bin/gcc gcc /usr/local/bin/x86_64-unknown-linux-gnu-gcc-5.2.0 52
 
gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 5.2.0 (GCC) 



 g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../configure --enable-checking=release --enable-languages=c,c++ --disable-multilib
Thread model: posix
gcc version 5.2.0 (GCC) 



strings /usr/local/lib64/libstdc++.so.6|grep GLIBCXX
2. 复制链接

cp /usr/local/lib64/libstdc++.so.6.0.21  /usr/lib64

cd /usr/lib64

rm -f libstdc++.so.6

ln -s libstdc++.so.6.0.21 libstdc++.so.6

ll libstdc*

补充

pip3.9 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

vim  /data/MiniGPT-4/minigpt4/models/mini_gpt4.py:92                                     │
│                                                                                                  │
│    86 │   │   self.llama_tokenizer.pad_token = self.llama_tokenizer.eos_token                    │
│    87 │   │                                                                                      │
│    88 │   │   if self.low_resource:                                                              │
│ ❱  89 │   │   │   self.llama_model = LlamaForCausalLM.from_pretrained(                           │
│    90 │   │   │   │   llama_model,                                                               │
│    91 │   │   │   │   torch_dtype=torch.float16,                                                 │
│    92 │   │   │   │   #load_in_8bit=True, 



mkdir -p /export/home/.cache/minigpt4

wget https://repo.anaconda.com/archive/Anaconda3-5.3.0-Linux-x86_64.sh
chmod +x Anaconda3-5.3.0-Linux-x86_64.sh
./Anaconda3-5.3.0-Linux-x86_64.sh
vim /root/.bashrc
export PATH=/root/anaconda3/bin:$PATH
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
conda env create -f environment.yml
conda activate minigpt4
python demo.py --cfg-path eval_configs/minigpt4_eval.yaml
>> Home

51ak

2023/09/25

Categories: centos python Tags: 整理

《数据库工作笔记》公众号
扫描上面的二维码,关注我的《数据库工作笔记》公众号