DawnC commited on
Commit
c14cba9
·
verified ·
1 Parent(s): dffb425

Delete app_aoti.py

Browse files
Files changed (1) hide show
  1. app_aoti.py +0 -162
app_aoti.py DELETED
@@ -1,162 +0,0 @@
1
- import os
2
- import sys
3
-
4
- # CRITICAL: Import spaces FIRST before any CUDA initialization
5
- try:
6
- import spaces
7
- except ImportError:
8
- pass
9
-
10
- sys.stdout.flush()
11
- import functools
12
- print = functools.partial(print, flush=True)
13
-
14
- import ftfy
15
- import sentencepiece
16
-
17
- from FlowFacade_aoti import FlowFacadeAOTI
18
- from ui_manager import UIManager
19
-
20
-
21
- def preload_models():
22
- """
23
- Pre-download models to cache on HF Spaces startup.
24
- Includes AOTI files for faster first-run experience.
25
- """
26
- if not os.environ.get('SPACE_ID'):
27
- return
28
-
29
- cache_dir = os.path.expanduser("~/.cache/huggingface/hub")
30
- if os.path.exists(cache_dir):
31
- cached_models = os.listdir(cache_dir)
32
- if any("wan2.2" in m.lower() or "models--kijai" in m.lower() for m in cached_models):
33
- print("✓ Models already cached (YAML preload worked)")
34
- return
35
-
36
- print("→ Pre-caching models to disk (first-time setup)...")
37
- print(" This may take 2-3 minutes, please wait...")
38
-
39
- try:
40
- from diffusers import WanTransformer3DModel
41
- from transformers import AutoModelForCausalLM, AutoTokenizer
42
- from huggingface_hub import hf_hub_download
43
- import torch
44
-
45
- print(" [1/5] Downloading video model transformer...")
46
- WanTransformer3DModel.from_pretrained(
47
- "cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers",
48
- subfolder='transformer',
49
- torch_dtype=torch.bfloat16,
50
- )
51
-
52
- print(" [2/5] Downloading video model transformer_2...")
53
- WanTransformer3DModel.from_pretrained(
54
- "cbensimon/Wan2.2-I2V-A14B-bf16-Diffusers",
55
- subfolder='transformer_2',
56
- torch_dtype=torch.bfloat16,
57
- )
58
-
59
- print(" [3/5] Downloading Lightning LoRA...")
60
- hf_hub_download(
61
- "Kijai/WanVideo_comfy",
62
- "Lightx2v/lightx2v_I2V_14B_480p_cfg_step_distill_rank128_bf16.safetensors"
63
- )
64
-
65
- print(" [4/5] Downloading AOTI files...")
66
- try:
67
- hf_hub_download(
68
- "zerogpu-aoti/Wan2",
69
- filename="package.pt2",
70
- subfolder="WanTransformerBlock.fp8da"
71
- )
72
- print(" ✓ AOTI files downloaded")
73
- except Exception as e:
74
- print(f" ⚠ AOTI download failed: {e}")
75
- print(" Will use FP8-only mode")
76
-
77
- print(" [5/5] Downloading text model (optional)...")
78
- AutoModelForCausalLM.from_pretrained(
79
- "Qwen/Qwen2.5-0.5B-Instruct",
80
- torch_dtype=torch.bfloat16,
81
- )
82
- AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B-Instruct")
83
-
84
- print("✓ All models cached successfully!")
85
- print(" Future users will load instantly from cache")
86
-
87
- except Exception as e:
88
- print(f"⚠ Pre-cache warning: {e}")
89
- print(" Models will download on first generation instead")
90
-
91
-
92
- def check_environment():
93
- """Check if required packages are installed."""
94
- required_packages = [
95
- "torch", "transformers", "diffusers", "gradio", "PIL",
96
- "accelerate", "numpy", "ftfy", "sentencepiece"
97
- ]
98
-
99
- optional_packages = {
100
- "torchao": "INT8/FP8 quantization",
101
- "xformers": "Memory efficient attention",
102
- }
103
-
104
- missing_packages = []
105
- missing_optional = []
106
-
107
- for package in required_packages:
108
- try:
109
- __import__(package)
110
- except ImportError:
111
- missing_packages.append(package)
112
-
113
- for package, description in optional_packages.items():
114
- try:
115
- __import__(package)
116
- except ImportError:
117
- missing_optional.append(f"{package} ({description})")
118
-
119
- if missing_packages:
120
- print("\n❌ Missing required packages:", ", ".join(missing_packages))
121
- print("\nInstall commands:")
122
- print("!pip install torch==2.9.0 torchvision==0.24.0 torchaudio==2.9.0 --index-url https://download.pytorch.org/whl/cu126")
123
- print("!pip install diffusers>=0.32.0 transformers>=4.46.0 accelerate gradio pillow numpy spaces ftfy sentencepiece protobuf imageio-ffmpeg")
124
- print("!pip install torchao xformers")
125
- sys.exit(1)
126
-
127
- if missing_optional and os.environ.get('DEBUG'):
128
- print("⚠ Optional packages missing:", ", ".join(missing_optional))
129
-
130
-
131
- def main():
132
- check_environment()
133
- preload_models()
134
-
135
- try:
136
- facade = FlowFacadeAOTI()
137
- ui = UIManager(facade)
138
- is_colab = 'google.colab' in sys.modules
139
-
140
- print("✓ Ready (AOTI mode)")
141
- ui.launch(
142
- share=is_colab,
143
- server_name="0.0.0.0",
144
- server_port=None,
145
- show_error=True
146
- )
147
-
148
- except KeyboardInterrupt:
149
- print("\n⚠ Shutdown requested")
150
- if 'facade' in locals():
151
- facade.cleanup()
152
- sys.exit(0)
153
-
154
- except Exception as e:
155
- print(f"\n❌ Startup error: {str(e)}")
156
- import traceback
157
- traceback.print_exc()
158
- sys.exit(1)
159
-
160
-
161
- if __name__ == "__main__":
162
- main()