本文記錄 在 華為昇騰 910B(65GB) * 8 上 部署 DeepSeekR1 蒸餾系列模型(14B、32B)全過程與測試結果。
NPU:910B3 (65GB) * 8 (910B 有三個版本 910B1、2、3)
模型:DeepSeek-R1-Distill-Qwen-14B、DeepSeek-R1-Distill-Qwen-32B
部署方法:鏡像部署 1.0.0-800I-A2-py311-openeuler24.03-lts? (需要申請下載權限,審核需要2天左右)
本文基礎環境如下:
----------------
aarch64
910B(65GB) * 8
CANN 7.0
npu-smi 23.0.2.1
----------------
模型下載
DeepSeek-R1-Distill-Qwen-14B · 模型庫
DeepSeek-R1-Distill-Qwen-32B · 模型庫
modelscope 魔搭社區模型下載
本文將模型下載到服務器的 /data1/apps/models? 路徑下
- 例如 /data1/apps/models/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B?
啟動鏡像時,將路徑掛載:-v /data1/apps/models:/storage/llm?
那么在鏡像容器內模型地址:
?/storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B?
權重轉換
14B、32B 是.safetensor權重,無需轉換,可以直接使用。
環境依賴
拉取鏡像
下載地址: 昇騰鏡像倉庫詳情
登陸賬號,申請下載權限 -- 點擊立即下載 --- 彈出一個窗口 -- 按照指示拉取鏡像
docker pull --platform=linux/arm64 swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:1.0.0-800I-A2-py311-openeuler24.03-lts
--platform=linux/arm64 指定拉去內核為 arm 架構版本的鏡像
由于本文的910B是純內網機器,無法直接訪問下載
于是 找了臺可以訪問公網的機器(x86的),拉取鏡像、導出、傳輸到內網機器、導入
如果你的機器可以訪問公網,直接拉去即可
查看拉取的鏡像版本
docker inspect 25ba5f455ae3| grep Architecture
導出鏡像
docker save -o 1.0.0-800I-A2-py311-openeuler24.03-lts.tar swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:1.0.0-800I-A2-py311-openeuler24.03-lts
- 加載
docker load -i 1.0.0-800I-A2-py311-openeuler24.03-lts.tar1.0.0-300I-Duo-py311-openeuler24.03-lts.tar
環境
- python 3.11
- torch 2.1
[root@pm-a813-005 DeepSeek-R1-Distill-Qwen-14B]# python --version Python 3.11.6 [root@pm-a813-005 DeepSeek-R1-Distill-Qwen-14B]# pip show torch Name: torch Version: 2.1.0 Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration Home-page: https://pytorch.org/ Author: PyTorch Team Author-email: packages@pytorch.org License: BSD-3 Location: /usr/local/lib64/python3.11/site-packages Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions Required-by: accelerate, torch-npu, torchvision
- mindie_llm 1.0.0
- mindiebenchmark 1.0.0
- mindieclient 1.0.0
- mindiesd 1.0.0
- mindietorch 1.0.0+torch2.1.0.abi0
啟動鏡像
root 特權模型
docker run -it -d --net=host --shm-size=10g \--privileged \--name deepseek-r1-distill-root-test \-v /usr/local/Ascend/driver:/usr/local/Ascend/driver:ro \-v /usr/local/sbin:/usr/local/sbin:ro \-v /data1/apps/models:/storage/llm \swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:1.0.0-800I-A2-py311-openeuler24.03-lts \bash
docker exec -it deepseek-r1-distill-root-test bash
普通用戶
docker run -it -d --net=host --shm-size=10g \--name deepseek-r1-distill-test1 \--device=/dev/davinci_manager \--device=/dev/hisi_hdc \--device=/dev/devmm_svm \--device=/dev/davinci0 \--device=/dev/davinci1 \--device=/dev/davinci2 \--device=/dev/davinci3 \--device=/dev/davinci4 \--device=/dev/davinci5 \--device=/dev/davinci6 \--device=/dev/davinci7 \-v /usr/local/Ascend/driver:/usr/local/Ascend/driver:ro \-v /usr/local/sbin:/usr/local/sbin:ro \-v /data1/apps/models:/storage/llm \-w /storage/llm \swr.cn-south-1.myhuaweicloud.com/ascendhub/mindie:1.0.0-800I-A2-py311-openeuler24.03-lts \bash
注意,以上啟動命令僅供參考,請根據需求自行修改再啟動容器,尤其需要注意:
?--user?,如果您的環境中HDK是通過普通用戶安裝(例如默認的HwHiAiUser?,可以通過id HwHiAiUser?命令查看該用戶組ID),請設置好對應的用戶組,例如用戶組1001可以使用HDK,則--user mindieuser:1001?,鏡像中默認使用的是用戶組1000。如果您的HDK是由root用戶安裝,且指定了--install-for-all?參數,則無需指定--user?參數。
設定容器名稱--name?與鏡像名稱,例如mindie:1.0.0-800I-A2-py311-openeuler24.03-lts?。
如果不使用--priviliged?參數,則需要設置各設備,包括設置想要使用的卡號--device?:
... --name <container-name> \ --device=/dev/davinci_manager \ --device=/dev/hisi_hdc \ --device=/dev/davinci0 \ ...
設定權重掛載的路徑,-v /path-to-weights:/path-to-weights:ro?,注意,權重路徑權限應當設置為750。如果使用普通用戶鏡像,權重路徑所屬應為鏡像內默認的1000用戶。可參考以下命令進行修改:
chmod -R 755 /path-to-weights chown -R 1000:1000 /path-to-weights# 進入容器后執行 chmod -R 755 /storage/llm chown -R 1000:1000 /storage/llm
在普通用戶鏡像中,注意所有文件均在 /home/mindieuser? 下,請勿直接掛載 /home? 目錄,以免宿主機上存在相同目錄,將容器內文件覆蓋清除。
- 進入容器
docker exec -it deepseek-r1-distill-test1 bash
確認環境
檢驗HDK是否可用
輸入以下命令,應當正確顯示設備信息:
npu-smi info
如果出現以下信息:
bash: npu-smi: command not found
說明宿主機上的 npu-smi? 工具不在 /usr/local/sbin? 路徑中,可能是由于HDK版本過舊或其他原因導致,可以使用以下命令找到該工具,并在啟動容器時將其掛載到容器內:
find / -name npu-smi
一般來說,可能出現在 /usr/local/bin/npu-smi? 路徑下。
檢驗Torch是否可用
啟動Python,并輸入以下命令:
import torch
import torch_npu
若無報錯信息,則說明Torch組件正常。
檢查MindIE各組件
輸入以下命令:
pip list | grep mindie
應出現類似如下輸出:
mindie_llm 1.0.0
mindiebenchmark 1.0.0
mindieclient 1.0.0
mindiesd 1.0.0
mindietorch 1.0.0+torch2.1.0.abi0
或者輸入以下命令:
cat /home/mindieuser/Ascend/mindie/latest/version.info
應出現類似如下輸出:
Ascend-mindie : MindIE 1.0.0
mindie-rt: 1.0.0
mindie-torch: 1.0.0
mindie-service: 1.0.0
mindie-llm: 1.0.0
mindie-sd:1.0.0
Platform : aarch64
說明各組件正常。
確認模型地址正確
cd /storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B
cd /storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B
cd /storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B
確認權限
chmod -R 750 /storage/llm
設置模型服務啟動配置
打開配置文件
vi /usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
修改建議
一般只需要修改以下配置(單實例)
{..."ServerConfig" :{..."port" : 1040, #自定義"managementPort" : 1041, #自定義"metricsPort" : 1042, #自定義..."httpsEnabled" : false, # 取消https協議啟動服務...},"BackendConfig": {..."npuDeviceIds" : [[0,1]],..."ModelDeployConfig":{"truncation" : false,"ModelConfig" : [{..."modelName" : "deepseek-14b","modelWeightPath" : "/storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B","worldSize" : 2,...}]},}
}
- (多實例)以 14B 為例, 一張卡一個實例, 八張就是八個實例,并發要求200
### ServerConfig
- **`httpsEnabled`**:取消https協議 設為 false### 3. `ModelDeployParam` 部分
#### 整體配置
- **`modelInstanceNumber`**:由于單卡能跑一個實例,機器有 8 張卡,可設置為 8。
- **`tokenizerProcessNumber`**:可使用默認值 8,也可根據實際性能情況進行調整。
- **`maxSeqLen`**:根據需求,最大上下文為 8192,設置為 8192 + 4096 = 12288(輸入長度 + 輸出長度)。
- **`npuDeviceIds`**:由于是單機 8 卡,設置為 `[[0], [1], [2], [3], [4], [5], [6], [7]]`。
- **`multiNodesInferEnabled`**:設置為 `false`,因為是單機推理。#### `ModelParam`
- **`worldSize`**:由于使用 8 張卡, 8 個實例,一個實例一張卡,設置為 1。
- **`cpuMemSize`**:CPU 內存有 1.4T,可適當增大,例如設置為 100(單位:GB)。
- **`npuMemSize`**:使用快速計算公式計算:- 假設單卡總空閑顯存為 60GB,模型權重占用 40GB(根據實際情況調整),后處理占用 1GB,系數取 0.8。- 則 `npuMemSize = (60 - 40/1 - 1) * 0.8 ≈ 15`,可設置為 15(單位:GB)。### 4. `ScheduleParam` 部分
- **`maxPrefillBatchSize`**:可根據實際性能測試進行調整,初始可設置為 200。
- **`maxPrefillTokens`**:設置為大于等于 `maxSeqLen` 的值,例如設置為 16384。
- **`prefillTimeMsPerReq`**:可根據實際情況調整,使用默認值 150。
- **`prefillPolicyType`**:可使用默認值 0(FCFS,先來先服務)。
- **`decodeTimeMsPerReq`**:可根據實際情況調整,使用默認值 50。
- **`decodePolicyType`**:可使用默認值 0(FCFS,先來先服務)。
- **`maxBatchSize`**:根據 `npuMemSize` 和 `cacheBlockSize` 等參數重新計算,初始可設置為 200。
- **`maxIterTimes`**:最大輸出為 4096,設置為 4096。
- **`maxPreemptCount`**:可根據實際情況設置,初始可設置為 0。
- **`supportSelectBatch`**:可根據實際情況設置,初始可使用默認值 `false`。
- **`maxQueueDelayMicroseconds`**:使用默認值 5000。### 預估最大并發量
最大并發量受多種因素影響,包括模型復雜度、硬件性能、參數配置等。
上面的配置,理論上最大并發量可達到 200 左右,但實際并發量需要通過性能測試來確定。可以逐步增加并發請求,觀察系統的響應時間、資源利用率等指標,找到系統的性能瓶頸,從而確定最大并發量。
配置示例
14B
{"Version" : "1.1.0","LogConfig" :{"logLevel" : "Info","logFileSize" : 20,"logFileNum" : 20,"logPath" : "logs/mindservice.log"},"ServerConfig" :{"ipAddress" : "127.0.0.1","managementIpAddress" : "127.0.0.2","port" : 1025,"managementPort" : 1026,"metricsPort" : 1027,"allowAllZeroIpListening" : false,"maxLinkNum" : 1000,"httpsEnabled" : false,"fullTextEnabled" : false,"tlsCaPath" : "security/ca/","tlsCaFile" : ["ca.pem"],"tlsCert" : "security/certs/server.pem","tlsPk" : "security/keys/server.key.pem","tlsPkPwd" : "security/pass/key_pwd.txt","tlsCrlPath" : "security/certs/","tlsCrlFiles" : ["server_crl.pem"],"managementTlsCaFile" : ["management_ca.pem"],"managementTlsCert" : "security/certs/management/server.pem","managementTlsPk" : "security/keys/management/server.key.pem","managementTlsPkPwd" : "security/pass/management/key_pwd.txt","managementTlsCrlPath" : "security/management/certs/","managementTlsCrlFiles" : ["server_crl.pem"],"kmcKsfMaster" : "tools/pmt/master/ksfa","kmcKsfStandby" : "tools/pmt/standby/ksfb","inferMode" : "standard","interCommTLSEnabled" : true,"interCommPort" : 1121,"interCommTlsCaPath" : "security/grpc/ca/","interCommTlsCaFiles" : ["ca.pem"],"interCommTlsCert" : "security/grpc/certs/server.pem","interCommPk" : "security/grpc/keys/server.key.pem","interCommPkPwd" : "security/grpc/pass/key_pwd.txt","interCommTlsCrlPath" : "security/grpc/certs/","interCommTlsCrlFiles" : ["server_crl.pem"],"openAiSupport" : "vllm"},"BackendConfig" : {"backendName" : "mindieservice_llm_engine","modelInstanceNumber" : 8,"npuDeviceIds" : [[0], [1], [2], [3], [4], [5], [6], [7]],"tokenizerProcessNumber" : 8,"multiNodesInferEnabled" : false,"multiNodesInferPort" : 1120,"interNodeTLSEnabled" : true,"interNodeTlsCaPath" : "security/grpc/ca/","interNodeTlsCaFiles" : ["ca.pem"],"interNodeTlsCert" : "security/grpc/certs/server.pem","interNodeTlsPk" : "security/grpc/keys/server.key.pem","interNodeTlsPkPwd" : "security/grpc/pass/mindie_server_key_pwd.txt","interNodeTlsCrlPath" : "security/grpc/certs/","interNodeTlsCrlFiles" : ["server_crl.pem"],"interNodeKmcKsfMaster" : "tools/pmt/master/ksfa","interNodeKmcKsfStandby" : "tools/pmt/standby/ksfb","ModelDeployConfig" :{"maxSeqLen" : 12288,"maxInputTokenLen" : 8192,"truncation" : false,"ModelConfig" : [{"modelInstanceType" : "Standard","modelName" : "deepseek-14b","modelWeightPath" : "/storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B","worldSize" : 1,"cpuMemSize" : 50,"npuMemSize" : -1,"backendType" : "atb","trustRemoteCode" : false}]},"ScheduleConfig" :{"templateType" : "Standard","templateName" : "Standard_LLM","cacheBlockSize" : 128,"maxPrefillBatchSize" : 200,"maxPrefillTokens" : 16384,"prefillTimeMsPerReq" : 150,"prefillPolicyType" : 0,"decodeTimeMsPerReq" : 50,"decodePolicyType" : 0,"maxBatchSize" : 200,"maxIterTimes" : 4096,"maxPreemptCount" : 0,"supportSelectBatch" : false,"maxQueueDelayMicroseconds" : 5000}}
}
32B
{"Version" : "1.1.0","LogConfig" :{"logLevel" : "Verbose","logFileSize" : 200,"logFileNum" : 64,"logPath" : "logs/mindservice.log"},"ServerConfig" :{"ipAddress" : "127.0.0.1","managementIpAddress" : "127.0.0.2","port" : 1025,"managementPort" : 1026,"metricsPort" : 1027,"allowAllZeroIpListening" : false,"maxLinkNum" : 1000,"httpsEnabled" : false,"fullTextEnabled" : false,"tlsCaPath" : "security/ca/","tlsCaFile" : ["ca.pem"],"tlsCert" : "security/certs/server.pem","tlsPk" : "security/keys/server.key.pem","tlsPkPwd" : "security/pass/key_pwd.txt","tlsCrlPath" : "security/certs/","tlsCrlFiles" : ["server_crl.pem"],"managementTlsCaFile" : ["management_ca.pem"],"managementTlsCert" : "security/certs/management/server.pem","managementTlsPk" : "security/keys/management/server.key.pem","managementTlsPkPwd" : "security/pass/management/key_pwd.txt","managementTlsCrlPath" : "security/management/certs/","managementTlsCrlFiles" : ["server_crl.pem"],"kmcKsfMaster" : "tools/pmt/master/ksfa","kmcKsfStandby" : "tools/pmt/standby/ksfb","inferMode" : "standard","interCommTLSEnabled" : true,"interCommPort" : 1121,"interCommTlsCaPath" : "security/grpc/ca/","interCommTlsCaFiles" : ["ca.pem"],"interCommTlsCert" : "security/grpc/certs/server.pem","interCommPk" : "security/grpc/keys/server.key.pem","interCommPkPwd" : "security/grpc/pass/key_pwd.txt","interCommTlsCrlPath" : "security/grpc/certs/","interCommTlsCrlFiles" : ["server_crl.pem"],"openAiSupport" : "vllm"},"BackendConfig" : {"backendName" : "mindieservice_llm_engine","modelInstanceNumber" : 4,"npuDeviceIds" : [[0,1], [2,3], [4,5], [6,7]],"tokenizerProcessNumber" : 8,"multiNodesInferEnabled" : false,"multiNodesInferPort" : 1120,"interNodeTLSEnabled" : true,"interNodeTlsCaPath" : "security/grpc/ca/","interNodeTlsCaFiles" : ["ca.pem"],"interNodeTlsCert" : "security/grpc/certs/server.pem","interNodeTlsPk" : "security/grpc/keys/server.key.pem","interNodeTlsPkPwd" : "security/grpc/pass/mindie_server_key_pwd.txt","interNodeTlsCrlPath" : "security/grpc/certs/","interNodeTlsCrlFiles" : ["server_crl.pem"],"interNodeKmcKsfMaster" : "tools/pmt/master/ksfa","interNodeKmcKsfStandby" : "tools/pmt/standby/ksfb","ModelDeployConfig" :{"maxSeqLen" : 13000,"maxInputTokenLen" : 4096,"truncation" : false,"ModelConfig" : [{"modelInstanceType" : "Standard","modelName" : "deepseek-32b","modelWeightPath" : "/storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-32B","worldSize" : 2,"cpuMemSize" : 100,"npuMemSize" : 10,"backendType" : "atb","trustRemoteCode" : false}]},"ScheduleConfig" :{"templateType" : "Standard","templateName" : "Standard_LLM","cacheBlockSize" : 128,"maxPrefillBatchSize" : 50,"maxPrefillTokens" : 16384,"prefillTimeMsPerReq" : 150,"prefillPolicyType" : 0,"decodeTimeMsPerReq" : 50,"decodePolicyType" : 0,"maxBatchSize" : 200,"maxIterTimes" : 4096,"maxPreemptCount" : 0,"supportSelectBatch" : false,"maxQueueDelayMicroseconds" : 5000}}
}
服務啟動項參數說明
詳細查看官網
配置參數說明-快速開始-MindIE Service開發指南-服務化集成部署-MindIE1.0.RC2開發文檔-昇騰社區
OtherParam參數
配置項 | 取值類型 | 取值范圍 | 配置說明 |
---|---|---|---|
ResourceParam | |||
cacheBlockSize | uint32_t | [1, 128] | kvcache block的size大小。必填,默認值:128;建議值:128,其他值建議取為2的n次冪。 |
LogParam | |||
logLevel | string | "Verbose""Info""Warning""Error""None" | "Verbose":打印Verbose、Info、Warning和Error級別的日志。"Info":打印Info、Warning和Error級別的日志。"Warning":打印Warning和Error級別的日志。"Error":打印Error級別的日志。"None":不打印日志。必填,默認值:"Info"。 |
logPath | string | 日志文件路徑,長度<=4096。 | 支持絕對和相對路徑。如果配置為相對路徑,則代碼中會取工程目錄,最后拼接而成。例如,假設MindIE Service的安裝路徑為“/opt/Ascend-mindie-service{version}linux-x86_64/”,則默認的日志絕對路徑為“/opt/Ascend-mindie-service{version}linux-x86_64/logs/mindservice.log”。若配置路徑不滿足要求,則使用默認路徑:“工程路徑/logs/mindservice.log”。必填,默認值:"logs/mindservice.log"。 |
ServeParam | |||
ipAddress | string | IPv4地址。 | EndPoint提供的業務面RESTful接口綁定的IP地址。全零偵聽會導致三面隔離失效,不滿足安全配置要求,禁止綁定IP地址為0.0.0.0。如果存在環境變量MIES_CONTAINER_IP,則優先取環境變量值作為業務面IP地址。如果不存在環境變量MIES_CONTAINER_IP,則取該配置值。必填,默認值:"127.0.0.1"。 |
managementIpAddress | string | IPv4地址。 | EndPoint提供的管理面RESTful接口綁定的IP地址。全零偵聽會導致三面隔離失效,不滿足安全配置要求,禁止綁定IP地址為0.0.0.0。如果該環境變量MIES_CONTAINER_MANAGEMENT_IP存在,則直取環境變量值作為管理面IP地址。如果“managementIpAddress”字段存在,則取字段本身值;否則取“ipAddress”字段的值作為管理面IP地址。如果采用多IP地址的方案,對“ipAddress”和“managementAddress”的初始值都需要做相應的修改。選填,默認值:"127.0.0.2"。 |
port | int32_t | [1024, 65535] | EndPoint提供的業務面RESTful接口綁定的端口號。如果采用物理機/宿主機IP地址通信,請自行保證端口號無沖突。必填,默認值:1025。 |
managementPort | int32_t | [1024, 65535] | EndPoint提供的管理面(管理面接口參考表1)接口綁定的端口號。業務面與管理面可采用四種方案:單IP地址單端口號(推薦)單IP地址多端口號多IP地址單端口號多IP地址多端口號在單卡節點中,不能使用多IP地址單端口號的方案,會因端口號占用而無法啟動。選填,默認值:1026。 |
maxLinkNum | uint32_t | [1, 1000] | RESTful接口請求并發數,EndPoint支持的最大并發請求數。必填,默認值:1000。 |
httpsEnabled | bool | truefalse | 是否開啟https通信。true:開啟https通信。false:關閉https通信。必填,默認值:true,建議值:true,取值為false時,忽略后續https通信相關參數。 |
tlsCaPath | string | 建議tlsCaPath+tlsCaFile路徑長度<=4096。實際路徑為工程路徑+tlsCaPath,上限限制與操作系統有關,最小值為1。 | 根證書路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后必填,默認值:"security/ca/"。 |
tlsCaFile | set--string | 建議tlsCaPath+tlsCaFile路徑長度<=4096。不可為空,并且tlsCaPath+tlsCaFile路徑長度上限與操作系統有關,最小值為1。 | 業務面根證書名稱列表。“httpsEnabled”=true生效,生效后必填,默認值:["ca.pem"]。 |
tlsCert | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+tlsCert,上限限制與操作系統有關,最小值為1。 | 業務面服務證書文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后必填,默認值:"security/certs/server.pem"。 |
tlsPk | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+tlsPk,上限限制與操作系統有關,最小值為1。 | 業務面服務證書私鑰文件路徑,證書私鑰的長度要求>=3072,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后必填,默認值:"security/keys/server.key.pem"。 |
tlsPkPwd | string | 文件路徑長度<=4096。支持為空;若非空,則實際路徑為工程路徑+tlsPkPwd,上限限制與操作系統有關,最小值為1。 | 業務面服務證書私鑰加密密鑰文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后選填,默認值:"security/pass/key_pwd.txt"。若私鑰經過加密但是未提供此文件,系統啟動時會要求用戶在交互窗口輸入私鑰加密口令。 |
tlsCrl | string | 建議文件路徑長度<=4096。支持為空;若非空,則實際路徑為工程路徑+tlsCrl,上限限制與操作系統有關,最小值為1。 | 業務面服務證書吊銷列表文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后必填,默認值:"security/certs/server_crl.pem"。“httpsEnabled”=false不啟用吊銷列表。“tlsCrl”的值只能配套“tlsCaFile”文件列表中的第一個CA文件。 |
managementTlsCaFile | set--string | 建議tlsCaPath+managementTlsCaFile路徑長度<=4096。不可為空,并且tlsCaPath+managementTlsCaFile路徑長度上限與操作系統有關,最小值為1。 | 管理面根證書名稱列表,當前管理面證書和業務面證書放在同一個路徑(tlsCaPath)下。“httpsEnabled”=true且“ipAddress”!=“managementIpAddress”生效,生效后必填,默認值:["management_ca.pem"]。 |
managementTlsCert | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+managementTlsCert,上限限制與操作系統有關,最小值為1。 | 管理面服務證書文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true且“ipAddress”!=“managementIpAddress”生效,生效后必填,默認值:"security/certs/management_server.pem"。 |
managementTlsPk | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+managementTlsPk,上限限制與操作系統有關,最小值為1。 | 管理面服務證書私鑰文件路徑,證書私鑰的長度要求>=3072,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true且“ipAddress”!=“managementIpAddress”生效,生效后必填,默認值:"security/keys/management_server.key.pem"。 |
managementTlsPkPwd | string | 文件路徑長度<=4096。支持為空;若非空,則實際路徑為工程路徑+managementTlsPkPwd,上限限制與操作系統有關,最小值為1 | 管理面服務證書私鑰加密密鑰文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true且“ipAddress”!=“managementIpAddress”生效,生效后選填,默認值:"security/pass/management/key_pwd.txt"。若私鑰經過加密但是未提供此文件,系統啟動時會要求用戶在交互窗口輸入私鑰加密口令。 |
managementTlsCrl | string | 建議文件路徑長度<=4096。支持為空;若非空,則實際路徑為工程路徑+managementTlsCrl,上限限制與操作系統有關,最小值為1。 | 管理面證書吊銷列表文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true且“ipAddress”!=“managementIpAddress”生效,生效后必填,默認值:"security/certs/management_server_crl.pem"。“httpsEnabled”=false不啟用吊銷列表。“managementTlsCrl”的值只能配套“managementTlsCaFile”文件列表中的第一個CA文件。 |
kmcKsMaster | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+kmcKsMaster,上限限制與操作系統有關,最小值為1。 | KMC密鑰庫文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后必填,默認值:"tools/pmt/master/ksfa"。 |
kmcKsStandby | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+kmcKsStandby,上限限制與操作系統有關,最小值為1。 | KMC密鑰庫備份文件路徑,只支持軟件包安裝路徑下的相對路徑。“httpsEnabled”=true生效,生效后必填,默認值:"tools/pmt/standby/ksfb"。 |
multiNodesInferPort | uint32_t | [1024, 65535] | 跨機通信的端口號,多機推理場景使用。選填,默認值:1120。 |
interNodeTLSEnabled | bool | truefalse | 多機推理時,跨機通信是否開啟證書安全認證。true:開啟證書安全認證。false:關閉證書安全認證。選填,默認值:true。取值為false時,忽略后續參數。 |
interNodeTlsCaFile | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+interNodeTlsCaFile,上限限制與操作系統有關,最小值為1。 | 根證書名稱路徑,只支持軟件包安裝路徑下的相對路徑。“interNodeTLSEnabled”=true生效,生效后必填,默認值:"security/ca/ca.pem"。 |
interNodeTlsCert | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+interNodeTlsCert,上限限制與操作系統有關,最小值為1。 | 服務證書文件路徑,只支持軟件包安裝路徑下的相對路徑。“interNodeTLSEnabled”=true生效,生效后必填,默認值:"security/certs/server.pem"。 |
interNodeTlsPk | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+interNodeTlsPk,上限限制與操作系統有關,最小值為1。 | 服務證書私鑰文件路徑,只支持軟件包安裝路徑下的相對路徑。“interNodeTLSEnabled”=true生效,生效后必填,默認值:"security/keys/server.key.pem"。 |
interNodeTlsPkPwd | string | 建議文件路徑長度<=4096。支持為空;若非空,則實際路徑為工程路徑+interNodeTlsPkPwd,上限限制與操作系統有關,最小值為1。 | 服務證書私鑰加密密鑰文件路徑,只支持軟件包安裝路徑下的相對路徑。“interNodeTLSEnabled”=true生效,生效后必填,默認值:"security/pass/mindie_server_key_pwd.txt"。 |
interNodeKmcKsfMaster | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+interNodeKmcKsfMaster,上限限制與操作系統有關,最小值為1。 | KMC密鑰庫文件路徑,只支持軟件包安裝路徑下的相對路徑。“interNodeTLSEnabled”=true生效,生效后必填,默認值:"tools/pmt/master/ksfa"。 |
interNodeKmcKsfStandby | string | 建議文件路徑長度<=4096。實際路徑為工程路徑+interNodeKmcKsfStandby,上限限制與操作系統有關,最小值為1。 | KMC密鑰庫備份文件路徑,只支持軟件包安裝路徑下的相對路徑。“interNodeTLSEnabled”=true生效,生效后必填,默認值:"tools/pmt/standby/ksfb"。 |
說明
- 如果網絡環境不安全,不開啟https通信,即“httpsEnabled”=“false”時,會存在較高的網絡安全風險。
- 如果推理服務所在的計算節點的網絡為跨公網和局域網,綁定0.0.0.0的IP地址可能導致網絡隔離失效,存在較大安全風險。故該場景下禁止EndPoint的IP地址綁定為0.0.0.0。
- 如果配置了相同的管理面和業務面的IP地址,會導致隔離失效。
WorkFlowParam參數
配置項 | 取值類型 | 取值范圍 | 配置說明 |
---|---|---|---|
TemplateParam | |||
templateType | string | 當前取值只能為:"Standard" | 普通推理。必填,默認值:"Standard"。 |
templateName | string | 由大寫字母、小寫字母和下劃線組成,且不以下劃線作為開頭和結尾,字符串長度小于或等于256。 | 工作流名稱。必填,默認值:"Standard_llama"。 |
ModelDeployParam參數
配置項 | 取值類型 | 取值范圍 | 配置說明 |
---|---|---|---|
engineName | string | 長度1~50,只支持小寫字母加下劃線。且不以下劃線作為開頭和結尾。 | 根據engineName找對應的so文件。必填,默認值:"mindieservice_llm_engine"。 |
modelInstanceNumber | uint32_t | [1, 10] | 模型實例個數。必填,默認值:1。 |
tokenizerProcessNumber | uint32_t | [1, 32] | tokenizer進程數。選填,默認值:8。 |
maxSeqLen | uint32_t | 上限根據顯存和用戶需求來決定,最小值需大于0。 | 最大序列長度。輸入的長度+輸出的長度<=maxSeqLen,用戶根據自己的推理場景選擇maxSeqLen。如果maxSeqLen大于模型支持的最大序列長度,可能會影響推理精度。必填,默認值:2560。 |
npuDeviceIds | set-set<size_t> | 根據模型和環境的實際情況來決定。 | 表示啟用哪幾張卡。對于每個模型實例分配的npuIds。多機推理場景下該值無效,每個節點上使用的npuDeviceIds根據ranktable計算獲得。必填,默認值:[[0,1,2,3]]。 |
multiNodesInferEnabled | bool | truefalse | false:單機推理。true:多機推理。選填,默認值:false。 |
ModelParam | |||
modelInstanceType | string | "Standard""StandardMock" | 模型類型。"Standard":普通推理。"StandardMock":假模型。選填,默認值:"Standard"。 |
modelName | string | 由大寫字母、小寫字母、數字、中劃線、點和下劃線組成,且不以中劃線、點和下劃線作為開頭和結尾,字符串長度小于或等于256。 | 模型名稱。必填,默認值:"llama_65b"。 |
modelWeightPath | string | 文件絕對路徑長度的上限與操作系統有關,最小值為1。 | 模型權重路徑。程序會讀取該路徑下的config.json中torch_dtype和vocab_size字段的值,需保證路徑和相關字段存在。必填,默認值:"/data/atb_testdata/weights/llama1-65b-safetensors"。該路徑會進行安全校驗,必須使用絕對路徑,且和執行用戶的屬組和權限保持一致。 |
worldSize | uint32_t | 根據模型實際情況來決定。每一套模型參數中worldSize必須與使用的NPU數量相等。 | 啟用幾張卡推理。目前llama-65b至少啟用四張NPU卡。多機推理場景下該值無效,worldSize根據ranktable計算獲得。必填,默認值:4。 |
cpuMemSize | uint32_t | 上限根據顯存和用戶需求來決定。只有當maxPreemptCount為0時,才可以取值為0。 | CPU中可以用來申請kv cache的size上限。必填,默認值:5,建議值:5,單位:GB。 |
npuMemSize | uint32_t | 上限根據顯存和用戶需求來決定,下限大于0。 | NPU中可以用來申請kv cache的size上限。必填,默認值:8,建議值:8,單位:GB。快速計算公式:npuMemSize=(單卡總空閑-權重/NPU卡數-后處理占用)*系數,其中系數取0.8。 |
backendType | string | "atb""ms" | 對接的后端類型。必填,默認值:"atb"。 |
pluginParams | string | 根據并行解碼實際所需填寫一個json字符串。 | 選填,默認值:""。 |
ScheduleParam參數
配置項 | 取值類型 | 取值范圍 | 配置說明 |
---|---|---|---|
maxPrefillBatchSize | uint32_t | [1, maxBatchSize] | 最大prefill batch size。maxPrefillBatchSize和maxPrefillTokens誰先達到各自的取值就完成本次組batch。該參數主要是在明確需要限制prefill階段batch size的場景下使用,否則可以設置為0(此時引擎將默認取maxBatchSize值)或與maxBatchSize值相同。必填,默認值:50。 |
maxPrefillTokens | uint32_t | [5120, 512000],且必須大于或等于maxSeqLen的取值。 | 每次prefill時,當前batch中所有input token總數,不能超過maxPrefillTokens。maxPrefillTokens和maxPrefillBatchSize誰先達到各自的取值就完成本次組batch。必填,默認值:8192。 |
prefillTimeMsPerReq | uint32_t | [0, 1000] | 與decodeTimeMsPerReq比較,計算當前應該選擇prefill還是decode。單位:ms,當“supportSelectBatch”=true時有效。其調度策略流程圖請參見圖1。必填,默認值:150。 |
prefillPolicyType | uint32_t | 013 | prefill階段的調度策略,其調度策略流程圖請參見圖2。0:FCFS,先來先服務。1:STATE,prefill階段等同于FCFS策略。3:MLFQ,多級反饋隊列。其中,3是0/1的組合。必填,默認值:0。 |
decodeTimeMsPerReq | uint32_t | [0, 1000] | 與prefillTimeMsPerReq比較,計算當前應該選擇prefill還是decode。單位:ms,當“supportSelectBatch”=true時有效。其調度策略流程圖請參見圖1。必填,默認值:50。 |
decodePolicyType | uint32_t | 013 | decode階段的調度策略。其調度策略流程圖請參見圖2。0:FCFS,先來先服務。1:STATE,decode階段優先執行未被搶占和換出的請求。3:MLFQ,多級反饋隊列。其中,3是0/1的組合。必填,默認值:0。 |
maxBatchSize | uint32_t | [1, 5000],且必須大于或等于maxPreemptCount的取值。 | 最大decode batch size。首先計算block_num:Total Block Num = Floor(NPU顯存/(模型網絡數cacheBlockSize模型注意力頭數注意力頭大小Cache類型字節數Cache數)),其中,Cache數=2;在tensor并行的情況下,block_numworld_size為實際的分配block數。如果是多卡,公式中的模型注意力頭數注意力大小的值需要均攤在每張卡上,即“模型注意力頭數注意力大小/卡數”。公式中的Floor表示計算結果向下取整。為每個請求申請的block數量Block Num=Ceil(輸入Token數/Block Size)+Ceil(最大輸出Token數/Block Size)。輸入Token數:輸入(字符串)做完tokenizer后的tokenID個數;最大輸出Token數:模型推理最大迭代次數和最大輸出長度之間取較小值。公式中的Ceil表示計算結果向上取整。maxBatchSize=Total Block Num/Block Num。必填,默認值:200。 |
maxIterTimes | uint32_t | [1, maxSeqLen-1] | 迭代次數,即一句話最大可生成長度。與允許推理生成的最大token個數max_tokens(或max_new_tokens)取較小值作為最大可生成長度。必填,默認值:512。 |
maxPreemptCount | int32_t | [0, maxBatchSize],當取值大于0時,cpuMemSize取值不可為0。 | 每一批次最大可搶占請求的上限,即限制一輪調度最多搶占請求的數量,最大上限為maxBatchSize,取值大于0則表示開啟可搶占功能。必填,默認值:0。 |
supportSelectBatch | bool | truefalse | batch選擇策略。false:表示每一輪調度時,優先調度和執行prefill階段的請求。true:表示每一輪調度時,根據當前prefill與decode請求的數量,自適應調整prefill和decode階段請求調度和執行的先后順序。必填,默認值:false。 |
maxQueueDelayMicroseconds | uint32_t | [500, 1000000] | 隊列等待時間,單位:us。必填,默認值:5000。 |
圖1 調度策略和執行先后順序流程圖
圖2 prefill和decode階段的調度策略流程圖
?
啟動模型
拉起服務化接口
cd /usr/local/Ascend/mindie/latest/mindie-service/bin
./mindieservice_daemon
后臺啟動
cd $MIES_INSTALL_PATH
nohup ./bin/mindieservice_daemon > output.log 2>&1 &
tail -f output.log# nuhup 開啟一個后臺進程
[1] 107
# 殺死進程 kill 107
Daemon start success! 則為啟動成功
?
接口測試
time curl -X POST http://127.0.0.1:1025/v1/chat/completions \-H "Accept: application/json" \-H "Content-type: application/json" \-d '{"model": "deepseek-14b","messages": [{"role": "user","content": "我有五天假期,我想去海南玩,請給我一個攻略"}],"max_tokens": 2048,"presence_penalty": 1.03,"frequency_penalty": 1.0,"seed": null,"temperature": 0.5,"top_p": 0.95,"stream": false
}'
?
腳本測試(可選)
cd $ATB_SPEED_HOME_PATH
python examples/run_pa.py --model_path /storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B
?
并發測試
14B - 單卡運行
八張卡 八個實例
設備 | 模型 | 上下文(輸出+輸出長度) | 并發 | 循環次數 | 并發請求總輸出速率(tokens/s) | 單個請求速率的平均 | 請求超時個數(超過60s的請求) |
---|---|---|---|---|---|---|---|
910B3 * 8 | deepseek-14b | 2048 | 1 | 1 | 33.03 | 33.03 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 1 | 1 | 31.91 | 31.91 | 0 |
910B3 * 8 | deepseek-14b | 8192 | 1 | 1 | 31.08 | 31.08 | 0 |
910B3 * 8 | deepseek-14b | 2048 | 4 | 1 | 101.63 | 32.93 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 4 | 1 | 113.43 | 31.98 | 0 |
910B3 * 8 | deepseek-14b | 8192 | 4 | 1 | 94.86 | 31.11 | 0 |
910B3 * 8 | deepseek-14b | 2048 | 8 | 1 | 213.05 | 31.99 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 8 | 1 | 185.08 | 30.09 | 0 |
910B3 * 8 | deepseek-14b | 8192 | 8 | 1 | 154.08 | 29.45 | 0 |
910B3 * 8 | deepseek-14b | 2048 | 16 | 1 | 284.99 | 31.00 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 16 | 1 | 279.60 | 29.44 | 0 |
910B3 * 8 | deepseek-14b | 8192 | 16 | 1 | 346.78 | 27.92 | 0 |
910B3 * 8 | deepseek-14b | 2048 | 32 | 1 | 579.98 | 29.46 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 32 | 1 | 575.08 | 26.80 | 0 |
910B3 * 8 | deepseek-14b | 8192 | 32 | 1 | 560.29 | 24.92 | 0 |
910B3 * 8 | deepseek-14b | 2048 | 64 | 1 | 932.15 | 24.59 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 64 | 1 | 1118.59 | 24.52 | 0 |
910B3 * 8 | deepseek-14b | 8192 | 64 | 1 | 816.21 | 21.98 | 2 |
910B3 * 8 | deepseek-14b | 2048 | 96 | 1 | 1294.45 | 25.58 | 0 |
910B3 * 8 | deepseek-14b | 4096 | 96 | 1 | 1437.15 | 21.76 | 2 |
910B3 * 8 | deepseek-14b | 8192 | 96 | 1 | 1291.17 | 18.78 | 5 |
910B3 * 8 | deepseek-14b | 2048 | 128 | 1 | 1307.53 | 20.16 | 5 |
910B3 * 8 | deepseek-14b | 4096 | 128 | 1 | 1560.00 | 16.81 | 28 |
910B3 * 8 | deepseek-14b | 8192 | 128 | 1 | 1348.41 | 13.06 | 37 |
910B3 * 8 | deepseek-14b | 2048 | 196 | 1 | 1417.76 | 12.30 | 77 |
910B3 * 8 | deepseek-14b | 4096 | 196 | 1 | 404.82 | 2.84 | 171 |
910B3 * 8 | deepseek-14b | 8192 | 196 | 1 | 521.18 | 2.94 | 162 |
32B - 雙卡并行
八張卡 四個實例
設備 | 模型 | 上下文(輸出+輸出長度) | 并發 | 循環次數 | 并發請求總輸出速率(tokens/s) | 單個請求速率的平均 | 請求超時個數(超過60s的請求) |
---|---|---|---|---|---|---|---|
910B3 * 8 | deepseek-32b | 2048 | 1 | 1 | 27.64 | 27.64 | 0 |
910B3 * 8 | deepseek-32b | 4096 | 1 | 1 | 26.43 | 26.43 | 0 |
910B3 * 8 | deepseek-32b | 8192 | 1 | 1 | 25.09 | 25.09 | 0 |
910B3 * 8 | deepseek-32b | 2048 | 4 | 1 | 80.31 | 26.23 | 0 |
910B3 * 8 | deepseek-32b | 4096 | 4 | 1 | 67.86 | 23.03 | 0 |
910B3 * 8 | deepseek-32b | 8192 | 4 | 1 | 81.54 | 23.39 | 0 |
910B3 * 8 | deepseek-32b | 2048 | 8 | 1 | 147.15 | 23.17 | 0 |
910B3 * 8 | deepseek-32b | 4096 | 8 | 1 | 131.06 | 22.09 | 0 |
910B3 * 8 | deepseek-32b | 8192 | 8 | 1 | 123.23 | 20.39 | 0 |
910B3 * 8 | deepseek-32b | 2048 | 16 | 1 | 279.69 | 21.08 | 0 |
910B3 * 8 | deepseek-32b | 4096 | 16 | 1 | 161.08 | 19.83 | 2 |
910B3 * 8 | deepseek-32b | 8192 | 16 | 1 | 223.36 | 19.38 | 0 |
910B3 * 8 | deepseek-32b | 2048 | 32 | 1 | 312.54 | 21.06 | 0 |
910B3 * 8 | deepseek-32b | 4096 | 32 | 1 | 367.03 | 18.93 | 1 |
910B3 * 8 | deepseek-32b | 8192 | 32 | 1 | 273.43 | 18.20 | 5 |
910B3 * 8 | deepseek-32b | 2048 | 64 | 1 | 762.26 | 20.52 | 0 |
910B3 * 8 | deepseek-32b | 4096 | 64 | 1 | 521.32 | 16.75 | 6 |
910B3 * 8 | deepseek-32b | 8192 | 64 | 1 | 442.43 | 14.48 | 15 |
910B3 * 8 | deepseek-32b | 2048 | 96 | 1 | 866.97 | 18.46 | 1 |
910B3 * 8 | deepseek-32b | 4096 | 96 | 1 | 905.75 | 11.65 | 20 |
910B3 * 8 | deepseek-32b | 8192 | 96 | 1 | 471.27 | 5.59 | 50 |
910B3 * 8 | deepseek-32b | 2048 | 128 | 1 | 522.60 | 7.00 | 75 |
910B3 * 8 | deepseek-32b | 4096 | 128 | 1 | 117.51 | 0.99 | 118 |
910B3 * 8 | deepseek-32b | 8192 | 128 | 1 | 0.00 | 0.00 | 128 |
910B3 * 8 | deepseek-32b | 2048 | 196 | 1 | 1345.32 | 14.69 | 91 |
910B3 * 8 | deepseek-32b | 4096 | 196 | 1 | 925.30 | 11.43 | 146 |
910B3 * 8 | deepseek-32b | 8192 | 196 | 1 | 755.33 | 9.04 | 166 |
并發測試腳本代碼
找一個文件夾,創建、執行并發請求腳本
- python model_request_test.py
- python statistic.py
- 新建請求腳本
vi model_request_test.py
# -*- coding: utf-8 -*-
# @Time : 2025/2/14 14:29import os.pathimport asyncio
import aiohttp
import time
import json
import logging# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')test_context = """
我們過了江,進了車站。我買票,他忙著照看行李。行李太多了,得向腳夫⑾行些小費才可過去。他便又忙著和他們講價錢。我那時真是聰明過分,總覺他說話不大漂亮,非自己插嘴不可,但他終于講定了價錢;就送我上車。他給我揀定了靠車門的一張椅子;我將他給我做的紫毛大衣鋪好座位。他囑我路上小心,夜里要警醒些,不要受涼。又囑托茶房好好照應我。我心里暗笑他的迂;他們只認得錢,托他們只是白托!而且我這樣大年紀的人,難道還不能料理自己么?我現在想想,我那時真是太聰明了。
我說道:“爸爸,你走吧。”他往車外看了看,說:“我買幾個橘子去。你就在此地,不要走動。”我看那邊月臺的柵欄外有幾個賣東西的等著顧客。走到那邊月臺,須穿過鐵道,須跳下去又爬上去。父親是一個胖子,走過去自然要費事些。我本來要去的,他不肯,只好讓他去。我看見他戴著黑布小帽,穿著黑布大馬褂⑿,深青布棉袍,蹣跚⒀地走到鐵道邊,慢慢探身下去,尚不大難。可是他穿過鐵道,要爬上那邊月臺,就不容易了。他用兩手攀著上面,兩腳再向上縮;他肥胖的身子向左微傾,顯出努力的樣子。這時我看見他的背影,我的淚很快地流下來了。我趕緊拭干了淚。怕他看見,也怕別人看見。我再向外看時,他已抱了朱紅的橘子往回走了。過鐵道時,他先將橘子散放在地上,自己慢慢爬下,再抱起橘子走。到這邊時,我趕緊去攙他。他和我走到車上,將橘子一股腦兒放在我的皮大衣上。于是撲撲衣上的泥土,心里很輕松似的。過一會兒說:“我走了,到那邊來信!”我望著他走出去。他走了幾步,回過頭看見我,說:“進去吧,里邊沒人。”等他的背影混入來來往往的人里,再找不著了,我便進來坐下,我的眼淚又來了。
"""# 輸入文本列表 此處為示例,實際測試請使用長度在 1800、3500、7000 字左右的文本作為輸入 使得上下文長度在 2048、4096、8192 字左右
input_texts = [test_context * (2048 // len(test_context)) + "\n====\n總結以上文本為字數200字的摘要。",test_context * (4096 // len(test_context)) + "\n====\n總結以上文本為字數500字的摘要。",test_context * (8192 // len(test_context)) + "\n====\n總結以上文本為字數1000字的摘要。",
]# 并發請求列表
concurrency_levels = [1, 4, 8, 16, 32, 64, 96, 128, 196]
# concurrency_levels = [96, 128, 196]
# concurrency_levels = [1]# 循環次數
loop_count = 1# 請求接口地址
url = "http://127.0.0.1:1025/v1/chat/completions"# 設備和模型信息
device = "910B3 * 8"
# model = "DeepSeek-R1-Distill-32B"
model = "deepseek-14b" # 此處對應配置文件中的 ModelDeployConfig.ModelConfig.modelNameif not os.path.exists(model):os.mkdir(model)async def make_request(session, input_text):# logging.info("開始單個請求")headers = {"Accept": "application/json","Content-type": "application/json"}data = {"model": model,"messages": [{"role": "user", "content": input_text}],"max_tokens": 2048,"presence_penalty": 1.03,"frequency_penalty": 1.0,"seed": None,"temperature": 0.5,"top_p": 0.95,"stream": True}start_time = time.time()try:async with session.post(url, headers=headers, json=data, timeout=60) as response:output_tokens = 0async for chunk in response.content.iter_chunked(65535):try:chunk_str = chunk.decode('utf-8').strip()if chunk_str.startswith("data: "):chunk_str = chunk_str[len("data: "):]chunk_data = json.loads(chunk_str)"""data: {"id":"endpoint_common_34","object":"chat.completion.chunk","created":1739519727,"model":"deepseek-32b","usage":{"prompt_tokens":6,"completion_tokens":27,"total_tokens":33},"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":"stop"}]}"""output_tokens += 1except (json.JSONDecodeError, UnicodeDecodeError):continueend_time = time.time()elapsed_time = end_time - start_timeprint(f"elapsed_time: 0.0614")output_rate = output_tokens / elapsed_time if elapsed_time > 0 else 0logging.info(f"單個請求完成,輸出 tokens: {output_tokens},耗時: {elapsed_time:.2f}s,輸出速率: {output_rate:.2f} tokens/s")return output_tokens, elapsed_time, output_rateexcept asyncio.TimeoutError:logging.warning("單個請求超時")return 0, 60, 0except Exception as e:print(f"ERROR: {e}")return 0, 60, 0async def run_concurrent_tests(concurrency, input_text):logging.info(f"開始并發數為 {concurrency} 的測試")async with aiohttp.ClientSession() as session:tasks = [make_request(session, input_text) for _ in range(concurrency)]results = await asyncio.gather(*tasks)total_output_tokens = sum([result[0] for result in results])total_elapsed_time = max([result[1] for result in results])total_output_rate = total_output_tokens / total_elapsed_time if total_elapsed_time > 0 else 0average_single_rate = sum([result[2] for result in results]) / concurrencytimeout_count = sum([1 for result in results if result[1] >= 60])logging.info(f"并發數為 {concurrency} 的測試完成,總輸出 tokens: {total_output_tokens},總耗時: {total_elapsed_time:.2f}s,"f"并發請求總輸出速率: {total_output_rate:.2f} tokens/s,單個請求速率平均: {average_single_rate:.2f} tokens/s,超時個數: {timeout_count}")return total_output_rate, average_single_rate, timeout_countasync def main():print("|設備|模型|上下文(輸出+輸出長度)|并發|循環次數|并發請求總輸出速率(tokens/s)|單個請求速率的平均|請求超時個數(超過60s的請求)|")print("| ------| ------| --------| ------| ----------| ------------------| ----------| --------------|")for concurrency in concurrency_levels:all_results = []for i, input_text in enumerate(input_texts):input_length = len(input_text)total_output_rate, average_single_rate, timeout_count = await run_concurrent_tests(concurrency, input_text)context = 2048 * (2 ** i)print(f"測試 {i + 1}/{len(input_texts)} 完成,并發數為 {concurrency},循環次數為 {loop_count}")result = {"設備": device,"模型": model,"上下文(輸出+輸出長度)": context,"并發": concurrency,"循環次數": loop_count,"并發請求總輸出速率(tokens/s)": total_output_rate,"單個請求速率的平均": average_single_rate,"請求超時個數(超過60s的請求)": timeout_count}all_results.append(result)print(f"|{device}|{model}|{context}|{concurrency}|{loop_count}|{total_output_rate:.2f}|{average_single_rate:.2f}|{timeout_count}|")# 按并發數保存到 JSON 文件filename = f'{model}/test_results_concurrency_{concurrency}.json'with open(filename, 'w', encoding='utf-8') as f:json.dump(all_results, f, ensure_ascii=False, indent=4)logging.info(f"并發數為 {concurrency} 的測試結果已保存到 {filename}")if __name__ == "__main__":asyncio.run(main())
- 新建統計腳本
vi statistic.py
# -*- coding: utf-8 -*-
# @Time : 2025/2/17 8:32
import json# 并發請求列表
concurrency_levels = [1, 4, 8, 16, 32, 64, 96, 128, 196]
version = 'deepseek-14b' # 此處對應配置文件中的 ModelDeployConfig.ModelConfig.modelName# 匯總所有結果
all_results = []
for concurrency in concurrency_levels:filename = f'{version}/test_results_concurrency_{concurrency}.json'try:with open(filename, 'r', encoding='utf-8') as f:results = json.load(f)all_results.extend(results)except FileNotFoundError:print(f"未找到文件 {filename},請確保之前的測試已成功保存結果。")# 生成 Markdown 表格表頭
markdown_table = "|設備|模型|上下文(輸出+輸出長度)|并發|循環次數|并發請求總輸出速率(tokens/s)|單個請求速率的平均|請求超時個數(超過60s的請求)|\n"
markdown_table += "| ------| ------| --------| ------| ----------| ------------------| ----------| --------------|\n"# 填充表格內容
for result in all_results:markdown_table += f"|{result['設備']}|{result['模型']}|{result['上下文(輸出+輸出長度)']}|{result['并發']}|{result['循環次數']}|{result['并發請求總輸出速率(tokens/s)']:.2f}|{result['單個請求速率的平均']:.2f}|{result['請求超時個數(超過60s的請求)']}|\n"# 輸出 Markdown 表格
print(markdown_table)# 保存 Markdown 表格到文件
with open(f'{version}/summary_table.md', 'w', encoding='utf-8') as f:f.write(markdown_table)
報錯
Operation not permitted
[root@pm-a813-005 bin]# ./mindieservice_daemon
terminate called after throwing an instance of 'system_error'what(): Operation not permitted
模型路徑的權限設置錯誤
chmod -R 755 /path-to-weights
參考 mindie/README.md · Ascend/ascend-docker-image - Gitee.com
ConnectionRefusedError
[root@pm-a813-005 /]# vi /usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
[root@pm-a813-005 /]# cd /usr/local/Ascend/mindie/latest/mindie-service/bin
[root@pm-a813-005 bin]# ./mindieservice_daemon
...
Traceback (most recent call last):File "/usr/lib64/python3.11/multiprocessing/process.py", line 314, in _bootstrapself.run()File "/usr/lib64/python3.11/multiprocessing/process.py", line 108, in runself._target(*self._args, **self._kwargs)File "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/common/repository_manager/route.py", line 71, in wrapperraise expFile "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/common/repository_manager/route.py", line 63, in wrapperfunc(*args, **kwargs)File "/usr/local/Ascend/ascend-toolkit/latest/python/site-packages/tbe/common/repository_manager/route.py", line 268, in task_distributekey, func_name, detail = resource_proxy[TASK_QUEUE].get()^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "<string>", line 2, in getFile "/usr/lib64/python3.11/multiprocessing/managers.py", line 822, in _callmethodkind, result = conn.recv()^^^^^^^^^^^File "/usr/lib64/python3.11/multiprocessing/connection.py", line 250, in recvbuf = self._recv_bytes()^^^^^^^^^^^^^^^^^^File "/usr/lib64/python3.11/multiprocessing/connection.py", line 430, in _recv_bytesbuf = self._recv(4)^^^^^^^^^^^^^File "/usr/lib64/python3.11/multiprocessing/connection.py", line 395, in _recvchunk = read(handle, remaining)^^^^^^^^^^^^^^^^^^^^^^^
ConnectionResetError: [Errno 104] Connection reset by peer
/usr/lib64/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 30 leaked semaphore objects to clean up at shutdownwarnings.warn('resource_tracker: There appear to be %d '
/usr/lib64/python3.11/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 30 leaked semaphore objects to clean up at shutdownwarnings.warn('resource_tracker: There appear to be %d '
Daemon is killing...
Killed
當前鏡像 和 宿主機服務器的 驅動版本不對應,前往官網換個鏡像
引用pytorch
警告而已,影響不大
[root@pm-a813-005 atb-models]# python
Python 3.11.6 (main, Nov 27 2024, 18:16:08) [GCC 12.3.1 (openEuler 12.3.1-38.oe2403)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch>>> import torch_npu
/usr/local/lib64/python3.11/site-packages/torch_npu/__init__.py:248: UserWarning: On the interactive interface, the value of TASK_QUEUE_ENABLE is set to 0 by default. Do not set it to 1 to prevent some unknown errorswarnings.warn("On the interactive interface, the value of TASK_QUEUE_ENABLE is set to 0 by default. \
>>>
the size of npuDeviceIds (subset) does not equal to worldSize
the size of npuDeviceIds (subset) does not equal to worldSize
ERR: Failed to init endpoint! Please check the service log or console output.
Killed
此錯誤表明 npuDeviceIds?(可能是 NPU 設備 ID 的子集)的數量與 worldSize? 不匹配。在分布式計算的場景下,worldSize? 通常代表參與計算的所有進程或設備的總數,而 npuDeviceIds? 則是指定要使用的 NPU 設備的 ID 列表。當這兩者的數量不一致時,就會觸發該錯誤。
vi /usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
...
"BackendConfig" : {"backendName" : "mindieservice_llm_engine","modelInstanceNumber" : 1,"npuDeviceIds" : [[0]],....
"ModelConfig" : [{"modelInstanceType" : "Standard","modelName" : "deepseek-14b","modelWeightPath" : "/storage/llm/deepseek-ai/DeepSeek-R1-Distill-Qwen-14B","worldSize" : 1, # 此處數量要與 npuDeviceIds 一致
....
Failed to init endpoint
The serverConfig.kmcKsfMaster path is invalid by: The input file: ksfa is not a regular file or not exists
The serverConfig.kmcKsfStandby path is invalid by: The input file: ksfb is not a regular file or not exists
The serverConfig_.tlsCert path is invalid by: The input file: server.pem is not a regular file or not exists
ERR: serverConfig_.tlsCrlFiles file not exit .
The serverConfig_.tlsCaFile path is invalid by: The input file: ca.pem is not a regular file or not exists
The serverConfig_.tlsPk path is invalid by: The input file: server.key.pem is not a regular file or not exists
The serverConfig_.tlsPkPwd path is invalid by: The input file: key_pwd.txt is not a regular file or not exists
The ServerConfig.managementTlsCert path is invalid by: The input file: server.pem is not a regular file or not exists
The ServerConfig.managementTlsCrlPath path is not a dir by:
ERR: serverConfig_.managementTlsCrlFiles file not exit .
ERR: serverConfig_.managementTlsCaFile file not exit .
The ServerConfig.managementTlsPk path is invalid by: The input file: server.key.pem is not a regular file or not exists
The ServerConfig.managementTlsPkPwd path is invalid by: The input file: key_pwd.txt is not a regular file or not exists
ERR: Failed to init endpoint! Please check the service log or console output.
Killed
解決方法就是取消https 啟動服務
vi /usr/local/Ascend/mindie/latest/mindie-service/conf/config.json
"ServerConfig" :{"ipAddress" : "127.0.0.1","managementIpAddress" : "127.0.0.2","port" : 1025,"managementPort" : 1026,"metricsPort" : 1027,"allowAllZeroIpListening" : false,"maxLinkNum" : 1000,"httpsEnabled" : false, # 設置為 false 不是用https
。。。
Please check the service log or console output.
ERR: Failed to init endpoint! Please check the service log or console output. Killed
實例啟動太多 共享內存不夠,導致日志寫入失敗
解決: 減少實例數量 或者增加 增加共享內存空間
docker run .... --shm-size=10g
其他查詢指令
系統架構
uname -m
NPU 信息
npu-smi info
CANN 版本
- x86
cat /usr/local/Ascend/ascend-toolkit/latest/x86_64-linux/ascend_toolkit_install.info
- arm
cat /usr/local/Ascend/ascend-toolkit/latest/arm64-linux/ascend_toolkit_install.info
[root@pm-a813-005 /]# cat /usr/local/Ascend/ascend-toolkit/latest/arm64-linux/ascend_toolkit_install.info
package_name=Ascend-cann-toolkit
version=8.0.0
innerversion=V100R001C20SPC001B251
compatible_version=[V100R001C15],[V100R001C17],[V100R001C18],[V100R001C19],[V100R001C20]
arch=aarch64
os=linux
path=/usr/local/Ascend/ascend-toolkit/8.0.0/aarch64-linux
基礎環境搭建
獲取CANN&MindIE安裝包&環境準備
- Atlas 800I A2/Atlas 300I Duo/Atlas 300 V
- 環境準備指導
CANN安裝
# 增加軟件包可執行權限,{version}表示軟件版本號,{arch}表示CPU架構,{soc}表示昇騰AI處理器的版本。
chmod +x ./Ascend-cann-toolkit_{version}_linux-{arch}.run
chmod +x ./Ascend-cann-kernels-{soc}_{version}_linux.run
# 校驗軟件包安裝文件的一致性和完整性
./Ascend-cann-toolkit_{version}_linux-{arch}.run --check
./Ascend-cann-kernels-{soc}_{version}_linux.run --check
# 安裝
./Ascend-cann-toolkit_{version}_linux-{arch}.run --install
./Ascend-cann-kernels-{soc}_{version}_linux.run --install# 設置環境變量
source /usr/local/Ascend/ascend-toolkit/set_env.sh
MindIE安裝
# 增加軟件包可執行權限,{version}表示軟件版本號,{arch}表示CPU架構。
chmod +x ./Ascend-mindie_${version}_linux-${arch}.run
./Ascend-mindie_${version}_linux-${arch}.run --check# 方式一:默認路徑安裝
./Ascend-mindie_${version}_linux-${arch}.run --install
# 設置環境變量
cd /usr/local/Ascend/mindie && source set_env.sh# 方式二:指定路徑安裝
./Ascend-mindie_${version}_linux-${arch}.run --install-path=${AieInstallPath}
# 設置環境變量
cd ${AieInstallPath}/mindie && source set_env.sh
Torch_npu安裝
下載 pytorch_v{pytorchversion}_py{pythonversion}.tar.gz
tar -xzvf pytorch_v{pytorchversion}_py{pythonversion}.tar.gz
# 解壓后,會有whl包
pip install torch_npu-{pytorchversion}.xxxx.{arch}.whl
相關鏈接
- 模型庫-ModelZoo-昇騰社區
- 模型庫-魔搭社區
- https://modelers.cn/MindIE
- modelscope 魔搭社區模型下載
- mindie/README.md · Ascend/ascend-docker-image - Gitee.com
- 配置參數說明-快速開始-MindIE Service開發指南-服務化集成部署-MindIE1.0.RC2開發文檔-昇騰社區
- 單機推理-配置MindIE Server-配置MindIE-MindIE安裝指南-環境準備-MindIE1.0.RC2開發文檔-昇騰社區
- DeepSeek-R1-Distill-Qwen-32B-模型庫-ModelZoo-昇騰社區
- mindie鏡像版本下載
- Altas產品查詢CANN軟件包版本的方法 - 華為
- npu-smi命令介紹(適用于1.0.11-1.0.15版本) - Atlas 300I 推理卡 用戶指南(型號 3010)31 - 華為?
-
昇騰模型庫
-
MindIE官方文檔
-
MindIE Service開發指南
-
DeepSeek-R1模型卡片
-
DeepSeek模型量化方法介紹
-
昇騰鏡像倉庫
-
量化技術白皮書
-
Ascend/ModelZoo-PyTorch
-
在線推理過程中可使用的環境變量配置
-
昇騰社區資源下載
-
CANN環境準備指導
-
DeepSeek 系列模型 華為昇騰官方教程
模型名稱 安裝教程 DeepSeek V3 DeepSeek-V3-模型庫-ModelZoo-昇騰社區 DeepSeek R1 DeepSeek-R1-模型庫-ModelZoo-昇騰社區 DeepSeek-R1-Distill-Qwen-1.5B DeepSeek-R1-Distill-Qwen-1.5B-模型庫-ModelZoo-昇騰社區 DeepSeek-R1-Distill-Qwen-7B DeepSeek-R1-Distill-Qwen-7B-模型庫-ModelZoo-昇騰社區 DeepSeek-R1-Distill-Llama-8B DeepSeek-R1-Distill-Llama-8B-模型庫-ModelZoo-昇騰社區 DeepSeek-R1-Distill-Qwen-14B DeepSeek-R1-Distill-Qwen-14B-模型庫-ModelZoo-昇騰社區 DeepSeek-R1-Distill-Qwen-32B DeepSeek-R1-Distill-Qwen-32B-模型庫-ModelZoo-昇騰社區 DeepSeek-R1-Distill-Llama-70B DeepSeek-R1-Distill-Llama-70B-模型庫-ModelZoo-昇騰社區 Janus-Pro-7B Janus-Pro-模型庫-ModelZoo-昇騰社區