原文地址: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)容如下:
-
requirements.txt中增加gradio==4.43.0依賴。使用 README.md 中設(shè)定的 Gradio SDK 版本4.36.0可能會遇到 與 pydantic 版本不匹配導(dǎo)致的報(bào)錯(cuò),故升級至4.43.0版本。 - 修改
src/app.py中get_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:
