Spaces:
Sleeping
Sleeping
Fix: Added sentencepiece and improved model patching with fail-safes
Browse files- app/models/video_reasoning.py +13 -12
- app/services/video_pipeline.py +11 -5
- requirements.txt +1 -0
app/models/video_reasoning.py
CHANGED
|
@@ -47,24 +47,25 @@ class VideoReasoningModule:
|
|
| 47 |
print(f"[VideoReasoning] GenerationConfig Warning: {e}")
|
| 48 |
|
| 49 |
# Recursive patch for transformers 4.50+ compatibility
|
| 50 |
-
# PhiForCausalLM no longer inherits from GenerationMixin in newer transformers,
|
| 51 |
-
# but moondream2's remote code expects .generate() to be available on sub-models.
|
| 52 |
def patch_recursive(m, path="model"):
|
| 53 |
-
if m
|
| 54 |
-
not hasattr(m, "generate") and hasattr(m, "prepare_inputs_for_generation")
|
| 55 |
-
):
|
| 56 |
if not isinstance(m, GenerationMixin):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
(m.__class__, GenerationMixin)
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
for name, child in m.named_children():
|
| 65 |
patch_recursive(child, f"{path}.{name}")
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id, revision=self.revision, use_fast=True)
|
| 70 |
|
|
|
|
| 47 |
print(f"[VideoReasoning] GenerationConfig Warning: {e}")
|
| 48 |
|
| 49 |
# Recursive patch for transformers 4.50+ compatibility
|
|
|
|
|
|
|
| 50 |
def patch_recursive(m, path="model"):
|
| 51 |
+
if not hasattr(m, "generate") and hasattr(m, "prepare_inputs_for_generation"):
|
|
|
|
|
|
|
| 52 |
if not isinstance(m, GenerationMixin):
|
| 53 |
+
try:
|
| 54 |
+
print(f"[VideoReasoning] Patching {path} ({m.__class__.__name__}) with GenerationMixin...")
|
| 55 |
+
# Use a simpler inheritance approach
|
| 56 |
+
class PatchedModule(m.__class__, GenerationMixin):
|
| 57 |
+
pass
|
| 58 |
+
m.__class__ = PatchedModule
|
| 59 |
+
except Exception as patch_e:
|
| 60 |
+
print(f"[VideoReasoning] Patch failed for {path}: {patch_e}")
|
| 61 |
|
| 62 |
for name, child in m.named_children():
|
| 63 |
patch_recursive(child, f"{path}.{name}")
|
| 64 |
|
| 65 |
+
try:
|
| 66 |
+
patch_recursive(self.model)
|
| 67 |
+
except Exception as e:
|
| 68 |
+
print(f"[VideoReasoning] Recursive patch aborted: {e}")
|
| 69 |
|
| 70 |
self.tokenizer = AutoTokenizer.from_pretrained(self.model_id, revision=self.revision, use_fast=True)
|
| 71 |
|
app/services/video_pipeline.py
CHANGED
|
@@ -40,12 +40,18 @@ def get_video_module(name: str):
|
|
| 40 |
return _video_modules[name]
|
| 41 |
except Exception as e:
|
| 42 |
print(f" [FAIL] Failed to load module '{name}': {e}", flush=True)
|
| 43 |
-
if name
|
| 44 |
print(f" [WARM] Using dummy fallback for '{name}' to avoid pipeline crash.")
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return _video_modules[name]
|
| 50 |
raise e
|
| 51 |
|
|
|
|
| 40 |
return _video_modules[name]
|
| 41 |
except Exception as e:
|
| 42 |
print(f" [FAIL] Failed to load module '{name}': {e}", flush=True)
|
| 43 |
+
if name in ["reasoning", "clip"]:
|
| 44 |
print(f" [WARM] Using dummy fallback for '{name}' to avoid pipeline crash.")
|
| 45 |
+
if name == "reasoning":
|
| 46 |
+
class DummyReasoning:
|
| 47 |
+
def analyze_physics(self, *args, **kwargs):
|
| 48 |
+
return {"score": 0.5, "reasoning": "Reasoning engine unavailable (Load Error)."}
|
| 49 |
+
_video_modules[name] = DummyReasoning()
|
| 50 |
+
else: # clip
|
| 51 |
+
class DummyClip:
|
| 52 |
+
def get_signal(self, *args, **kwargs):
|
| 53 |
+
return {"score": 0.5, "timeline": [], "max_spike": 0.5}
|
| 54 |
+
_video_modules[name] = DummyClip()
|
| 55 |
return _video_modules[name]
|
| 56 |
raise e
|
| 57 |
|
requirements.txt
CHANGED
|
@@ -42,3 +42,4 @@ google-generativeai
|
|
| 42 |
protobuf~=4.25.3
|
| 43 |
python-magic
|
| 44 |
reportlab
|
|
|
|
|
|
| 42 |
protobuf~=4.25.3
|
| 43 |
python-magic
|
| 44 |
reportlab
|
| 45 |
+
sentencepiece
|