Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Alibaba MNN HuggingFace Model Download

From Leeroopedia


Field Value
implementation_name HuggingFace_Model_Download
implementation_type External Tool Doc
repository Alibaba_MNN
workflow LLM_Deployment_Pipeline
pipeline_stage Source Acquisition
source_file N/A (user-side operation)
last_updated 2026-02-10 14:00 GMT

Summary

This implementation documents the user-side process of downloading pre-trained LLM model artifacts from HuggingFace Hub or ModelScope using git and git-lfs. The downloaded model directory serves as the input to the MNN export pipeline (llmexport.py).

API Signature

# Step 1: Install Git LFS (one-time setup)
git lfs install

# Step 2: Clone the model repository
git clone https://huggingface.co/<org>/<model-name>
# or from ModelScope:
git clone https://www.modelscope.cn/<org>/<model-name>.git

External Dependencies

  • git: Version control system (version 2.x or later)
  • git-lfs: Git Large File Storage extension (version 3.x recommended)
  • Network access: Connectivity to HuggingFace Hub (huggingface.co) or ModelScope (modelscope.cn)

Key Parameters

Parameter Description Example
Model repo URL Full URL to the model repository on HuggingFace or ModelScope https://huggingface.co/Qwen/Qwen2-0.5B-Instruct
Model variant/size The specific model size and variant to download Qwen2-0.5B-Instruct, Llama-3-8B, DeepSeek-V2-Lite
--depth (optional) Shallow clone depth to reduce download time --depth 1

Inputs

  • A HuggingFace model identifier (e.g., Qwen/Qwen2-0.5B-Instruct) or a full URL to the model repository
  • Sufficient local disk space for the model weights

Outputs

A local directory containing the complete model artifacts:

File Description
config.json Model architecture configuration (hidden_size, num_layers, model_type, etc.)
tokenizer.json Tokenizer vocabulary and encoding rules
tokenizer_config.json Tokenizer settings (special tokens, chat template, etc.)
*.safetensors or *.bin Model weight files (the actual learned parameters)
generation_config.json Default generation parameters (temperature, top_p, etc.)
special_tokens_map.json Mapping of special tokens (BOS, EOS, PAD, etc.)

Usage Example

# Install Git LFS if not already installed
git lfs install

# Clone Qwen2-0.5B-Instruct from ModelScope
git clone https://www.modelscope.cn/qwen/Qwen2-0.5B-Instruct.git

# Verify that weight files are properly downloaded (not LFS pointers)
ls -lh Qwen2-0.5B-Instruct/*.safetensors
# Expected: files should be hundreds of MB, not a few hundred bytes

# Check model type for MNN compatibility
python -c "import json; c=json.load(open('Qwen2-0.5B-Instruct/config.json')); print(c['model_type'])"
# Expected output: qwen2

Post-Download Verification

After cloning, it is critical to verify that weight files were properly downloaded:

# Check file sizes - LFS pointer files are only ~130 bytes
find Qwen2-0.5B-Instruct/ -name "*.safetensors" -exec ls -lh {} \;

# If files are suspiciously small, re-pull with LFS
cd Qwen2-0.5B-Instruct && git lfs pull

Notes

  • The MNN documentation explicitly warns: "clone 后检查一下模型大小,有可能因为lfs没安装导致下载的是空模型" (After cloning, check the model size; LFS may not be installed, resulting in an empty model).
  • For users in China, ModelScope mirrors typically offer significantly faster download speeds than HuggingFace.
  • The downloaded directory is passed directly to llmexport.py --path in the next pipeline stage.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment