Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -5,9 +5,10 @@ colorFrom: blue
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.29.0
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
short_description: SeedVR2-3B Image & Video API Demo
|
| 12 |
---
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 5 |
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
sdk_version: 5.29.0
|
| 8 |
+
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: apache-2.0
|
| 12 |
short_description: SeedVR2-3B Image & Video API Demo
|
| 13 |
---
|
| 14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -12,7 +12,6 @@
|
|
| 12 |
# // See the License for the specific language governing permissions and
|
| 13 |
# // limitations under the License.
|
| 14 |
import spaces
|
| 15 |
-
import subprocess
|
| 16 |
|
| 17 |
import os
|
| 18 |
import torch
|
|
@@ -61,7 +60,6 @@ import gradio as gr
|
|
| 61 |
from pathlib import Path
|
| 62 |
from urllib.parse import urlparse
|
| 63 |
from torch.hub import download_url_to_file, get_dir
|
| 64 |
-
import shlex
|
| 65 |
import uuid
|
| 66 |
import mimetypes
|
| 67 |
import torchvision.transforms as T
|
|
@@ -71,11 +69,9 @@ os.environ["MASTER_PORT"] = "12355"
|
|
| 71 |
os.environ["RANK"] = str(0)
|
| 72 |
os.environ["WORLD_SIZE"] = str(1)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
shell=True,
|
| 78 |
-
)
|
| 79 |
|
| 80 |
def load_file_from_url(url, model_dir=None, progress=True, file_name=None):
|
| 81 |
"""Load file from http url, will download models if necessary.
|
|
@@ -119,7 +115,6 @@ pretrain_model_url = {
|
|
| 119 |
'dit': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/seedvr2_ema_3b.pth',
|
| 120 |
'pos_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt',
|
| 121 |
'neg_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt',
|
| 122 |
-
'apex': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/apex-0.1-cp310-cp310-linux_x86_64.whl'
|
| 123 |
}
|
| 124 |
# download weights
|
| 125 |
if not os.path.exists('./ckpts/seedvr2_ema_3b.pth'):
|
|
@@ -130,11 +125,8 @@ if not os.path.exists('./pos_emb.pt'):
|
|
| 130 |
load_file_from_url(url=pretrain_model_url['pos_emb'], model_dir='./', progress=True, file_name=None)
|
| 131 |
if not os.path.exists('./neg_emb.pt'):
|
| 132 |
load_file_from_url(url=pretrain_model_url['neg_emb'], model_dir='./', progress=True, file_name=None)
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
subprocess.run(shlex.split("pip install apex-0.1-cp310-cp310-linux_x86_64.whl"))
|
| 137 |
-
print(f"✅ setup completed Apex")
|
| 138 |
|
| 139 |
# download images
|
| 140 |
torch.hub.download_url_to_file(
|
|
@@ -151,10 +143,16 @@ def configure_sequence_parallel(sp_size):
|
|
| 151 |
if sp_size > 1:
|
| 152 |
init_sequence_parallel(sp_size)
|
| 153 |
|
| 154 |
-
@spaces.GPU(duration=100)
|
| 155 |
def configure_runner(sp_size):
|
| 156 |
config_path = os.path.join('./configs_3b', 'main.yaml')
|
| 157 |
config = load_config(config_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
runner = VideoDiffusionInfer(config)
|
| 159 |
OmegaConf.set_readonly(runner.config, False)
|
| 160 |
|
|
@@ -167,7 +165,6 @@ def configure_runner(sp_size):
|
|
| 167 |
runner.vae.set_memory_limit(**runner.config.vae.memory_limit)
|
| 168 |
return runner
|
| 169 |
|
| 170 |
-
@spaces.GPU(duration=100)
|
| 171 |
def generation_step(runner, text_embeds_dict, cond_latents):
|
| 172 |
def _move_to_cuda(x):
|
| 173 |
return [i.to(torch.device("cuda")) for i in x]
|
|
|
|
| 12 |
# // See the License for the specific language governing permissions and
|
| 13 |
# // limitations under the License.
|
| 14 |
import spaces
|
|
|
|
| 15 |
|
| 16 |
import os
|
| 17 |
import torch
|
|
|
|
| 60 |
from pathlib import Path
|
| 61 |
from urllib.parse import urlparse
|
| 62 |
from torch.hub import download_url_to_file, get_dir
|
|
|
|
| 63 |
import uuid
|
| 64 |
import mimetypes
|
| 65 |
import torchvision.transforms as T
|
|
|
|
| 69 |
os.environ["RANK"] = str(0)
|
| 70 |
os.environ["WORLD_SIZE"] = str(1)
|
| 71 |
|
| 72 |
+
# FlashAttention is installed during the Space build from a Blackwell-compatible
|
| 73 |
+
# prebuilt wheel listed in requirements.txt; do not install an incompatible
|
| 74 |
+
# CUDA extension while the application is starting.
|
|
|
|
|
|
|
| 75 |
|
| 76 |
def load_file_from_url(url, model_dir=None, progress=True, file_name=None):
|
| 77 |
"""Load file from http url, will download models if necessary.
|
|
|
|
| 115 |
'dit': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/seedvr2_ema_3b.pth',
|
| 116 |
'pos_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/pos_emb.pt',
|
| 117 |
'neg_emb': 'https://huggingface.co/ByteDance-Seed/SeedVR2-3B/resolve/main/neg_emb.pt',
|
|
|
|
| 118 |
}
|
| 119 |
# download weights
|
| 120 |
if not os.path.exists('./ckpts/seedvr2_ema_3b.pth'):
|
|
|
|
| 125 |
load_file_from_url(url=pretrain_model_url['pos_emb'], model_dir='./', progress=True, file_name=None)
|
| 126 |
if not os.path.exists('./neg_emb.pt'):
|
| 127 |
load_file_from_url(url=pretrain_model_url['neg_emb'], model_dir='./', progress=True, file_name=None)
|
| 128 |
+
# The original Apex binary targeted PyTorch 2.4 / CUDA 12.1. We avoid it by
|
| 129 |
+
# selecting the native normalization layers before constructing the model.
|
|
|
|
|
|
|
|
|
|
| 130 |
|
| 131 |
# download images
|
| 132 |
torch.hub.download_url_to_file(
|
|
|
|
| 143 |
if sp_size > 1:
|
| 144 |
init_sequence_parallel(sp_size)
|
| 145 |
|
|
|
|
| 146 |
def configure_runner(sp_size):
|
| 147 |
config_path = os.path.join('./configs_3b', 'main.yaml')
|
| 148 |
config = load_config(config_path)
|
| 149 |
+
# Replace GPU-architecture-specific Apex fused normalizations with
|
| 150 |
+
# equivalent torch/diffusers layers. Preserve the original YAML file.
|
| 151 |
+
OmegaConf.set_readonly(config, False)
|
| 152 |
+
config.dit.model.vid_out_norm = "rms"
|
| 153 |
+
config.dit.model.txt_in_norm = "layer"
|
| 154 |
+
config.dit.model.norm = "rms"
|
| 155 |
+
config.dit.model.qk_norm = "rms"
|
| 156 |
runner = VideoDiffusionInfer(config)
|
| 157 |
OmegaConf.set_readonly(runner.config, False)
|
| 158 |
|
|
|
|
| 165 |
runner.vae.set_memory_limit(**runner.config.vae.memory_limit)
|
| 166 |
return runner
|
| 167 |
|
|
|
|
| 168 |
def generation_step(runner, text_embeds_dict, cond_latents):
|
| 169 |
def _move_to_cuda(x):
|
| 170 |
return [i.to(torch.device("cuda")) for i in x]
|
requirements.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
einops==0.7.0 # Tensor operations
|
| 3 |
|
| 4 |
# Training
|
| 5 |
-
torch==2.
|
| 6 |
omegaconf==2.3.0 # Configuration system.
|
| 7 |
lpips==0.1.4 # LPIPS model for VAE training
|
| 8 |
|
|
@@ -16,7 +16,7 @@ sentencepiece==0.2.0 # For Text Encoder
|
|
| 16 |
diffusers==0.29.1 # Diffusers
|
| 17 |
rotary-embedding-torch==0.5.3 # Rotary positional embedding
|
| 18 |
transformers==4.38.2 # Transformers
|
| 19 |
-
torchvision==0.
|
| 20 |
tiktoken==0.7.0 # Tiktoken for generation
|
| 21 |
transformers_stream_generator==0.0.5 #LLM generation support
|
| 22 |
|
|
@@ -44,4 +44,8 @@ isort >= 5, < 6 # Import sorting
|
|
| 44 |
pre-commit==3.7.0 # Pre-commit hooks
|
| 45 |
expecttest==0.2.1 # Pytorch dist tests
|
| 46 |
hypothesis==6.100.1 # Fix randomness
|
| 47 |
-
av==12.0.0 # Process audio and video
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
einops==0.7.0 # Tensor operations
|
| 3 |
|
| 4 |
# Training
|
| 5 |
+
torch==2.8.0 # ZeroGPU Blackwell (sm_120), CUDA 12.8 compatible
|
| 6 |
omegaconf==2.3.0 # Configuration system.
|
| 7 |
lpips==0.1.4 # LPIPS model for VAE training
|
| 8 |
|
|
|
|
| 16 |
diffusers==0.29.1 # Diffusers
|
| 17 |
rotary-embedding-torch==0.5.3 # Rotary positional embedding
|
| 18 |
transformers==4.38.2 # Transformers
|
| 19 |
+
torchvision==0.23.0 # Matches PyTorch 2.8.0
|
| 20 |
tiktoken==0.7.0 # Tiktoken for generation
|
| 21 |
transformers_stream_generator==0.0.5 #LLM generation support
|
| 22 |
|
|
|
|
| 44 |
pre-commit==3.7.0 # Pre-commit hooks
|
| 45 |
expecttest==0.2.1 # Pytorch dist tests
|
| 46 |
hypothesis==6.100.1 # Fix randomness
|
| 47 |
+
av==12.0.0 # Process audio and video
|
| 48 |
+
|
| 49 |
+
# Precompiled FlashAttention-2 for Blackwell, torch 2.8 / CUDA 12.8 / Python 3.10.
|
| 50 |
+
# Keep the Python version in README.md at 3.10 to match this wheel.
|
| 51 |
+
flash-attn @ https://huggingface.co/datasets/multimodalart/zerogpu-blackwell-wheels/resolve/main/wheels/pt28-cu128-cp310/flash_attn-2.8.3-cp310-cp310-linux_x86_64.whl
|
setup.sh
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
set -euo pipefail
|
| 3 |
+
# The original setup.sh compiled legacy CUDA extensions at runtime.
|
| 4 |
+
# Blackwell-compatible FlashAttention is now installed from requirements.txt,
|
| 5 |
+
# and Apex is replaced with native normalization layers in app.py.
|
| 6 |
+
echo "SeedVR2 ZeroGPU Blackwell: dependencies installed via requirements.txt"
|