如何快速上手AnyFlow-FAR-Wan2.1-1.3B-Diffusers:5分钟搭建文本到视频生成环境
【免费下载链接】AnyFlow-FAR-Wan2.1-1.3B-Diffusers项目地址: https://ai.gitcode.com/hf_mirrors/nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers
AnyFlow-FAR-Wan2.1-1.3B-Diffusers是一款基于Wan2.1-T2V-1.3B-Diffusers文本到视频骨干模型开发的1.3B因果视频扩散模型,支持文本到视频(T2V)、图像到视频(I2V)和视频到视频(V2V)多种生成任务,让用户能够轻松将创意转化为生动视频内容。
🚀 为什么选择AnyFlow-FAR-Wan2.1-1.3B-Diffusers?
这款模型具有以下核心优势:
- ⚡ 任意步数生成:不同于传统蒸馏模型固定步数预算,单个模型可适应任意推理预算,实现高质量少步生成,且随着采样步数增加提供稳定改进
- 🔀 多架构支持:支持因果和双向视频扩散模型的任意步蒸馏
- 🎬 多任务兼容:一个因果视频扩散模型即可支持文本到视频、图像到视频和视频到视频生成
- 📈 可扩展性能:已在1.3B至14B参数范围内验证了性能表现
⚙️ 环境准备步骤
1️⃣ 创建Conda环境
首先需要创建并激活专用的Conda环境:
conda create -n far python=3.10 conda activate far2️⃣ 安装PyTorch和依赖项
安装PyTorch及相关依赖:
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128 pip install -r requirements.txt --no-build-isolation📥 模型下载方法
克隆仓库
通过以下命令克隆项目仓库:
git clone https://gitcode.com/hf_mirrors/nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers使用Hugging Face Hub下载
安装Hugging Face Hub工具并下载模型:
pip install "huggingface_hub[cli]" hf download nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers --repo-type model --local-dir experiments/pretrained_models/AnyFlow-FAR-Wan2.1-1.3B-Diffusers🔍 项目核心文件结构
项目主要包含以下关键目录和文件:
- scheduler/:包含调度器配置文件scheduler_config.json
- text_encoder/:文本编码器配置和模型文件,如config.json和模型权重文件
- tokenizer/:分词器相关文件,包括special_tokens_map.json、spiece.model等
- transformer/:转换器配置和模型文件config.json、diffusion_pytorch_model.safetensors
- vae/:VAE配置和模型文件config.json、diffusion_pytorch_model.safetensors
- LICENSE.md:模型许可协议文件
- README.md:项目说明文档
- model_index.json:模型索引配置文件
🎮 快速开始生成视频
文本到视频生成
使用以下Python代码实现文本到视频生成:
import torch from diffusers.utils import export_to_video from far.pipelines.pipeline_far_wan_anyflow import FARWanAnyFlowPipeline model_id = "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers" pipeline = FARWanAnyFlowPipeline.from_pretrained(model_path).to('cuda', dtype=torch.bfloat16) prompt = "CG game concept digital art, a majestic elephant with a vibrant tusk and sleek fur running swiftly towards a herd of its kind." video = pipeline( prompt=prompt, height=480, width=832, num_frames=81, num_inference_steps=4, generator=torch.Generator('cuda').manual_seed(0) ).frames[0] export_to_video(output, "output.mp4", fps=16)图像到视频生成
基于现有图像生成视频:
import torch from diffusers.utils import export_to_video from PIL import Image from torchvision import transforms from far.pipelines.pipeline_far_wan_anyflow import FARWanAnyFlowPipeline model_id = "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers" pipeline = FARWanAnyFlowPipeline.from_pretrained(model_path).to('cuda', dtype=torch.bfloat16) # 加载图像 image_path = 'assets/example_image.jpg' prompt = 'A towering, battle-scarred humanoid robot walking through the skeletal remains of a city ruin.' image = Image.open(image_path).convert('RGB') image = transforms.ToTensor()(transforms.Resize([480, 832])(image)).unsqueeze(0).unsqueeze(0) video = pipeline( prompt=prompt, context_sequence={'raw': image}, height=480, width=832, num_frames=81, num_inference_steps=4, generator=torch.Generator('cuda').manual_seed(0) ).frames[0] export_to_video(output, "output.mp4", fps=16)视频到视频生成
基于现有视频生成新视频:
import torch from diffusers.utils import export_to_video import decord from torchvision import transforms from far.pipelines.pipeline_far_wan_anyflow import FARWanAnyFlowPipeline decord.bridge.set_bridge('torch') model_id = "nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers" pipeline = FARWanAnyFlowPipeline.from_pretrained(model_path).to('cuda', dtype=torch.bfloat16) # 加载视频 video_path = 'assets/example_video.mp4' prompt = "A focused trail runner's powerful strides through a dense, sun-dappled forest." video_reader = decord.VideoReader(video_path) frame_idxs = select_frame_indices(len(video_reader), video_reader.get_avg_fps(), target_fps=16)[:num_cond_frames] frames = video_reader.get_batch(frame_idxs) frames = (frames / 255.0).float().permute(0, 3, 1, 2).contiguous() frames = transforms.Resize([480, 832])(frames).unsqueeze(0) video = pipeline( prompt=prompt, context_sequence={'raw': frames}, height=480, width=832, num_frames=81, num_inference_steps=4, generator=torch.Generator('cuda').manual_seed(0) ).frames[0] export_to_video(output, "output.mp4", fps=16)📜 许可协议说明
该模型根据NVIDIA单向非商业许可(NSCLv1)发布,主要限制包括:
- 模型仅供非商业使用
- NVIDIA不对使用模型或衍生模型生成的任何输出主张所有权
完整许可条款请参见LICENSE.md文件。
🙏 致谢
本代码库基于Diffusers构建,同时参考了FAR、Self-Forcing和TiM的实现,感谢这些项目的作者开源其工作。
【免费下载链接】AnyFlow-FAR-Wan2.1-1.3B-Diffusers项目地址: https://ai.gitcode.com/hf_mirrors/nvidia/AnyFlow-FAR-Wan2.1-1.3B-Diffusers
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考