石家庄网站到首页排名,商务网站的建设与维护,那里做网站最好,做博客网站什么空间好codeshell安装配置 1 注意事项1.1 Python版本问题 2 codeshell环境搭建2.1 codeshell使用软件各版本2.2 软件下载2.3 codeshell使用环境安装2.3.1 python-3.10.9-amd64.exe安装2.3.2 Anaconda3-2022.10-Windows-x86_64.exe安装2.3.3 创建环境2.3.4 Pytorch安装2.3.5 transforme… codeshell安装配置 1 注意事项1.1 Python版本问题 2 codeshell环境搭建2.1 codeshell使用软件各版本2.2 软件下载2.3 codeshell使用环境安装2.3.1 python-3.10.9-amd64.exe安装2.3.2 Anaconda3-2022.10-Windows-x86_64.exe安装2.3.3 创建环境2.3.4 Pytorch安装2.3.5 transformers 3 下载codeshell模型4 codeshell使用注意这里是在py310环境使用的所以需要先激活py310环境。4.1 Web UI4.2 CLI Demo 5 总结 1 注意事项
1.1 Python版本问题
codeshell推荐使用的python版本是3.8以上但是最好不要选择最新版本的否则可能会在配置pytorch环境时报环境不兼容的错误。
这里使用目前最新版本python3.12后错误信息如下
(py312) C:\Users\lcconda install pytorch torchvision torchaudio pytorch-cuda12.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[version2.7,2.8.0a0|3.5,3.6.0a0]- torchaudio - python[version3.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[version3.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: python3.12If python is on the left-most side of the chain, thats the version youve 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 - pytorch2.1.0 - pytorch-cuda[version11.6,11.7|11.7,11.8|11.8,11.9|12.1,12.2]
torchaudio - pytorch2.1.0 - pytorch-cuda[version11.6,11.7|11.7,11.8|11.8,11.9|12.1,12.2]
torchaudio - pytorch-cuda[version11.6.*|11.7.*|11.8.*|12.1.*]
torchvision - pytorch-cuda[version11.6.*|11.7.*|11.8.*|12.1.*]Package setuptools conflicts for:
python3.12 - pip - setuptools
pytorch - jinja2 - setuptools
torchvision - setuptoolsPackage flit-core conflicts for:
torchvision - typing_extensions - flit-core[version3.6,4]
pytorch - typing_extensions - flit-core[version3.6,4]Package pytorch conflicts for:
torchvision - pytorch[version1.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[version1.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
python3.12 - pip - requests2 codeshell环境搭建
codeshell地址https://github.com/WisdomShell/codeshell
codeshell使用环境
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【根据实际情况而定】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使用环境安装
2.3.1 python-3.10.9-amd64.exe安装
选择自定义安装并勾选使用管理员权限安装和将python.exe加入到环境。 设置自定义安装位置 验证安装结果 cmd命令弹窗输入python 点击回车看到下图则安装python成功。
2.3.2 Anaconda3-2022.10-Windows-x86_64.exe安装
选择Just Me 自定义安装路径 只勾选Register然后点击Install。 去除这两个勾选然后点击Finish。
2.3.3 创建环境
1.查看Python版本 cmd打开命令行输入python --version查验python版本。 2. 打开Anaconda Prompt页面输入指令conda create -n py310 python3.10这里每个人不一样要根据查出来的版本做修改。 3. 看见如下图的示例表示环境创建完毕。 4. 最后conda activate py310激活环境看到左下角改变为py310代表进入该环境。 5. 其他命令 - 退出激活的环境conda deactivate。 - 查看虚拟环境列表conda env list。 - conda删除环境conda remove -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把连接超时的时间设置成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官网然后下拉至如图所示位置只需保证系统和电脑匹配CUDA版本小于本机CUDA版本调整结束后复制红框中的指令。conda install pytorch torchvision torchaudio pytorch-cuda12.1 -c pytorch -c nvidia4. 打开Anaconda Prompt激活py310环境conda activate py310然后粘贴上一步的指令回车执行。 5. 如果报OpenSSL错误
(py310) C:\Users\liuchconda install pytorch torchvision torchaudio pytorch-cuda12.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(hostconda.anaconda.org, port443): Max retries exceeded with url: /pytorch/win-64/current_repodata.json (Caused by SSLError(Cant 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. 等待安装直到左上角出现done【下载依赖较多耗时较长】。 8. 输入pip list查看安装了哪些包。 9. 输入python进入环境输入import torch无报错代表导入成功这里要等待一段时间。 10. 输入torch.cuda.is_available()查看torch是否可以使用显卡True代表可以。 至此Pytorch安装完毕。
2.3.5 transformers
安装最新版本
pip install transformers指定版本推荐
pip install transformers4.34.0输入pip list查看安装了哪些包。 至此codeshell环境安装完毕。
3 下载codeshell模型
在第二部分主要是搭建了codeshell使用环境但是本地还没有最底层的模型文件所以需要单独下载模型文件才能真正使用codeshell。
目前有四个开源的模型如下
CodeShell BaseCodelShell底座模型具有强大的代码基础能力。CodeShell ChatCodelShell对话模型在代码问答、代码补全等下游任务重性能优异。CodeShell Chat 4bitCodelShell对话模型4bit量化版本在保证模型性能的前提下内存消耗更小速度更快。CodeShell CPPCodelShell对话模型CPP版本支持开发者在没有GPU的个人电脑中使用。注意CPP版本同样支持量化操作用户可以在最小内存为8G的个人电脑中运行CodelShell。
其中有三个模型是在huggingface上托管
WisdomShell/CodeShell-7B对应CodeShell Base。WisdomShell/CodeShell-7B-Chat对应CodeShell Chat。WisdomShell/CodeShell-7B-Chat-int4对应CodeShell Chat 4bit。
所以需要从huggingface上下载下来。
git lfs install
git clone https://huggingface.co/WisdomShell/CodeShell-7B-Chat4 codeshell使用
注意这里是在py310环境使用的所以需要先激活py310环境。
conda activate py3104.1 Web UI
通过下列命令启动Web服务服务启动后可以通过https://127.0.0.1:8000进行访问。
python demos/web_demo.py如果报错提示缺少相关依赖模块使用pip install 模块名称下载安装即可例如报下错误
(py310) E:\Python\codeshellpython demos/web_demo.py
Traceback (most recent call last):File E:\Python\codeshell\demos\web_demo.py, line 28, in moduleimport gradio as gr
ModuleNotFoundError: No module named gradio则需要安装相关依赖然后重新启动
pip install gradio如果提示连接不上https://huggingface.co需要开代理或者将model下载到本地。
4.2 CLI Demo
python demos/cli_demo.py5 总结 耗内存 在4.1 Web UI和4.2 CLI Demo使用时可以看到占用内存16943MB即16.54GB。 响应慢 根据问题写代码时很慢。 准确性 尚可 golang语言实现输入一个英文句子反转句子中单词的顺序但单词内的字符顺序不变简单起见标点符号和普通单词一样处理。 package mainimport (fmtstrings
)func reverseWords(s string) string {words : strings.Fields(s)for i, j : 0, len(words)-1; i j; i, j i1, 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语言使用两个协程交替打印数字和字母。 package mainimport (fmttime
)func main() {// 创建两个协程go printNumber()go printLetter()// 阻塞直到协程完成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)}
}其他 未测
个人目前觉得在配置较高的电脑运行可能会比较流畅个人使用体验不是很好。