部署 NIM 前,需要做好如下准备:
VKE 集群中已安装 csi-nas / prometheus-agent / vci-virtual-kubelet / cr-credential-controller 组件
在 VKE 集群中使用相适配的 VCI GPU 实例规格,具体软硬件支持情况可以查看硬件要求:https://docs.nvidia.com/nim/large-language-models/latest/support-matrix.html
创建 NAS 实例,作为存储类,用于模型文件的存储
创建镜像仓库CR 实例,用于托管 NIM 镜像
开通托管 PrometheusVMP服务
1. 在国内运行 NIM 官方镜像时,为了避免网络访问影响镜像拉取速度,可以提前拉取相应 NIM 镜像并上传到火山引擎镜像仓库 CR,操作步骤如下:
$ export NGC_API_KEY=<value> # ngc 的 api key$ echo "$NGC_API_KEY" | docker login nvcr.io --username '$oauthtoken' --password-stdin$ docker pull nvcr.io/nim/meta/llama3-8b-instruct:1.0.0$ docker tag nvcr.io/nim/meta/llama3-8b-instruct:1.0.0 <your-cr-host>/<your-cr-namespace>/llama3-8b-instruct:1.0.0$ echo "<your-cr-password>" | docker login --username=<account-name>@<account-id> <your-cr-host>$ docker push <your-cr-host>/<your-cr-namespace>/llama3-8b-instruct:1.0.0
2. 下载代码到本地,进入到代码的 Helm Chart 目录中,把 Helm Chart 推送到镜像仓库(Helm 版本大于 3.7):
$gitclonehttps://github.com/NVIDIA/nim-deploy.git$cdnim-deploy/helm/nim-llmhelmregistrylogin--username=<account-name>@<account-id><your-cr-host>helmpackage./--version0.2.1helmpushnim-llm-0.2.1.tgzoci://<your-cr-host>/<your-cr-namespace>
3. 在 VKE 的应用中心的 Helm 应用中选择创建 Helm 应用,并选择对应 chart,集群信息,并点击 values.yaml 的编辑按钮进入编辑页:
4. 覆盖 values 内容为如下值来根据火山引擎环境调整参数配置,提升部署性能,点击确定完成参数改动,再继续在部署页点击确定完成部署
image:#Adjusttotheactuallocationoftheimageandversionyouwantrepository:<your-cr-host>/<your-cr-namespace>/llama3-8b-instructtag:1.0.0model:name:meta/llama3-8b-instruct#notstrictlynecessary,butenablesrunning"helmtest"belowngcAPISecret:ngc-apingcAPIKey:"<your-ngc-api-key>"persistence:enabled:truestorageClass:"<your-nas-storage-class>"annotations:helm.sh/resource-policy:keepstatefulSet:enabled:falsemetrics:enabled:trueserviceMonitor:#forusewiththePrometheusOperatorandtheprimaryserviceobjectenabled:trueadditionalLabels:volcengine.vmp:"true"service:typeoadBalancerpodAnnotations:vci.vke.volcengine.com/preferred-instance-family:vci.gni2#规格按模型和region情况具体选择,参考https://www.volcengine.com/docs/6460/76911选择适配规格vke.volcengine.com/burst-to-vci:enforceresources:limits:nvidia.com/gpu:1
5. Pod 启动过程中需要下载模型,需要等待模型下载完成时间。若 Pod 日志出现如下内容或者 Pod 状态变成 Ready,说明服务已经准备好:
INFO:Uvicornrunningonhttp://0.0.0.0:8000(PressCTRL+Ctoquit)
6.在VKE控制台获取LBService地址(Service名称为<release-name>-nim-llm)
7. 访问 NIM 服务
$curl-X'POST'\'http://<lb-ip>:8000/v1/chat/completions'\-H'accept:application/json'\-H'Content-Type:application/json'\-d'{"messages":[{"content":"Youareapoliteandrespectfulchatbothelpingpeopleplanavacation.","role":"system"},{"content":"WhatshouldIdofora4dayvacationinSpain?","role":"user"}],"model":"meta/llama3-8b-instruct","max_tokens":16,"top_p":1,"n":1,"stream":false,"stop":"\n","frequency_penalty":0.0}'会有如下输出:
{"id":"cmpl-a98bbfec02ab4771a3d6ad81caf63e94","object":"chat.completion","created":1718878017,"model":"meta/llama3-8b-instruct","choices":[{"index":0,"message":{"role":"assistant","content":"¡hola!Spainisawonderfuldestination,andI'dbedelightedto"},"logprobs":null,"finish_reason":"length","stop_reason":null}],"usage":{"prompt_tokens":42,"total_tokens":58,"completion_tokens":16}}NIM 提供了丰富的观测指标和 Grafana Dashboard,详情可参考Observability:https://docs.nvidia.com/nim/large-language-models/latest/observability.html#prometheus。
在 VKE 中,可通过如下方法搭建 NIM 监控:
1. 参考文档搭建 Grafana:https://www.volcengine.com/docs/6731/126068。
2. 进入 Grafana 中,在 dashboard 菜单中选择 import:
3. 按照NIM 官方文档中的教程导入NIM Dashboard:
4. 观测面板效果如下:
相比直接构建大模型镜像,基于 VKE 使用 NIM 部署和访问模型有如下优点:
易用性:NIM 提供了预先构建好的模型容器镜像,用户无需从头开始构建和配置环境,配合 VKE 与 CR 的应用部署能力,极大简化了部署过程
性能优化:NIM 的容器镜像是经过优化的,可以在 NVIDIA GPU 上高效运行,充分利用 VCI 的硬件性能
模型选择:NIM 官方提供了多种大语言模型,用户可以根据需求选择合适的模型,部署在 VKE 中仅需对 values.yaml 配置做修改即可
自动更新:通过 NGC,NIM 可以自动下载和更新模型,用户无需手动管理模型版本
可观测性:NIM 内置了丰富的观测指标,配合 VKE 与 VMP 观测能力开箱即用
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |