Spaces:
Paused
Paused
Commit ·
2c40a1b
1
Parent(s): e99b3c1
Fix: move generate.py patch into standalone Python script, remove inline -c
Browse files- Dockerfile +3 -20
- patch_wan_init.py +15 -12
Dockerfile
CHANGED
|
@@ -22,38 +22,21 @@ WORKDIR /app
|
|
| 22 |
# Clone official Wan2.2
|
| 23 |
RUN git clone https://github.com/Wan-Video/Wan2.2.git /app/Wan2.2
|
| 24 |
|
| 25 |
-
# Patch
|
| 26 |
COPY --chown=user ./patch_wan_init.py /tmp/patch_wan_init.py
|
| 27 |
|
| 28 |
# PyTorch
|
| 29 |
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
|
| 30 |
|
| 31 |
-
#
|
| 32 |
RUN cd /app/Wan2.2 && (pip install --no-cache-dir -r requirements.txt 2>/dev/null; exit 0)
|
| 33 |
-
|
| 34 |
-
# Install any remaining deps explicitly
|
| 35 |
RUN pip install --no-cache-dir \
|
| 36 |
opencv-python easydict decord einops ftfy "numpy>=1.23.5,<2" \
|
| 37 |
tqdm "imageio[ffmpeg]" imageio-ffmpeg sentencepiece \
|
| 38 |
protobuf soundfile librosa peft dashscope
|
| 39 |
|
| 40 |
# Apply patches
|
| 41 |
-
RUN python3 /tmp/patch_wan_init.py
|
| 42 |
-
head -5 /app/Wan2.2/wan/__init__.py
|
| 43 |
-
|
| 44 |
-
RUN python3 -c "
|
| 45 |
-
# Patch generate.py to make dashscope optional
|
| 46 |
-
p = '/app/Wan2.2/generate.py'
|
| 47 |
-
with open(p) as f:
|
| 48 |
-
c = f.read()
|
| 49 |
-
c = c.replace(
|
| 50 |
-
'from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander',
|
| 51 |
-
'try:\n from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander\nexcept ImportError:\n DashScopePromptExpander = None\n QwenPromptExpander = None'
|
| 52 |
-
)
|
| 53 |
-
with open(p, 'w') as f:
|
| 54 |
-
f.write(c)
|
| 55 |
-
print('Patched generate.py')
|
| 56 |
-
"
|
| 57 |
|
| 58 |
# Copy app
|
| 59 |
COPY --chown=user ./requirements.txt requirements.txt
|
|
|
|
| 22 |
# Clone official Wan2.2
|
| 23 |
RUN git clone https://github.com/Wan-Video/Wan2.2.git /app/Wan2.2
|
| 24 |
|
| 25 |
+
# Patch script
|
| 26 |
COPY --chown=user ./patch_wan_init.py /tmp/patch_wan_init.py
|
| 27 |
|
| 28 |
# PyTorch
|
| 29 |
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
|
| 30 |
|
| 31 |
+
# All deps (flash_attn may fail, that's ok)
|
| 32 |
RUN cd /app/Wan2.2 && (pip install --no-cache-dir -r requirements.txt 2>/dev/null; exit 0)
|
|
|
|
|
|
|
| 33 |
RUN pip install --no-cache-dir \
|
| 34 |
opencv-python easydict decord einops ftfy "numpy>=1.23.5,<2" \
|
| 35 |
tqdm "imageio[ffmpeg]" imageio-ffmpeg sentencepiece \
|
| 36 |
protobuf soundfile librosa peft dashscope
|
| 37 |
|
| 38 |
# Apply patches
|
| 39 |
+
RUN python3 /tmp/patch_wan_init.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# Copy app
|
| 42 |
COPY --chown=user ./requirements.txt requirements.txt
|
patch_wan_init.py
CHANGED
|
@@ -1,27 +1,19 @@
|
|
| 1 |
import os
|
| 2 |
|
|
|
|
| 3 |
p = '/app/Wan2.2/wan/__init__.py'
|
| 4 |
with open(p) as f:
|
| 5 |
content = f.read()
|
| 6 |
-
|
| 7 |
lines = content.split('\n')
|
| 8 |
result = []
|
| 9 |
-
|
| 10 |
-
# Only wrap imports known to fail with missing optional deps
|
| 11 |
problematic = {'speech2video', 'animate', 'video2audio'}
|
| 12 |
-
|
| 13 |
for line in lines:
|
| 14 |
stripped = line.strip()
|
| 15 |
if stripped.startswith('from .') and 'import' in stripped:
|
| 16 |
-
# Check if this import references a problematic submodule
|
| 17 |
parts = stripped.split()
|
| 18 |
-
module_ref = parts[1]
|
| 19 |
module_name = module_ref.lstrip('.')
|
| 20 |
-
|
| 21 |
-
# Determine if this might be problematic
|
| 22 |
-
is_problematic = any(mod in module_name for mod in problematic)
|
| 23 |
-
|
| 24 |
-
if is_problematic:
|
| 25 |
indent = line[:len(line) - len(line.lstrip())]
|
| 26 |
result.append(f'{indent}try:')
|
| 27 |
result.append(f'{indent} {stripped}')
|
|
@@ -31,7 +23,18 @@ for line in lines:
|
|
| 31 |
result.append(line)
|
| 32 |
else:
|
| 33 |
result.append(line)
|
| 34 |
-
|
| 35 |
with open(p, 'w') as f:
|
| 36 |
f.write('\n'.join(result))
|
| 37 |
print('Patched wan/__init__.py')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
|
| 3 |
+
# Patch wan/__init__.py
|
| 4 |
p = '/app/Wan2.2/wan/__init__.py'
|
| 5 |
with open(p) as f:
|
| 6 |
content = f.read()
|
|
|
|
| 7 |
lines = content.split('\n')
|
| 8 |
result = []
|
|
|
|
|
|
|
| 9 |
problematic = {'speech2video', 'animate', 'video2audio'}
|
|
|
|
| 10 |
for line in lines:
|
| 11 |
stripped = line.strip()
|
| 12 |
if stripped.startswith('from .') and 'import' in stripped:
|
|
|
|
| 13 |
parts = stripped.split()
|
| 14 |
+
module_ref = parts[1]
|
| 15 |
module_name = module_ref.lstrip('.')
|
| 16 |
+
if any(mod in module_name for mod in problematic):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
indent = line[:len(line) - len(line.lstrip())]
|
| 18 |
result.append(f'{indent}try:')
|
| 19 |
result.append(f'{indent} {stripped}')
|
|
|
|
| 23 |
result.append(line)
|
| 24 |
else:
|
| 25 |
result.append(line)
|
|
|
|
| 26 |
with open(p, 'w') as f:
|
| 27 |
f.write('\n'.join(result))
|
| 28 |
print('Patched wan/__init__.py')
|
| 29 |
+
|
| 30 |
+
# Patch generate.py
|
| 31 |
+
p = '/app/Wan2.2/generate.py'
|
| 32 |
+
with open(p) as f:
|
| 33 |
+
c = f.read()
|
| 34 |
+
c = c.replace(
|
| 35 |
+
'from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander',
|
| 36 |
+
'try:\n from wan.utils.prompt_extend import DashScopePromptExpander, QwenPromptExpander\nexcept ImportError:\n DashScopePromptExpander = None\n QwenPromptExpander = None'
|
| 37 |
+
)
|
| 38 |
+
with open(p, 'w') as f:
|
| 39 |
+
f.write(c)
|
| 40 |
+
print('Patched generate.py')
|