This Skill provides two core capabilities:
- Download model weights from HuggingFace or ModelScope
- Generate fake weights (random initialization) based on the Diffusers Pipeline config files, for business validation
Quick Start
1. Download Model Weights
Download from HuggingFace:
pip install -U huggingface_hub
# 基础用法
hf download Wan-AI/Wan2.2-I2V-A14B-Diffusers
Using a proxy (for access within China)
export HF_ENDPOINT=https://hf-mirror.com hf download Wan-AI/Wan2.2-I2V-A14B-Diffusers
Download via script (supports dry-run testing)python scripts/download_weights.py hf Wan-AI/Wan2.2-I2V-A14B-Diffusers --proxy https://hf-mirror.com python scripts/download_weights.py hf Wan-AI/Wan2.2-I2V-A14B-Diffusers --dry-run
**从 ModelScope 下载:**
```bash
pip install modelscope
# 基础用法
modelscope download --model Wan-AI/Wan2.2-T2V-A14B
# 通过脚本下载
python scripts/download_weights.py modelscope Wan-AI/Wan2.2-T2V-A14B -o ./models
python scripts/download_weights.py modelscope Wan-AI/Wan2.2-T2V-A14B --dry-run
2. Generate Fake Weights
Automatically download metadata from HuggingFace (config.json, model_index.json, tokenizer, etc.,without downloading weight files), then randomly initialize each sub-model based on the config and save it, generating fake weightswith a file structure completely identicalto the original model.
Generate directly from HuggingFace:
# 生成 Z-Image-Turbo 假权重
python scripts/generate_fake_weights.py from-hub Tongyi-MAI/Z-Image-Turbo -o ./fake_z_image --dtype bfloat16
# 生成 Qwen-Image-2512 假权重(国内使用镜像)
python scripts/generate_fake_weights.py from-hub Qwen/Qwen-Image-2512 -o ./fake_qwen --proxy https://hf-mirror.com
Generate from an existing local metadata directory:
python scripts/generate_fake_weights.py from-local ./model_metadata_dir -o ./fake_weights --dtype bfloat16
Verify that the fake weights can be loaded normally:
import torch
import diffusers
pipe = diffusers.DiffusionPipeline.from_pretrained(
"./fake_z_image",
torch_dtype=torch.bfloat16,
)
print(f"Pipeline: {type(pipe).__name__}")
for name, comp in pipe.components.items():
if hasattr(comp, "parameters"):
pc = sum(p.numel() for p in comp.parameters())
print(f" {name}: {type(comp).__name__} ({pc:,} params)")
Environment Requirements
| Component | Installation Command | Description |
|---|---|---|
| huggingface_hub | pip install -U huggingface_hub |
HuggingFace download & fake weight metadata download |
| modelscope | pip install modelscope |
ModelScope download |
| torch | pip install torch |
Fake weight generation |
| diffusers | pip install diffusers |
Pipeline model instantiation |
| transformers | pip install transformers |
text_encoder instantiation |
Fake Weight Generation Principle
Generation process:
- Download metadata files from HuggingFace via
snapshot_download(excluding*.safetensors、*.bin) - Read
model_index.json, parse each component of the Pipeline (scheduler, text_encoder, tokenizer, transformer, vae) - For each model component, use
from_config()to instantiate the model from config.json (random weights) - Save via
save_pretrained(), automatically generating correctly formatted safetensors files and index.json - tokenizer and scheduler directly copy the config files
The generated directory structure is completely identical to the original model, for example Z-Image-Turbo:
fake_z_image_turbo/
├── model_index.json
├── scheduler/
│ └── scheduler_config.json
├── text_encoder/
│ ├── config.json
│ ├── generation_config.json
│ ├── model.safetensors
│ └── model.safetensors.index.json
├── tokenizer/
│ ├── merges.txt
│ ├── tokenizer_config.json
│ ├── tokenizer.json
│ └── vocab.json
├── transformer/
│ ├── config.json
│ ├── diffusion_pytorch_model-00001-of-00002.safetensors
│ ├── diffusion_pytorch_model-00002-of-00002.safetensors
│ └── diffusion_pytorch_model.safetensors.index.json
└── vae/
├── config.json
└── diffusion_pytorch_model.safetensors
Script Reference
download_weights.py
| Parameter | Required | Description |
|---|---|---|
source |
Yes | Download source:hf or modelscope |
model_id |
Yes | Model ID (e.g., Wan-AI/Wan2.2-I2V-A14B-Diffusers) |
-o, --output-dir |
No | Output directory |
--proxy |
No | HuggingFace proxy URL (only for hf source) |
--dry-run |
No | Test mode, does not actually download |
generate_fake_weights.py
Subcommand from-hub: Download metadata from HuggingFace + generate fake weights
| Parameter | Required | Description |
|---|---|---|
model_id |
Yes | HuggingFace Model ID |
-o, --output-dir |
Yes | Output directory |
--proxy |
No | HuggingFace proxy URL |
--dtype |
No | Data type:float32、float16、bfloat16(default:bfloat16) |
Subcommand from-local: Generate fake weights from a local metadata directory
| Parameter | Required | Description |
|---|---|---|
metadata_dir |
Yes | Local metadata directory (must contain model_index.json) |
-o, --output-dir |
Yes | Output directory |
--dtype |
No | Data type (default:bfloat16) |
Verified models
| Model | Pipeline type | Component | Verification status |
|---|---|---|---|
| Qwen/Qwen-Image-2512 | QwenImagePipeline | vae(127M) + text_encoder(8.3B) + transformer(20.4B) | ✅ |
| Tongyi-MAI/Z-Image-Turbo | ZImagePipeline | vae(84M) + text_encoder(4.0B) + transformer(6.2B) | ✅ |
Notes
- Fake weights are randomly initialized; the generated images are meaningless and are only used to verify the code workflow
- Generating fake weights for large models (>10B parameters) may require a lot of memory and time
- In mainland China, it is recommended to use
--proxy https://hf-mirror.comor set theHF_ENDPOINTenvironment variable - If you encounter a socks proxy conflict, first
unset all_proxy ALL_PROXYand then run