通义万相2.1开源版本地化部署详细攻略,生成视频再添利器

2025 年 2 月 25 日晚上 11:00 通义万相 2.1 开源发布,前两周太忙没空搞它,这个周末,也来本地化部署一个,体验生成效果如何,总的来说,它在国内文生视频、图生视频的行列处于领先位置,同时也支持文生图。

一、开源代码下载来源

GitHub:https://github.com/Wan-Video/Wan2.1

这个源码包中可以做的事包括:

Wan2.1 Text-to-Video
 Multi-GPU Inference code of the 14B and 1.3B models
 Checkpoints of the 14B and 1.3B models
 Gradio demo
 ComfyUI integration
 Diffusers integration
 Diffusers + Multi-GPU Inference
Wan2.1 Image-to-Video
 Multi-GPU Inference code of the 14B model
 Checkpoints of the 14B model
 Gradio demo
 ComfyUI integration
 Diffusers integration
 Diffusers + Multi-GPU Inference

以下相关网址,有在线体验的,有可以下载配套模型的,也有可以下载源码的,根据需要自行选择,访问国外的网站请提前准备好科学上网。

官网:https://tongyi.aliyun.com/wanxiang/

博客:https://wanxai.com/

Modelscope:https://modelscope.cn/organization/Wan-AI

Hugging Face:https://huggingface.co/Wan-AI

二、下载python虚拟环境管理软件,安装较新版的python

下载地址:https://docs.conda.io/en/latest/miniconda.html

安装好后打开它,最好使用管理员模式打开。

依次敲入指令,创建并激活项目所需的虚拟环境。(关于conda的使用方法会单独出一篇教程,这里就不多解释了)

conda create --name Wan21 python=3.12.9

三、安装git

https://git-scm.com/

验证安装成功如下:

四、安装cuda

到官网CUDA Toolkit Archive | NVIDIA Developer 下载驱动,按提示安装。这里需要为自己的显卡选择具体的版本,命令行输入指令nvidia-smi查看对应版本。

下载后安装完配置一下环境变量

五、下载万象2.1源码

git clone https://github.com/Wan-Video/Wan2.1.git

六、安装万象2.1所需的依赖包

到conda的虚拟环境中来安装,给万象2.1配置专用的python运行环境。

conda activate Wan21

看看这个依赖源的清单,数量不多,建议还是手工一条条安装,以便看到哪一个在安装中出问题了,定向解决。

很多时候用上面的清单安装后,torch版本不支持cuda,可以参照下面这个网址,找到对应的版本去下载。

https://github.com/facebookresearch/xformers#installing-xformers

有时运行还会报错,缺少flash-attn依赖,可以根据对应的torch版本下载这个依赖包,不过编译的时间好长,只要不报错,一定要耐心等待,我可是等了半天多才完成编译。

我最终的依赖包清单如下:

(wanvideo21) F:\GitProject\Wan2.1>pip list
Package            Version
------------------ ------------
accelerate         1.4.0
aiofiles           23.2.1
aiohappyeyeballs   2.5.0
aiohttp            3.11.13
aiosignal          1.3.2
annotated-types    0.7.0
anyio              4.8.0
attrs              25.1.0
certifi            2025.1.31
charset-normalizer 3.4.1
click              8.1.8
colorama           0.4.6
dashscope          1.22.1
diffusers          0.32.2
easydict           1.13
einops             0.8.1
fastapi            0.115.11
ffmpy              0.5.0
filelock           3.17.0
flash_attn         2.7.3
frozenlist         1.5.0
fsspec             2025.2.0
ftfy               6.3.1
gradio             5.20.0
gradio_client      1.7.2
groovy             0.1.2
h11                0.14.0
httpcore           1.0.7
httpx              0.28.1
huggingface-hub    0.29.2
idna               3.10
imageio            2.37.0
imageio-ffmpeg     0.6.0
importlib_metadata 8.6.1
intel-openmp       2021.4.0
Jinja2             3.1.6
markdown-it-py     3.0.0
MarkupSafe         2.1.5
mdurl              0.1.2
mkl                2021.4.0
mpmath             1.3.0
multidict          6.1.0
networkx           3.4.2
numpy              1.26.0
opencv-python      4.11.0.86
orjson             3.10.15
packaging          24.2
pandas             2.2.3
pillow             11.1.0
pip                25.0.1
propcache          0.3.0
psutil             7.0.0
pydantic           2.10.6
pydantic_core      2.27.2
pydub              0.25.1
Pygments           2.19.1
python-dateutil    2.9.0.post0
python-multipart   0.0.20
pytz               2025.1
PyYAML             6.0.2
regex              2024.11.6
requests           2.32.3
rich               13.9.4
ruff               0.9.9
safehttpx          0.1.6
safetensors        0.5.3
semantic-version   2.10.0
setuptools         75.8.2
shellingham        1.5.4
six                1.17.0
sniffio            1.3.1
starlette          0.46.0
sympy              1.13.1
tbb                2021.11.0
tokenizers         0.21.0
tomlkit            0.13.2
torch              2.6.0+cu126
torchaudio         2.6.0+cu126
torchvision        0.21.0+cu126
tqdm               4.67.1
transformers       4.49.0
typer              0.15.2
typing_extensions  4.12.2
tzdata             2025.1
urllib3            2.3.0
uvicorn            0.34.0
wcwidth            0.2.13
websocket-client   1.8.0
websockets         15.0.1
wheel              0.45.1
yarl               1.18.3
zipp               3.21.0

七、下载模型文件

pip install "huggingface_hub[cli]"
huggingface-cli download Wan-AI/Wan2.1-T2V-14B --local-dir ./Wan2.1-T2V-14B

因为模型文件比较大,这个根据网速情况,会有些慢 。如果发现下载速度变慢了,可以ctrl+c终止后重新启动。

模型文件种类:

八、文生视频测试

单GPU情况下指令如下:

python generate.py  --task t2v-14B --size 1280*720 --ckpt_dir ./Wan2.1-T2V-14B --save_file output --prompt "A cute little cat is cooking."

如果显存不够大,会报“Out-of-Memory”错误,可以使用参数--offload_model True and --t5_cpu启用cpu计算,同时改用小点的模型,使用低分辨率的像素来生成。

python generate.py --task t2v-1.3B --size 480*832 --ckpt_dir ./Wan2.1-T2V-1.3B --offload_model True --t5_cpu --sample_shift 8 --sample_guide_scale 6 --save_file ./output/test1.mp4 --prompt "A cute little cat is cooking."

九、图生视频测试

单GPU情况下指令如下:

python generate.py --task t2v-1.3B --size 480*832 --ckpt_dir ./Wan2.1-T2V-1.3B --offload_model True --t5_cpu --image ./examples/test.jpg --save_file ./output/test2.mp4 --prompt "Summer beach vacation style, a white cat wearing sunglasses sits on a surfboard. The fluffy-furred feline gazes directly at the camera with a relaxed expression. Blurred beach scenery forms the background featuring crystal-clear waters, distant green hills, and a blue sky dotted with white clouds. The cat assumes a naturally relaxed posture, as if savoring the sea breeze and warm sunlight. A close-up shot highlights the feline's intricate details and the refreshing atmosphere of the seaside."

十、文生图片测试

python generate.py --task t2v-1.3B --size 480*832 --ckpt_dir ./Wan2.1-T2V-1.3B --prompt '一个漂亮的女孩' --offload_model True --t5_cpu

官方说是文生图,结果生成的还是视频。

想看指令可以带哪些参数,可以查看源码文件generate.py,其中片段如下:

def _parse_args():
    parser = argparse.ArgumentParser(
        description="Generate a image or video from a text prompt or image using Wan"
    )
    parser.add_argument(
        "--task",
        type=str,
        default="t2v-14B",
        choices=list(WAN_CONFIGS.keys()),
        help="The task to run.")
    parser.add_argument(
        "--size",
        type=str,
        default="1280*720",
        choices=list(SIZE_CONFIGS.keys()),
        help="The area (width*height) of the generated video. For the I2V task, the aspect ratio of the output video will follow that of the input image."
    )
    parser.add_argument(
        "--frame_num",
        type=int,
        default=None,
        help="How many frames to sample from a image or video. The number should be 4n+1"
    )
    parser.add_argument(
        "--ckpt_dir",
        type=str,
        default=None,
        help="The path to the checkpoint directory.")
    parser.add_argument(
        "--offload_model",
        type=str2bool,
        default=None,
        help="Whether to offload the model to CPU after each model forward, reducing GPU memory usage."
    )
    parser.add_argument(
        "--ulysses_size",
        type=int,
        default=1,
        help="The size of the ulysses parallelism in DiT.")
    parser.add_argument(
        "--ring_size",
        type=int,
        default=1,
        help="The size of the ring attention parallelism in DiT.")
    parser.add_argument(
        "--t5_fsdp",
        action="store_true",
        default=False,
        help="Whether to use FSDP for T5.")
    parser.add_argument(
        "--t5_cpu",
        action="store_true",
        default=False,
        help="Whether to place T5 model on CPU.")
    parser.add_argument(
        "--dit_fsdp",
        action="store_true",
        default=False,
        help="Whether to use FSDP for DiT.")
    parser.add_argument(
        "--save_file",
        type=str,
        default=None,
        help="The file to save the generated image or video to.")
    parser.add_argument(
        "--prompt",
        type=str,
        default=None,
        help="The prompt to generate the image or video from.")
    parser.add_argument(
        "--use_prompt_extend",
        action="store_true",
        default=False,
        help="Whether to use prompt extend.")
    parser.add_argument(
        "--prompt_extend_method",
        type=str,
        default="local_qwen",
        choices=["dashscope", "local_qwen"],
        help="The prompt extend method to use.")
    parser.add_argument(
        "--prompt_extend_model",
        type=str,
        default=None,
        help="The prompt extend model to use.")
    parser.add_argument(
        "--prompt_extend_target_lang",
        type=str,
        default="zh",
        choices=["zh", "en"],
        help="The target language of prompt extend.")
    parser.add_argument(
        "--base_seed",
        type=int,
        default=-1,
        help="The seed to use for generating the image or video.")
    parser.add_argument(
        "--image",
        type=str,
        default=None,
        help="The image to generate the video from.")
    parser.add_argument(
        "--sample_solver",
        type=str,
        default='unipc',
        choices=['unipc', 'dpm++'],
        help="The solver used to sample.")
    parser.add_argument(
        "--sample_steps", type=int, default=None, help="The sampling steps.")
    parser.add_argument(
        "--sample_shift",
        type=float,
        default=None,
        help="Sampling shift factor for flow matching schedulers.")
    parser.add_argument(
        "--sample_guide_scale",
        type=float,
        default=5.0,
        help="Classifier free guidance scale.")

    args = parser.parse_args()

    _validate_args(args)

    return args

体验感受:总的来说万象生成的视频质量还是不错的,最大的亮点是它原生支持中文提示词,对大部分的同胞们来说这是个福音。只不过这玩意太耗显存,看下面官方给出的测试报告就知道了,起步是4090,也进一步验证了智能时代拼的是算力。

<think>好的,我需要帮助用户了解如何在本地部署Hugging Face上的通义象模型。根据提供的引用内容,首先需要整理出部署的步骤和关注意事项。用户可能对技术细节不太熟悉,所以需要分步骤说明,确保清晰易懂。 首先,用户需要准备硬件和软件环境。根据引用[1]和[5],硬件要求至少需要NVIDIA显卡,显存不低于10GB,推荐16GB以上,特别是对于14B模型。软件方面需要Python 3.8+、CUDA 11.8和PyTorch 2.0+。这些是基础,必须正确安装才能继续后续步骤。 接下来是克隆代码仓库。引用[1]提到需要克隆官方仓库,用户可能需要使用git命令,例如git clone https://github.com/Wan-AI/Wan2.1.git。这一步需要注意仓库地址是否正确,以及是否有权限访问。 然后是安装依赖项。使用pip安装requirements.txt中的依赖,可能还需要安装huggingface_hub的CLI工具来下载模型,如引用[2]所示。需要提醒用户确保所有依赖正确安装,避免本冲突。 下载模型部分,引用[2]和[5]都提到了使用huggingface-cli下载模型,用户需要执行应的命令,例如指定模型名称和本地目录。需要明确说明不同模型本的选择,如14B和1.3B的区别,以及显存需求的不同。 配置环境变量可能涉及设置CUDA路径和模型路径,引用[1]和[3]提到需要正确配置这些变量,确保模型能够正确加载。用户可能需要编辑.bashrc或其他配置文件,需要给出具体命令示例。 运行模型阶段,需要提供示例代码或命令,如运行inference脚本,并指定参数。引用[3]和[4]提到可能需要调整参数,如视频分辨率和帧数,用户需要根据硬件情况进行调整。 注意事项部分,需要强调硬件兼容性、网络问题、模型本和显存监控,如引用[1]和[4]所述。特别是对于网络不稳定的用户,可能需要使用代理或镜像源。 最后,生成关问题需要考虑用户可能遇到的后续问题,例如性能优化、与其他工具集成、自定义训练和应用场景,如引用[5]提到的不同模型本的应用。 总结来说,需要将步骤分解为环境准备、克隆代码、安装依赖、下载模型、配置环境、运行模型和注意事项,每个步骤详细说明,并引用关的引用来源。同时,使用用户友好的语言,避免过于技术化,确保用户能够逐步跟随操作。</think>### 分步指南:本地部署Hugging Face通义模型 #### **一、环境准备** 1. **硬件要求** - **GPU**:需NVIDIA显卡,显存≥10GB(14B模型推荐16GB以上,1.3B模型需≥8GB)[^5] - **内存**:≥32GB - **存储**:至少50GB可用空间(模型文件约15-30GB)[^2][^5] 2. **软件依赖** - **操作系统**:Linux(推荐Ubuntu 20.04+)或Windows WSL2[^1] - **CUDA**:11.8+ - **Python**:3.8+ - **PyTorch**:2.0+ 安装命令示例: ```bash pip install torch==2.0.1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118 ``` --- #### **二、获取代码与模型** 1. **克隆代码仓库** 执行以下命令克隆官方仓库: ```bash git clone https://github.com/Wan-AI/Wan2.1.git cd Wan2.1 ``` 2. **安装依赖** ```bash pip install -r requirements.txt pip install "huggingface_hub[cli]" # 必须安装CLI工具[^2] ``` 3. **下载模型权重** - **14B模型**(高质量视频生成): ```bash huggingface-cli download Wan-AI/Wan2.1-T2V-14B --local-dir ./Wan2.1-T2V-14B ``` - **1.3B模型**(低显存需求): ```bash huggingface-cli download Wan-AI/Wan2.1-T2V-1.3B --local-dir ./Wan2.1-T2V-1.3B ``` --- #### **三、配置运行环境** 1. **设置环境变量** 在`.bashrc`或终端中执行: ```bash export PYTHONPATH=$PYTHONPATH:$(pwd) export MODEL_PATH=./Wan2.1-T2V-14B # 根据实际模型路径修改 ``` 2. **验证CUDA可用性** 运行测试脚本: ```python import torch print(torch.cuda.is_available()) # 应输出True ``` --- #### **四、运行模型** 1. **文生视频示例** 创建脚本`infer_t2v.py`: ```python from models import WanT2V model = WanT2V.from_pretrained(MODEL_PATH) prompt = "一只猫在草地上追逐蝴蝶" output = model.generate(prompt, max_frames=24, resolution="480p") output.save("output.mp4") ``` 2. **执行生成** ```bash python infer_t2v.py ``` --- #### **五、关键注意事项** 1. **硬件兼容性** - 确认显卡支持FP16计算(如RTX 30/40系列)[^5] - 若显存不足,可尝试降低分辨率(如720p→480p)或减少`max_frames`参数[^3] 2. **网络问题处理** - 若下载模型失败,可加`--resume-download`参数续传[^2] - 国内用户建议使用阿里云镜像加速: ```bash huggingface-cli download ... --repo-type=model --cache-dir=/cache --local-dir-use-symlinks=False ``` 3. **多模态扩展** 若要使用图生视频(I2V)功能,需额外下载图像编码器权重: ```bash huggingface-cli download Wan-AI/Wan2.1-I2V-14B --local-dir ./I2V-14B ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数智前沿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值