🚀 Allegro - 文本到視頻生成模型
Allegro 是一款開源的文本到視頻生成模型,能夠根據輸入的文本生成高質量的視頻內容。它具有廣泛的內容創作能力、高效的模型結構和出色的輸出質量,為視頻生成領域帶來了新的可能性。
🚀 快速開始
安裝必要依賴
- 確保 Python 版本 >= 3.10,PyTorch 版本 >= 2.4,CUDA 版本 >= 12.4。
- 建議使用 Anaconda 創建一個新的環境(Python >= 3.10),運行命令
conda create -n rllegro python=3.10 -y
來運行以下示例。
- 運行命令
pip install git+https://github.com/huggingface/diffusers.git torch==2.4.1 transformers==4.40.1 accelerate sentencepiece imageio imageio-ffmpeg beautifulsoup4
。
運行推理
import torch
from diffusers import AutoencoderKLAllegro, AllegroPipeline
from diffusers.utils import export_to_video
vae = AutoencoderKLAllegro.from_pretrained("rhymes-ai/Allegro-T2V-40x360P", subfolder="vae", torch_dtype=torch.float32)
vae.tile_overlap_t = 8
vae.tile_overlap_h = 144
vae.tile_overlap_w = 64
vae.stride = (16,112,192)
pipe = AllegroPipeline.from_pretrained(
"rhymes-ai/Allegro-T2V-40x360P", vae=vae, torch_dtype=torch.bfloat16
)
pipe.to("cuda")
pipe.vae.enable_tiling()
prompt = "A seaside harbor with bright sunlight and sparkling seawater, with many boats in the water. From an aerial view, the boats vary in size and color, some moving and some stationary. Fishing boats in the water suggest that this location might be a popular spot for docking fishing boats."
positive_prompt = """
(masterpiece), (best quality), (ultra-detailed), (unwatermarked),
{}
emotional, harmonious, vignette, 4k epic detailed, shot on kodak, 35mm photo,
sharp focus, high budget, cinemascope, moody, epic, gorgeous
"""
negative_prompt = """
nsfw, lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality,
low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry.
"""
prompt = prompt.format(prompt.lower().strip())
video = pipe(prompt, negative_prompt=negative_prompt, guidance_scale=7.5, max_sequence_length=512, num_inference_steps=100, generator = torch.Generator(device="cuda:0").manual_seed(42)).frames[0]
export_to_video(video, "output.mp4", fps=15)
使用 pipe.enable_sequential_cpu_offload()
可以將模型卸載到 CPU 以減少 GPU 內存消耗,但推理時間會顯著增加。
(可選)將視頻插值到 30 FPS
建議使用 EMA-VFI 將視頻從 15 FPS 插值到 30 FPS。為了獲得更好的視覺質量,請使用 imageio 保存視頻。
更快的推理方法
如需瞭解如 Context Parallel、PAB 等更快的推理方法,請參考我們的 GitHub 倉庫。
✨ 主要特性
- 開源:社區可獲取完整的 模型權重 和 代碼,採用 Apache 2.0 許可證!
- 多功能內容創作:能夠生成廣泛的內容,從人類和動物的特寫鏡頭到各種動態場景。
- 高質量輸出:以 15 FPS 生成 2 到 6 秒的詳細視頻,分辨率為 368x640 和 720x1280,可使用 EMA-VFI 插值到 30 FPS。
- 小巧高效:具有 1.75 億參數的 VideoVAE 和 28 億參數的 VideoDiT 模型。支持多種精度(FP32、BF16、FP16),在 BF16 模式下使用 CPU 卸載時,GPU 內存使用量為 9.3 GB。上下文長度為 79.2K,相當於 88 幀。
📦 模型信息
屬性 |
詳情 |
模型 |
Allegro-T2V-40x360P |
描述 |
文本到視頻生成模型 |
下載地址 |
Hugging Face |
參數 |
VAE: 1.75 億;DiT: 28 億 |
推理精度 |
VAE: FP32/TF32/BF16/FP16(FP32/TF32 最佳);DiT/T5: BF16/FP32/TF32 |
上下文長度 |
9.2K |
分辨率 |
368 x 640 |
幀數 |
40 |
視頻長度 |
約 3 秒 @ 15 FPS |
📚 模型展示
展示畫廊 · GitHub · 博客 · 論文 · Discord · 加入等待列表 (在 Discord 上試用!)
如需查看更多演示和相應提示,請訪問 Allegro 展示畫廊。
📄 許可證
本倉庫採用 Apache 2.0 許可證發佈。