北京平臺網(wǎng)站建設(shè)哪家好開封網(wǎng)站推廣公司
codeshell安裝配置
- 1 注意事項
- 1.1 Python版本問題
- 2 codeshell環(huán)境搭建
- 2.1 codeshell使用軟件各版本
- 2.2 軟件下載
- 2.3 codeshell使用環(huán)境安裝
- 2.3.1 python-3.10.9-amd64.exe安裝
- 2.3.2 Anaconda3-2022.10-Windows-x86_64.exe安裝
- 2.3.3 創(chuàng)建環(huán)境
- 2.3.4 Pytorch安裝
- 2.3.5 transformers
- 3 下載codeshell模型
- 4 codeshell使用
- 注意:這里是在py310環(huán)境使用的,所以需要先激活py310環(huán)境。
- 4.1 Web UI
- 4.2 CLI Demo
- 5 總結(jié)
1 注意事項
1.1 Python版本問題
codeshell
推薦使用的python
版本是3.8以上,但是最好不要選擇最新版本的,否則可能會在配置pytorch
環(huán)境時,報環(huán)境不兼容的錯誤。
這里使用目前最新版本python=3.12后,錯誤信息如下:
(py312) C:\Users\lc>conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
Collecting package metadata (current_repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Solving environment: unsuccessful attempt using repodata from current_repodata.json, retrying with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: unsuccessful initial attempt using frozen solve. Retrying with flexible solve.
Solving environment: |
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failedUnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:Specifications:- torchaudio -> python[version='>=2.7,<2.8.0a0|>=3.5,<3.6.0a0']- torchaudio -> python[version='>=3.10,<3.11.0a0|>=3.11,<3.12.0a0|>=3.9,<3.10.0a0|>=3.8,<3.9.0a0|>=3.7,<3.8.0a0|>=3.6,<3.7.0a0']- torchvision -> python[version='>=3.10,<3.11.0a0|>=3.8,<3.9.0a0|>=3.9,<3.10.0a0|>=3.11,<3.12.0a0|>=3.7,<3.8.0a0|>=3.6,<3.7.0a0|>=3.5,<3.6.0a0']Your python: python=3.12If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.The following specifications were found to be incompatible with each other:Output in format: Requested package -> Available versionsPackage pytorch-cuda conflicts for:
torchvision -> pytorch==2.1.0 -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8|>=11.8,<11.9|>=12.1,<12.2']
torchaudio -> pytorch==2.1.0 -> pytorch-cuda[version='>=11.6,<11.7|>=11.7,<11.8|>=11.8,<11.9|>=12.1,<12.2']
torchaudio -> pytorch-cuda[version='11.6.*|11.7.*|11.8.*|12.1.*']
torchvision -> pytorch-cuda[version='11.6.*|11.7.*|11.8.*|12.1.*']Package setuptools conflicts for:
python=3.12 -> pip -> setuptools
pytorch -> jinja2 -> setuptools
torchvision -> setuptoolsPackage flit-core conflicts for:
torchvision -> typing_extensions -> flit-core[version='>=3.6,<4']
pytorch -> typing_extensions -> flit-core[version='>=3.6,<4']Package pytorch conflicts for:
torchvision -> pytorch[version='1.10.0|1.10.1|1.10.2|1.11.0|1.12.0|1.12.1|1.13.0|1.13.1|2.0.0|2.0.1|2.1.0|1.9.1|1.9.0|1.8.1|1.8.0|1.7.1|1.7.0|1.6.0|1.5.1']
torchaudio -> pytorch[version='1.10.0|1.10.1|1.10.2|1.11.0|1.12.0|1.12.1|1.13.0|1.13.1|2.0.0|2.0.1|2.1.0|1.9.1|1.9.0|1.8.1|1.8.0|1.7.1|1.7.0|1.6.0']Package requests conflicts for:
torchvision -> requests
python=3.12 -> pip -> requests
2 codeshell環(huán)境搭建
codeshell地址:https://github.com/WisdomShell/codeshell
codeshell使用環(huán)境:
- python 3.8 and above【python 3.8以上】
- pytorch 2.0 and above are recommended【pytorch 建議2.0以上】
- transformers 4.32 and above【transformers 4.32以上】
- CUDA 11.8 and above are recommended (this is for GPU users, flash-attention users, etc.)【CUDA 11.8以上(可選)】
2.1 codeshell使用軟件各版本
- python-3.10.9-amd64.exe【這里選擇的是2022年的版本】
- Anaconda3-2022.10-Windows-x86_64.exe【用于安裝管理Pytorch,這里選擇的是2022年最后一個版本】
- Pytorch【根據(jù)實際情況而定】
- transformers【默認最新版】
2.2 軟件下載
- python-3.10.9-amd64.exe
- 下載地址:https://www.python.org/downloads
- 選擇如圖所示下載
2. Anaconda3-2022.10-Windows-x86_64.exe
- 下載地址:清華開源鏡像anaconda
- 選擇如圖所示下載
3. Pytorch【非安裝包的形式,不用下載】
4. transformers【非安裝包的形式,不用下載】
2.3 codeshell使用環(huán)境安裝
2.3.1 python-3.10.9-amd64.exe安裝
- 選擇自定義安裝,并勾選使用管理員權(quán)限安裝和將
python.exe
加入到環(huán)境。
- 設(shè)置自定義安裝位置
- 驗證安裝結(jié)果
cmd
命令彈窗,輸入python
,點擊回車,看到下圖,則安裝python
成功。
2.3.2 Anaconda3-2022.10-Windows-x86_64.exe安裝
- 選擇
Just Me
- 自定義安裝路徑
- 只勾選
Register
,然后點擊Install
。
- 去除這兩個勾選,然后點擊
Finish
。
2.3.3 創(chuàng)建環(huán)境
1.查看Python版本
cmd
打開命令行,輸入python --version
,查驗python
版本。
2. 打開Anaconda Prompt
頁面,輸入指令conda create -n py310 python=3.10
(這里每個人不一樣,要根據(jù)查出來的版本做修改。)
3. 看見如下圖的示例,表示環(huán)境創(chuàng)建完畢。
4. 最后conda activate py310
激活環(huán)境,看到左下角改變?yōu)?code>py310,代表進入該環(huán)境。
5. 其他命令
- 退出激活的環(huán)境,conda deactivate
。
- 查看虛擬環(huán)境列表,conda env list
。
- conda
刪除環(huán)境,conda remove -n
需要刪除的環(huán)境名 --all。
到這里,就代表anaconda
的安裝配置全部完成。
2.3.4 Pytorch安裝
- conda配置
- 更換鏡像源地址,以下是清華大學鏡像源地址:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
- 把連接超時的時間設(shè)置成
40s
,讀取超時的時間修改成100s
conda config --set remote_connect_timeout_secs 40
conda config --set remote_read_timeout_secs 100
- 配置文件位置:
C:\Users\liuch\.condarc
channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/- defaults
show_channel_urls: true
remote_connect_timeout_secs: 40.0
remote_read_timeout_secs: 100.0
注意:需要把 - defaults
刪掉。
- 查看本機的
CUDA
版本
cmd
命令行輸入nvidia-smi
,在第一行最右邊可以看到CUDA
的版本號。
- 點擊進入Pytorch官網(wǎng),然后下拉至如圖所示位置,只需保證系統(tǒng)和電腦匹配,
CUDA
版本小于本機CUDA
版本,調(diào)整結(jié)束后,復制紅框中的指令。conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
4. 打開Anaconda Prompt
,激活py310環(huán)境(conda activate py310
),然后粘貼上一步的指令,回車執(zhí)行。
5. 如果報OpenSSL
錯誤
(py310) C:\Users\liuch>conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
Collecting package metadata (current_repodata.json): failedCondaSSLError: OpenSSL appears to be unavailable on this machine. OpenSSL is required to
download and install packages.Exception: HTTPSConnectionPool(host='conda.anaconda.org', port=443): Max retries exceeded with url: /pytorch/win-64/current_repodata.json (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))
可去 https://slproweb.com/products/Win32OpenSSL.html 下載安裝包,注意最好下載Win64 OpenSSL v1.1.1w Light
的EXE
,也就是低版本的,因為v3.x
的安裝后依舊報錯。
6. 輸入y確認,回車。
7. 等待安裝直到左上角出現(xiàn)done
【下載依賴較多,耗時較長】。
8. 輸入pip list
,查看安裝了哪些包。
9. 輸入python
進入環(huán)境,輸入import torch
,無報錯代表導入成功(這里要等待一段時間)。
10. 輸入torch.cuda.is_available()
查看torch
是否可以使用顯卡,True
代表可以。
至此,Pytorch
安裝完畢。
2.3.5 transformers
安裝最新版本:
pip install transformers
指定版本(推薦):
pip install transformers==4.34.0
輸入pip list
,查看安裝了哪些包。
至此,codeshell
環(huán)境安裝完畢。
3 下載codeshell模型
在第二部分主要是搭建了codeshell
使用環(huán)境,但是本地還沒有最底層的模型文件,所以需要單獨下載模型文件,才能真正使用codeshell
。
目前有四個開源的模型如下:
- CodeShell Base:
CodelShell
底座模型,具有強大的代碼基礎(chǔ)能力。 - CodeShell Chat:
CodelShell
對話模型,在代碼問答、代碼補全等下游任務(wù)重性能優(yōu)異。 - CodeShell Chat 4bit:
CodelShell
對話模型4bit量化版本,在保證模型性能的前提下內(nèi)存消耗更小,速度更快。 - CodeShell CPP:
CodelShell
對話模型CPP
版本,支持開發(fā)者在沒有GPU
的個人電腦中使用。注意,CPP
版本同樣支持量化操作,用戶可以在最小內(nèi)存為8G的個人電腦中運行CodelShell
。
其中有三個模型是在huggingface
上托管:
WisdomShell/CodeShell-7B
:對應(yīng)CodeShell Base
。WisdomShell/CodeShell-7B-Chat
:對應(yīng)CodeShell Chat
。WisdomShell/CodeShell-7B-Chat-int4
:對應(yīng)CodeShell Chat 4bit
。
所以需要從huggingface上下載下來。
git lfs install
git clone https://huggingface.co/WisdomShell/CodeShell-7B-Chat
4 codeshell使用
注意:這里是在py310環(huán)境使用的,所以需要先激活py310環(huán)境。
conda activate py310
4.1 Web UI
通過下列命令啟動Web
服務(wù),服務(wù)啟動后,可以通過https://127.0.0.1:8000
進行訪問。
python demos/web_demo.py
- 如果報錯提示缺少相關(guān)依賴模塊,使用
pip install +模塊名稱
下載安裝即可,例如報下錯誤:
(py310) E:\Python\codeshell>python demos/web_demo.py
Traceback (most recent call last):File "E:\Python\codeshell\demos\web_demo.py", line 28, in <module>import gradio as gr
ModuleNotFoundError: No module named 'gradio'
則需要安裝相關(guān)依賴,然后重新啟動:
pip install gradio
- 如果提示連接不上
https://huggingface.co
,需要開代理,或者將model下載到本地。
4.2 CLI Demo
python demos/cli_demo.py
5 總結(jié)
-
耗內(nèi)存
在4.1 Web UI
和4.2 CLI Demo
使用時,可以看到占用內(nèi)存16943MB,即16.54GB。
-
響應(yīng)慢
根據(jù)問題寫代碼時,很慢。 -
準確性 尚可
- golang語言實現(xiàn),輸入一個英文句子,反轉(zhuǎn)句子中單詞的順序,但單詞內(nèi)的字符順序不變,簡單起見,標點符號和普通單詞一樣處理。
package mainimport ("fmt""strings" )func reverseWords(s string) string {words := strings.Fields(s)for i, j := 0, len(words)-1; i < j; i, j = i+1, j-1 {words[i], words[j] = words[j], words[i]}return strings.Join(words, " ") }func main() {s := "the weather is nice today."fmt.Println(reverseWords(s)) }
- golang語言使用兩個協(xié)程交替打印數(shù)字和字母。
package mainimport ("fmt""time" )func main() {// 創(chuàng)建兩個協(xié)程go printNumber()go printLetter()// 阻塞,直到協(xié)程完成for {// 休眠一段時間time.Sleep(1 * time.Second)} }func printNumber() {for i := 0; i < 10; i++ {fmt.Printf("%d ", i)time.Sleep(1 * time.Second)} }func printLetter() {for i := 'a'; i < 'z'; i++ {fmt.Printf("%c ", i)time.Sleep(1 * time.Second)} }
-
其他
未測
個人目前覺得在配置較高的電腦運行可能會比較流暢,個人使用體驗不是很好。