可本地部署使用的大模型顯存資源估算工具

原文地址:https://alphahinex.github.io/2025/02/16/model-memory-usage/


description: "解決線上版本當(dāng)前無法正常使用以及無法訪問的問題"
date: 2025.02.16 10:34
categories:
- AI
- Python
tags: [AI, Python, HuggingFace, LLM]
keywords: Hugging Face, Model Memory Calculator, Accelerate, Model was not found on the Hub


?? Model Memory Calculator?? Accelerate 庫提供的一個(gè)模型顯存計(jì)算工具,可估算模型訓(xùn)練或推理時(shí)所需的顯存大小。

但目前該在線工具無法正常使用,即使使用默認(rèn)的模型名稱,也會報(bào)在 Hub 中無法找到該模型:

在該 space 的 discussions 中也有不少人遇到了此問題。

本文提供一種本地化部署運(yùn)行此工具的方法,還可通過指定 HF_ENDPOINT 避免無法訪問 Hugging Face 的問題。

本地部署

hotfix 版本

直接部署 https://huggingface.co/spaces/hf-accelerate/model-memory-usage/tree/main 中的內(nèi)容會遇到一些問題,可使用 hotfix 分支的版本,主要改動內(nèi)容如下:

  1. requirements.txt 中增加 gradio==4.43.0 依賴。使用 README.md 中設(shè)定的 Gradio SDK 版本 4.36.0 可能會遇到 與 pydantic 版本不匹配導(dǎo)致的報(bào)錯(cuò),故升級至 4.43.0 版本。
  2. 修改 src/app.pyget_results 方法,修復(fù)官方應(yīng)用中無法在 Hub 中找到模型的問題。
diff --git a/src/app.py b/src/app.py
index 7a5e23e..500023a 100644
--- a/src/app.py
+++ b/src/app.py
@@ -7,6 +7,8 @@ from model_utils import calculate_memory, get_model


 def get_results(model_name: str, library: str, options: list, access_token: str):
+    if access_token == "":
+        access_token = None
     model = get_model(model_name, library, access_token)
     # try:
     #     has_discussion = check_for_discussion(model_name)

與原始版本具體區(qū)別可見 diff

Python 3.8

# conda create -n mmu-env python=3.8 -c https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
$ conda create -n mmu-env python=3.8
$ conda activate mmu-env

conda 環(huán)境安裝可參照 miniconda。

部署

$ git clone https://github.com/AlphaHinex/model-memory-usage.git
$ cd model-memory-usage

# pip install -r requirements.txt -i http://192.168.1.200/local/proxy/pypi/web/simple --trusted-host 192.168.1.200
# pip install -r requirements.txt
$ pip install -r requirements.txt -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

# python src/app.py
$ HF_ENDPOINT=https://hf-mirror.com python src/app.py

Model Name or URL 處輸入 deepseek-ai/DeepSeek-R1-Distill-Qwen-32B,在 Model Precision 選擇要估算的精度,點(diǎn)擊 Calculate Memory Usage

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容