初探AI之got-ocr2.0大模型本地部署與遇到的各種坑處理

wan了个蛋發表於2024-10-19

一、環境搭建

1.安裝cuda,本人使用的是12.1版本,下載地址:https://developer.nvidia.com/cuda-12-1-1-download-archive

image

2.安裝conda3,https://blog.csdn.net/m0_73634846/article/details/136378350

3.準備程式碼環境

原文: https://mp.weixin.qq.com/s/PQVrlr5FoVb89Mivzi7pLA

順序執行:

git clone https://github.com/Ucas-HaoranWei/GOT-OCR2.0.git
conda create -n got python=3.10 -y #建立虛擬環境
conda activate got #啟用虛擬環境
pip install -e . # 使用專案裡面pyproject.toml安裝依賴

安裝 Flash-Attention:

pip install ninja
pip install flash-attn --no-build-isolation
ps:以上是官方的安裝教程,但是其實會遇到很多問題,以下進行逐一說明,不保證能解決所有問題,但是大部分問題都能解決

二、問題序列:

1.python安裝cuda出現錯誤提示:AssertionError: Torch not compiled with CUDA enabled

https://blog.csdn.net/qq_44750293/article/details/129685556
問題本質是pytorch無法呼叫cuda,原因是國內加速映象預設會安裝cpu版本,安裝gpu版本即可,及torch.cuda.is_available輸出為false即代表安裝的版本為cpu版本,安裝gpu版本後即可輸出為true
###1、torch.cuda.is_available()顯示false解決方法:
	使用pytorch官方推薦的版本安裝:
		https://pytorch.org/
		例如cuda12.1的安裝命令: 
			conda:	conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
			pip:	
				pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 (親測有效,這個需要下載2小時+)
				阿里雲加速(使用這個最快,推薦,只需要下載2min+):
					pip install torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1 -f https://mirrors.aliyun.com/pytorch-wheels/cu121

2.遇到deepspeed安裝報錯

Python|Windows 安裝 DeepSpeed 安裝方法及報錯 Unable to pre-compile async_io 處理:
	https://blog.csdn.net/Changxing_J/article/details/139789110

配置visual studio
執行Anaconda Powershell Prompt,執行 Set-Item Env:\DS_BUILD_OPS 0,切換到deepspeed目錄,再次執行 :  .\build_win.bat

3.pip錯誤

ERROR: Could not find a version that satisfies the requirement setuptools_scm (from versions: none)
	嘗試切換pip源試試,pip install -i 源地址

4.conda錯誤

在VS介面啟用anaconda,但是報錯”CondaError: Run 'conda init' before 'conda activate'“,該如何解決?
	開啟Anaconda Prompt
	conda init
	conda activate 環境

5.遇到依賴C++環境的庫錯誤解決

【報錯】fatal error C1189
visual studio 版本過高或過低導致,目前2019版本相容性相對較好

https://blog.csdn.net/thisjuly/article/details/136260069

6.flash_attn安裝後執行失敗,本質是編譯的包不對

text-generation-webui載入codellama報錯DLL load failed while importing flash_attn_2_cuda: 找不到指定的模組。:
https://blog.csdn.net/dandandancpop/article/details/134729988
解決: https://github.com/Dao-AILab/flash-attention/releases ,在此連結中下載與本地cuda與torch且python相對應的版本即可,cuda12.1下載cu123親測可用,cp310為python3.10,cp311為python3.11其他同理

7.本地無法啟動大模型

因為預設的源是hugging-face,但是國內無法訪問,國內可使用modelscope(魔塔社群)的模型
hugging-face模型下載不成功?
	https://zhuanlan.zhihu.com/p/722248326?utm_campaign=shareopn&utm_medium=social&utm_psn=1824225242303819776&utm_source=wechat_session
	使用modelscope提供的模型

8.cudnn部署

https://blog.csdn.net/retainenergy/article/details/126183711
cuDNN下載連結:https://developer.nvidia.com/rdp/cudnn-archive ,本人使用的8.9.7,安裝連結中進行配置即可

三、需要用到的資源下載連結(只上傳了下載很慢的資源):

透過網盤分享的檔案:GOT-OCR大模型部署相關
連結: https://pan.baidu.com/s/1s18O0kS3apBvs-L35KB-qw?pwd=y4ht 提取碼: y4ht

相關文章