Spaces:
Sleeping
Sleeping
John Ho
commited on
Commit
·
2a9891d
1
Parent(s):
7c03996
trying to set device outsite of spaces.GPU decorator
Browse files
app.py
CHANGED
|
@@ -22,6 +22,10 @@ subprocess.run(
|
|
| 22 |
|
| 23 |
# The model is trained on 8.0 FPS which we recommend for optimal inference
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
def get_fps_ffmpeg(video_path: str):
|
| 27 |
probe = ffmpeg.probe(video_path)
|
|
@@ -37,7 +41,6 @@ def get_fps_ffmpeg(video_path: str):
|
|
| 37 |
return num / denom
|
| 38 |
|
| 39 |
|
| 40 |
-
@spaces.GPU(duration=30)
|
| 41 |
def load_model(
|
| 42 |
model_name: str = "chancharikm/qwen2.5-vl-7b-cam-motion-preview",
|
| 43 |
use_flash_attention: bool = True,
|
|
@@ -54,7 +57,7 @@ def load_model(
|
|
| 54 |
else Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 55 |
model_name,
|
| 56 |
torch_dtype=torch.bfloat16, # "auto",
|
| 57 |
-
device_map=
|
| 58 |
)
|
| 59 |
)
|
| 60 |
return model
|
|
@@ -98,7 +101,7 @@ def inference(
|
|
| 98 |
return_tensors="pt",
|
| 99 |
**video_kwargs,
|
| 100 |
)
|
| 101 |
-
inputs = inputs.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 102 |
|
| 103 |
# Inference
|
| 104 |
generated_ids = model.generate(**inputs, max_new_tokens=128)
|
|
|
|
| 22 |
|
| 23 |
# The model is trained on 8.0 FPS which we recommend for optimal inference
|
| 24 |
|
| 25 |
+
DTYPE = torch.bfloat16
|
| 26 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 27 |
+
logger.info(f"Device: {device}, dtype: {dtype}")
|
| 28 |
+
|
| 29 |
|
| 30 |
def get_fps_ffmpeg(video_path: str):
|
| 31 |
probe = ffmpeg.probe(video_path)
|
|
|
|
| 41 |
return num / denom
|
| 42 |
|
| 43 |
|
|
|
|
| 44 |
def load_model(
|
| 45 |
model_name: str = "chancharikm/qwen2.5-vl-7b-cam-motion-preview",
|
| 46 |
use_flash_attention: bool = True,
|
|
|
|
| 57 |
else Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
| 58 |
model_name,
|
| 59 |
torch_dtype=torch.bfloat16, # "auto",
|
| 60 |
+
device_map=DEVICE,
|
| 61 |
)
|
| 62 |
)
|
| 63 |
return model
|
|
|
|
| 101 |
return_tensors="pt",
|
| 102 |
**video_kwargs,
|
| 103 |
)
|
| 104 |
+
# inputs = inputs.to("cuda" if torch.cuda.is_available() else "cpu")
|
| 105 |
|
| 106 |
# Inference
|
| 107 |
generated_ids = model.generate(**inputs, max_new_tokens=128)
|