通义万相2.1在Ubuntu 22上部署使用
在Ubuntu 22.04上部署使用,显示NVIDIA GeForce RTX 3090,显存24Gb,根据官方的说法,消费级的显卡就可以部署了.
官方模型下载地址:https://huggingface.co/Wan-AI/Wan2.1-T2V-1.3B
github开源地址:https://github.com/Wan-Video/Wan2.1
安装说明:
git clone https://github.com/Wan-Video/Wan2.1.git
cd Wan2.1
pip install -r requirements.txt
在进行pip 安装的时候,会遇到安装编译 flash-attn半天没反应的问题.
Building wheel for flash-attn (setup.py)
在网上也有很多人有类似的问题,解决办法是去网站上面下载一个编译后的版本来得最快.
下载地址在这儿:https://github.com/Dao-AILab/flash-attention/releases
根据自己的设备情况来选择合适的版本:
https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.4.post1/flash_attn-2.7.4.post1+cu12torch2.4cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
设备情况是指以下几项内容的版本,torch的版本,python的版本,cuda的版本,像上面的链接表示torch大于2.4,cuda是12,python是3.10就都可以.
查看torch版本的方法
import torch
print(torch.__version__)
2.6.0+cu124
查看cuda版本的方法如下,其实,上面也已经显示cuda版本为12.4了.
import torch
print(torch.version.cuda)
12.4
下载完成后,直接pip install 就可以了
pip install flash_attn-2.7.4.post1+cu12torch2.4cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
保险起见,再次运行
pip install -r requirements.txt
接下来是下载模型,家用电脑上测试就只能体验1.3B的模型了(说是只要求8G的显存,实际使用的时候发现用的18G),14B的模型咱搞不了.
下载模型:
pip install modelscope
modelscope download Wan-AI/Wan2.1-T2V-1.3B --local_dir ./Wan2.1-T2V-1.3B
接下来慢慢等,这个包不大不小,有17G左右的样子
~/wan/Wan2.1-T2V-1.3B$ du -h -d1
252K ./examples
6.3M ./assets
20K ./._____temp
21M ./google
17G .
等待模型都下载完成了,就可以开炉炼了.
python3 generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ../Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "纪实摄影风格, 中景镜头,一位20岁精致妆容的韩国美女,露出白皙的皮肤, 充满青春与活力。半身特写,锐利的边缘" --frame_num=81 --save_file=15.mp4
参数简单说明:
../Wan2.1-T2V-1.3B是模型的保存目录
frame_num是帧数,看下面的日志fps是16帧,不知道在哪里看的,说的帧数要是4n+1还是n+1,这个n就是指fps, 反正如果不指定这个帧数,默认就是81帧
save_file是要保存的文件名,如果不指定的话,生成的文件名老长了,就是指示词直接命名.
下面是程序的各种输出:
[2025-02-28 10:23:09,245] INFO: offload_model is not specified, set to True.
[2025-02-28 10:23:09,245] INFO: Generation job args: Namespace(task='t2v-1.3B', size='832*480', frame_num=81, ckpt_dir='../Wan2.1-T2V-1.3B', offload_model=True, ulysses_size=1, ring_size=1, t5_fsdp=False, t5_cpu=False, dit_fsdp=False, save_file='15.mp4', prompt='纪实摄影风格,中景镜头,一位20岁精致妆容的韩国美女,露出白皙的皮肤, 充满青春与活力。半身特写,锐利的边缘', use_prompt_extend=False, prompt_extend_method='local_qwen', prompt_extend_model=None, prompt_extend_target_lang='ch', base_seed=6044133464219050096, image=None, sample_solver='unipc', sample_steps=50, sample_shift=8.0, sample_guide_scale=6.0)
[2025-02-28 10:23:09,246] INFO: Generation model config: {'__name__': 'Config: Wan T2V 1.3B', 't5_model': 'umt5_xxl', 't5_dtype': torch.bfloat16, 'text_len': 512, 'param_dtype': torch.bfloat16, 'num_train_timesteps': 1000, 'sample_fps': 16, 'sample_neg_prompt': '色调艳丽,过曝,静态,细节模糊不清,字幕,风格,作品,画作,画面,静止,整体发灰,最差质量,低质量,JPEG压缩残留,丑陋的,残缺的,多余的手指,画得不好的手部,画得不好的脸部,畸形的,毁容的,形态畸形的肢体,手指融合,静止不动的画面,杂乱的背景,三条腿,背景人很多,倒着走', 't5_checkpoint': 'models_t5_umt5-xxl-enc-bf16.pth', 't5_tokenizer': 'google/umt5-xxl', 'vae_checkpoint': 'Wan2.1_VAE.pth', 'vae_stride': (4, 8, 8), 'patch_size': (1, 2, 2), 'dim': 1536, 'ffn_dim': 8960, 'freq_dim': 256, 'num_heads': 12, 'num_layers': 30, 'window_size': (-1, -1), 'qk_norm': True, 'cross_attn_norm': True, 'eps': 1e-06}
[2025-02-28 10:23:09,246] INFO: Input prompt: 纪实摄影风格,中景镜头,一位20岁精致妆容的韩国美女,露出白皙的皮肤, 充满青春与活力。半身特写,锐利的边缘
[2025-02-28 10:23:09,246] INFO: Creating WanT2V pipeline.
[2025-02-28 10:24:11,819] INFO: loading ../Wan2.1-T2V-1.3B/models_t5_umt5-xxl-enc-bf16.pth
[2025-02-28 10:24:19,237] INFO: loading ../Wan2.1-T2V-1.3B/Wan2.1_VAE.pth
[2025-02-28 10:24:19,634] INFO: Creating WanModel from ../Wan2.1-T2V-1.3B
[2025-02-28 10:24:21,254] INFO: Generating video ...
100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [08:03<00:00, 9.67s/it]
[2025-02-28 10:32:55,448] INFO: Saving generated video to 15.mp4
[2025-02-28 10:32:56,941] INFO: Finished.
用时8分3秒,只生成了个5秒钟的视频,效果如下:
ffmpeg -i 15.mp4 -hide_banner
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '15.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf61.1.100
Duration: 00:00:05.06, start: 0.000000, bitrate: 4443 kb/s
Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 832x480, 4440 kb/s, 16 fps, 16 tbr, 16384 tbn, 32 tbc (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
encoder : Lavc61.3.100 libx264
源视频如下:https://const.net.cn/ai/15.mp4
截图如下:
发现脸太大了,我们想要半身的视频,可以调整提示语.重新炼
python3 generate.py --task t2v-1.3B --size 832*480 --ckpt_dir ../Wan2.1-T2V-1.3B --sample_shift 8 --sample_guide_scale 6 --prompt "纪实摄影风格, 中景镜头,一位20岁精致妆容的韩国美女,穿着白色的T-shirt,露出白皙的皮肤,充满青春与活力。半身特写,锐利的边缘" --frame_num=81 --save_file=16.mp4
在这个等待的时间,也可以看看显卡的占用情况
nvidia-smi
Fri Feb 28 10:40:36 2025
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.183.01 Driver Version: 535.183.01 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce RTX 3090 Off | 00000000:65:00.0 Off | N/A |
| 72% 65C P2 348W / 350W | 18472MiB / 24576MiB | 100% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| 0 N/A N/A 1282546 C python3 18466MiB |
+---------------------------------------------------------------------------------------+
发现显存确实是占用了18G.
生成的视频如下:https://const.net.cn/ai/16.mp4
视频截图:
不想自己搭建模型的,也可以在阿里的网站和app体验,用手机注册就可以了,每天登录有50灵感值,生成一个视频会扣除一定的灵感值,手机使用通义app每天也可以加50灵感值,体验一下应该是够了.官网地址:https://tongyi.aliyun.com/wanxiang/creation
本文链接地址:https://const.net.cn/826.html