AutoFixBot commited on
Commit
697a117
·
1 Parent(s): e545482

Quick auto-fix: remove recursion + safe handler

Browse files
handler.py CHANGED
@@ -1,13 +1,12 @@
 
 
1
  from diffusers import DiffusionPipeline
2
  import torch
3
- import os
4
 
5
  class EndpointHandler:
6
  def __init__(self, model_dir: str):
7
- print("🚀 Initializing Wan2.2 Diffusers pipeline (robust mode)...")
8
-
9
  try:
10
- # First attempt — normal load with relaxed safety flags
11
  self.pipe = DiffusionPipeline.from_pretrained(
12
  model_dir,
13
  torch_dtype=torch.float16,
@@ -15,38 +14,24 @@ class EndpointHandler:
15
  ignore_mismatched_sizes=True,
16
  safety_checker=None
17
  )
18
-
19
- except RuntimeError as e:
20
- print("⚠️ Mismatch detected during model load. Retrying component-wise load...")
21
- # Fallback: reload manually with relaxed constraints
22
  self.pipe = DiffusionPipeline.from_pretrained(
23
  model_dir,
24
  torch_dtype=torch.float16,
25
  low_cpu_mem_usage=False,
26
  safety_checker=None
27
  )
28
- for name, module in self.pipe.components.items():
29
- try:
30
- if hasattr(module, "load_state_dict"):
31
- print(f"Reloading {name} with ignore_mismatched_sizes=True")
32
- module.load_state_dict(
33
- module.state_dict(), strict=False
34
- )
35
- except Exception as sub_e:
36
- print(f"Skipping {name}: {sub_e}")
37
 
38
  if torch.cuda.is_available():
39
  self.pipe.to("cuda")
40
- print("✅ Pipeline moved to CUDA")
41
  else:
42
- print("⚠️ CUDA not available — running on CPU")
43
-
44
- print("✅ Pipeline initialized successfully!")
45
 
46
  def __call__(self, data):
47
- inputs = data.get("inputs", None)
48
- if not inputs:
49
- raise ValueError("Missing 'inputs' key in request payload.")
50
- print(f"🖼️ Generating video for input: {inputs}")
51
- output = self.pipe(inputs)
52
- return {"output": output}
 
1
+ import os
2
+ os.environ["DIFFUSERS_NO_CONFIG_RECURSION"] = "1"
3
  from diffusers import DiffusionPipeline
4
  import torch
 
5
 
6
  class EndpointHandler:
7
  def __init__(self, model_dir: str):
8
+ print("🚀 Initializing Wan2.2 Diffusers pipeline (safe mode)...")
 
9
  try:
 
10
  self.pipe = DiffusionPipeline.from_pretrained(
11
  model_dir,
12
  torch_dtype=torch.float16,
 
14
  ignore_mismatched_sizes=True,
15
  safety_checker=None
16
  )
17
+ except Exception as e:
18
+ print("⚠️ Retry with relaxed loading:", e)
 
 
19
  self.pipe = DiffusionPipeline.from_pretrained(
20
  model_dir,
21
  torch_dtype=torch.float16,
22
  low_cpu_mem_usage=False,
23
  safety_checker=None
24
  )
 
 
 
 
 
 
 
 
 
25
 
26
  if torch.cuda.is_available():
27
  self.pipe.to("cuda")
28
+ print("✅ Pipeline on CUDA")
29
  else:
30
+ print("⚠️ CUDA not found — running on CPU")
 
 
31
 
32
  def __call__(self, data):
33
+ prompt = data.get("inputs", "")
34
+ if not prompt:
35
+ raise ValueError("Missing 'inputs' field in request.")
36
+ result = self.pipe(prompt)
37
+ return {"output": result}
 
image_encoder/config.json CHANGED
@@ -1 +1,4 @@
1
- {"_class_name": "image_encoder", "_commit": "placeholder"}
 
 
 
 
1
+ {
2
+ "_class_name": "image_encoder",
3
+ "_commit": "placeholder"
4
+ }
image_encoder/diffusion_pytorch_model.safetensors.index.json CHANGED
@@ -1,9 +1,3 @@
1
- {
2
- "metadata": {
3
- "format": "pt",
4
- "total_size": 4920000000
5
- },
6
- "weight_map": {
7
- "model": "diffusion_pytorch_model.safetensors"
8
- }
9
- }
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ba5409b0bc67e3e65bc765cb93a34f17dace99d17a5f934fb5bbf3e6e64a917c
3
+ size 146
 
 
 
 
 
 
image_processor/config.json CHANGED
@@ -1 +1,4 @@
1
- {"_class_name": "image_processor", "_commit": "placeholder"}
 
 
 
 
1
+ {
2
+ "_class_name": "image_processor",
3
+ "_commit": "placeholder"
4
+ }
scheduler/config.json CHANGED
@@ -1 +1,4 @@
1
- {"_class_name": "scheduler", "_commit": "placeholder"}
 
 
 
 
1
+ {
2
+ "_class_name": "scheduler",
3
+ "_commit": "placeholder"
4
+ }
text_encoder/config.json CHANGED
@@ -1 +1,4 @@
1
- {"_class_name": "text_encoder", "_commit": "placeholder"}
 
 
 
 
1
+ {
2
+ "_class_name": "text_encoder",
3
+ "_commit": "placeholder"
4
+ }
tokenizer/config.json CHANGED
@@ -1 +1,4 @@
1
- {"_class_name": "tokenizer", "_commit": "placeholder"}
 
 
 
 
1
+ {
2
+ "_class_name": "tokenizer",
3
+ "_commit": "placeholder"
4
+ }