youssef
commited on
Commit
·
b75046f
1
Parent(s):
917e7fe
use device
Browse files
src/video_processor/processor.py
CHANGED
|
@@ -18,25 +18,17 @@ class VideoAnalyzer:
|
|
| 18 |
self.model_path = "HuggingFaceTB/SmolVLM2-2.2B-Instruct"
|
| 19 |
logger.info(f"Loading model from {self.model_path}")
|
| 20 |
|
| 21 |
-
cache_dir = "/models"
|
| 22 |
-
logger.info(f"Using cache directory: {cache_dir}")
|
| 23 |
-
|
| 24 |
# Load processor and model
|
| 25 |
self.processor = AutoProcessor.from_pretrained(
|
| 26 |
self.model_path,
|
| 27 |
-
cache_dir=cache_dir,
|
| 28 |
torch_dtype=torch.bfloat16
|
| 29 |
)
|
| 30 |
|
| 31 |
-
# Load model directly to CUDA
|
| 32 |
-
device_map = {"": 0} # Force model to GPU 0
|
| 33 |
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 34 |
self.model_path,
|
| 35 |
torch_dtype=torch.bfloat16,
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
cache_dir=cache_dir
|
| 39 |
-
)
|
| 40 |
logger.info(f"Model loaded on device: {self.model.device}")
|
| 41 |
|
| 42 |
def process_video(self, video_path: str, frame_interval: int = 30) -> List[Dict]:
|
|
|
|
| 18 |
self.model_path = "HuggingFaceTB/SmolVLM2-2.2B-Instruct"
|
| 19 |
logger.info(f"Loading model from {self.model_path}")
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Load processor and model
|
| 22 |
self.processor = AutoProcessor.from_pretrained(
|
| 23 |
self.model_path,
|
|
|
|
| 24 |
torch_dtype=torch.bfloat16
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
| 27 |
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 28 |
self.model_path,
|
| 29 |
torch_dtype=torch.bfloat16,
|
| 30 |
+
_attn_implementation="flash_attention_2"
|
| 31 |
+
).to(DEVICE)
|
|
|
|
|
|
|
| 32 |
logger.info(f"Model loaded on device: {self.model.device}")
|
| 33 |
|
| 34 |
def process_video(self, video_path: str, frame_interval: int = 30) -> List[Dict]:
|