做网站图片像素,网站备案期间可以用二级域名访问网站吗,网站 技术,苏州百度seo关键词优化本篇文章#xff0c;我们聊聊如何使用 Docker 容器快速上手朋友团队出品的中文版 LLaMA2 开源大模型#xff0c;国内第一个真正开源#xff0c;可以运行、下载、私有部署#xff0c;并且支持商业使用。
写在前面
感慨于昨天 Meta LLaMA2 模型开放下载之后#xff0c;Git…本篇文章我们聊聊如何使用 Docker 容器快速上手朋友团队出品的中文版 LLaMA2 开源大模型国内第一个真正开源可以运行、下载、私有部署并且支持商业使用。
写在前面
感慨于昨天 Meta LLaMA2 模型开放下载之后GitHub 上出现了许多“只有 Readme 文档” 的开源模型项目并一时间在各个群里疯狂传播宛如“郁金香泡沫”故事里的期货一般。
中午吃饭的时候和朋友一起吐槽朋友说这玩意又不难今晚整一个吧。也希望能藉此让中文开源生态变的更好一些于是本文的主角就有了中文版 LLaMA2 模型。
项目地址在https://github.com/LinkSoul-AI/Chinese-Llama-2-7b昨天开源的能够使用 Docker 运行 LLaMA2 的项目 https://github.com/soulteary/docker-llama2-chat 中也已经添加了中文 LLaMA2 的模型支持欢迎下载、转发、一键三连为一起建设更好的中文开源环境打个气 当然如果你想使用 MetaAI 官方的 LLaMA2 大模型可以翻阅昨天的文章《使用 Docker 快速上手官方版 LLaMA2 开源大模型》。
准备工作
因为中文版的 LLaMA2 模型采用了严格的和原版 LLaMA2 一致的输入格式进行训练所以中文模型完全兼容原版程序这样极大的减少了我们使用昨天文章中程序的工作量代码几乎和昨天的文章完全一致。
准备工作部分我们依旧只有两步工作需要做准备模型文件和模型运行环境。
关于模型运行环境我们在之前的文章《基于 Docker 的深度学习环境入门篇》中聊过就不赘述了还不熟悉的同学可以阅读参考。
只要你安装好 Docker 环境配置好能够在 Docker 容器中调用显卡的基础环境就可以进行下一步啦。
模型下载
中文 LLaMA2 模型完全开源、并开放给所有的人和组织下载使用所以我们直接使用下面的命令完成模型文件的下载获取就好了
# 依旧需要确保你安装了 Git LFS (https://git-lfs.com)
git lfs install# 然后下载我们的中文模型即可
git clone https://huggingface.co/LinkSoul/Chinese-Llama-2-7b从 HuggingFace 完成模型下载之后在开始下一步工作前我们来创建和调整一个目录以备后用。
# 和昨天一样创建一个目录
mkdir LinkSoul# 将模型移动到目录中
mv Chinese-Llama-2-7b LinkSoul/合适的目录结构类似下面这样。
# tree -L 2 LinkSoul
LinkSoul
└── Chinese-Llama-2-7b├── config.json├── generation_config.json├── pytorch_model-00001-of-00003.bin├── pytorch_model-00002-of-00003.bin├── pytorch_model-00003-of-00003.bin├── pytorch_model.bin.index.json├── README.md├── special_tokens_map.json├── tokenizer_config.json└── tokenizer.model2 directories, 10 files准备好模型之后我们准备运行模型。
启动模型应用程序
你使用下面的命令下载 Docker LLaMA2 Chat 模型应用程序文件
git clone https://github.com/soulteary/docker-llama2-chat.git等待程序下载完毕后我们进入程序目录然后开始构建中文模型容器镜像
# 进入程序目录
cd docker-llama2-chat
# 构建中文 7B 镜像
bash scripts/make-7b-cn.sh耐心等待镜像构建完毕后我们将之前准备好的存放着模型的 LinkSoul 目录移动到当前程序目录中然后选择要启动的模型程序即可
# 运行中文 7B 镜像应用程序
bash scripts/run-7b-cn.sh命令执行后如果一切顺利你将看到类似下面的日志 PyTorch
NVIDIA Release 23.06 (build 63009835)
PyTorch Version 2.1.0a04136153Container image Copyright (c) 2023, NVIDIA CORPORATION AFFILIATES. All rights reserved.Copyright (c) 2014-2023 Facebook Inc.
Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
Copyright (c) 2011-2013 NYU (Clement Farabet)
Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
Copyright (c) 2015 Google Inc.
Copyright (c) 2015 Yangqing Jia
Copyright (c) 2013-2016 The Caffe contributors
All rights reserved.Various files include modifications (c) NVIDIA CORPORATION AFFILIATES. All rights reserved.This container image and its contents are governed by the NVIDIA Deep Learning Container License.
By pulling and using the container, you accept the terms and conditions of this license:
https://developer.nvidia.com/ngc/nvidia-deep-learning-container-licenseLoading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:1200:00, 4.09s/it]
You are using the legacy behaviour of the class transformers.models.llama.tokenization_llama.LlamaTokenizer. This means that tokens that come after special tokens will not be properly handled. We recommend you to read the related pull request available at https://github.com/huggingface/transformers/pull/24565
Caching examples at: /app/gradio_cached_examples/20
Caching example 1/5
/usr/local/lib/python3.10/dist-packages/transformers/generation/utils.py:1270: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use a generation configuration file (see https://huggingface.co/docs/transformers/main_classes/text_generation )warnings.warn(
Caching example 2/5
Caching example 3/5
Caching example 4/5
Caching example 5/5
Caching complete/usr/local/lib/python3.10/dist-packages/gradio/utils.py:839: UserWarning: Expected 7 arguments for function function generate at 0x7fd4ac3d1000, received 6.warnings.warn(
/usr/local/lib/python3.10/dist-packages/gradio/utils.py:843: UserWarning: Expected at least 7 arguments for function function generate at 0x7fd4ac3d1000, received 6.warnings.warn(
Running on local URL: http://0.0.0.0:7860To create a public link, set shareTrue in launch().接下来使用浏览器打开 http://localhost:7860 或者 http://你的IP:7860 就能够开始体验中文版的 LLaMA2 Chat 模型啦。 启动后你就可以和他开始聊天交互啦。
当前只是第一版的模型效果和状态只能说刚刚及格未来应该会有更好的版本迭代出来我们一起期待吧。
显存使用情况
显存消耗和官方原版基本没有差异会占用 13G 左右的资源。
-----------------------------------------------------------------------------
| NVIDIA-SMI 525.125.06 Driver Version: 525.125.06 CUDA Version: 12.0 |
|---------------------------------------------------------------------------
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
||
| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | Off |
| 31% 41C P8 33W / 450W | 14101MiB / 24564MiB | 0% Default |
| | | N/A |
--------------------------------------------------------------------------------------------------------------------------------------------------------
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
||
| 0 N/A N/A 1434 G /usr/lib/xorg/Xorg 167MiB |
| 0 N/A N/A 1673 G /usr/bin/gnome-shell 16MiB |
| 0 N/A N/A 27402 C python 13914MiB |
-----------------------------------------------------------------------------峰值运行会消耗到 18G 左右的显存。
-----------------------------------------------------------------------------
| NVIDIA-SMI 525.125.06 Driver Version: 525.125.06 CUDA Version: 12.0 |
|---------------------------------------------------------------------------
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
||
| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | Off |
| 54% 72C P2 408W / 450W | 18943MiB / 24564MiB | 100% Default |
| | | N/A |
--------------------------------------------------------------------------------------------------------------------------------------------------------
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
||
| 0 N/A N/A 1434 G /usr/lib/xorg/Xorg 167MiB |
| 0 N/A N/A 1673 G /usr/bin/gnome-shell 16MiB |
| 0 N/A N/A 27402 C python 18756MiB |
-----------------------------------------------------------------------------好了到此为止你已经能在本地运行起来中文的 LLaMA2 大模型啦。接下来你就可以自由发挥啦比如在 langChain 或者之前的各种任务中特别具体的指令性工作不妨用它一试。
最后
在昨天的文章结尾里我提到了我对于未来开源模型生态是乐观的但是其实作为技术爱好者和一部分行业相关者也深知当前国内开源状况并不那么的好还有非常多可以改善的地方但是这需要大家一起努力。
所以我希望能够和来自各行各业不同背景和经历的朋友对开源、对模型感兴趣的朋友一起踏踏实实为开源生态添砖加瓦用实际行动去完善中文开源技术生态去进行技术布道、让好的技术、好的内容能够传播的更广泛、大家能够更早的知道和用到这些技术。
如果你感兴趣一起来玩吧
文章的最后关于 LLaMA2 我已经写了两篇基础的内容了接下来我们来聊聊有趣的工程实践和场景落地应用吧让大模型技术能够更快的飞入千家万户。
–EOF 本文使用「署名 4.0 国际 (CC BY 4.0)」许可协议欢迎转载、或重新修改使用但需要注明来源。 署名 4.0 国际 (CC BY 4.0)
本文作者: 苏洋
创建时间: 2023年07月21日 统计字数: 3599字 阅读时间: 8分钟阅读 本文链接: https://soulteary.com/2023/07/21/use-docker-to-quickly-get-started-with-the-chinese-version-of-llama2-open-source-large-model.html