Make all debug and progress messages conditional on --debug flag

parent f315edea
...@@ -30,7 +30,7 @@ import time ...@@ -30,7 +30,7 @@ import time
import uuid import uuid
from .comm import SocketCommunicator, Message from .comm import SocketCommunicator, Message
from .models import get_model from .models import get_model
from .config import get_system_prompt_content, get_comm_type, get_backend_worker_port from .config import get_system_prompt_content, get_comm_type, get_backend_worker_port, get_debug
# Set PyTorch CUDA memory management # Set PyTorch CUDA memory management
os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True' os.environ['PYTORCH_CUDA_ALLOC_CONF'] = 'expandable_segments:True'
...@@ -186,7 +186,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -186,7 +186,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Initializing analysis job' 'message': 'Initializing analysis job'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 5% - Initializing analysis job") if get_debug():
print(f"PROGRESS: Job {job_id} - 5% - Initializing analysis job")
torch.cuda.empty_cache() torch.cuda.empty_cache()
total_tokens = 0 total_tokens = 0
...@@ -205,7 +206,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -205,7 +206,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Model {model_path.split("/")[-1]} loaded successfully' 'message': f'Model {model_path.split("/")[-1]} loaded successfully'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 8% - Model loaded successfully") if get_debug():
print(f"PROGRESS: Job {job_id} - 8% - Model loaded successfully")
# Get system prompt # Get system prompt
print(f"DEBUG: Retrieving system prompt for job {job_id}") print(f"DEBUG: Retrieving system prompt for job {job_id}")
...@@ -231,7 +233,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -231,7 +233,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Extracted {total_frames} frames' 'message': f'Extracted {total_frames} frames'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 10% - Extracted {total_frames} frames") if get_debug():
print(f"PROGRESS: Job {job_id} - 10% - Extracted {total_frames} frames")
descriptions = [] descriptions = []
...@@ -248,7 +251,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -248,7 +251,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Processing frame {i+1}/{total_frames} at {ts:.1f}s' 'message': f'Processing frame {i+1}/{total_frames} at {ts:.1f}s'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - {progress_percent}% - Processing frame {i+1}/{total_frames}") if get_debug():
print(f"PROGRESS: Job {job_id} - {progress_percent}% - Processing frame {i+1}/{total_frames}")
# Check for cancellation # Check for cancellation
if job_id and check_job_cancelled(job_id): if job_id and check_job_cancelled(job_id):
...@@ -283,7 +287,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -283,7 +287,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': f'Completed frame {i+1}/{total_frames} ({progress_percent}%)' 'message': f'Completed frame {i+1}/{total_frames} ({progress_percent}%)'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - {progress_percent}% - Completed frame {i+1}/{total_frames}") if get_debug():
print(f"PROGRESS: Job {job_id} - {progress_percent}% - Completed frame {i+1}/{total_frames}")
if output_dir: if output_dir:
import shutil import shutil
...@@ -300,7 +305,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -300,7 +305,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Generating video summary' 'message': 'Generating video summary'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 85% - Generating video summary") if get_debug():
print(f"PROGRESS: Job {job_id} - 85% - Generating video summary")
# Check for cancellation before summary # Check for cancellation before summary
if job_id and check_job_cancelled(job_id): if job_id and check_job_cancelled(job_id):
...@@ -339,7 +345,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -339,7 +345,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Analysis completed' 'message': 'Analysis completed'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 100% - Analysis completed") if get_debug():
print(f"PROGRESS: Job {job_id} - 100% - Analysis completed")
result = f"Frame Descriptions:\n" + "\n".join(descriptions) + f"\n\nSummary:\n{summary}" result = f"Frame Descriptions:\n" + "\n".join(descriptions) + f"\n\nSummary:\n{summary}"
return result, total_tokens return result, total_tokens
...@@ -355,7 +362,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -355,7 +362,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Starting image analysis' 'message': 'Starting image analysis'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 20% - Starting image analysis") if get_debug():
print(f"PROGRESS: Job {job_id} - 20% - Starting image analysis")
# Check for cancellation before processing image # Check for cancellation before processing image
if job_id and check_job_cancelled(job_id): if job_id and check_job_cancelled(job_id):
...@@ -371,7 +379,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -371,7 +379,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Processing image with AI model' 'message': 'Processing image with AI model'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 50% - Processing image with AI model") if get_debug():
print(f"PROGRESS: Job {job_id} - 50% - Processing image with AI model")
result, tokens = analyze_single_image(media_path, full_prompt, model) result, tokens = analyze_single_image(media_path, full_prompt, model)
total_tokens += tokens total_tokens += tokens
...@@ -386,7 +395,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -386,7 +395,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Finalizing analysis results' 'message': 'Finalizing analysis results'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 90% - Finalizing analysis results") if get_debug():
print(f"PROGRESS: Job {job_id} - 90% - Finalizing analysis results")
# Send final progress update # Send final progress update
if comm: if comm:
...@@ -397,7 +407,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm ...@@ -397,7 +407,8 @@ def analyze_media(media_path, prompt, model_path, interval=10, job_id=None, comm
'message': 'Image analysis completed successfully' 'message': 'Image analysis completed successfully'
}) })
comm.send_message(progress_msg) comm.send_message(progress_msg)
print(f"PROGRESS: Job {job_id} - 100% - Image analysis completed successfully") if get_debug():
print(f"PROGRESS: Job {job_id} - 100% - Image analysis completed successfully")
torch.cuda.empty_cache() torch.cuda.empty_cache()
return result, total_tokens return result, total_tokens
...@@ -434,7 +445,8 @@ def worker_process(backend_type: str): ...@@ -434,7 +445,8 @@ def worker_process(backend_type: str):
model_path = data.get('model_path', 'Qwen/Qwen2.5-VL-7B-Instruct') model_path = data.get('model_path', 'Qwen/Qwen2.5-VL-7B-Instruct')
interval = data.get('interval', 10) interval = data.get('interval', 10)
job_id = message.msg_id # Use message ID for job identification job_id = message.msg_id # Use message ID for job identification
print(f"PROGRESS: Job {message.msg_id} accepted - Starting analysis") if get_debug():
print(f"PROGRESS: Job {message.msg_id} accepted - Starting analysis")
print(f"DEBUG: Starting analysis of {media_path} with model {model_path} for job {job_id}") print(f"DEBUG: Starting analysis of {media_path} with model {model_path} for job {job_id}")
result, tokens_used = analyze_media(media_path, prompt, model_path, interval, job_id, comm) result, tokens_used = analyze_media(media_path, prompt, model_path, interval, job_id, comm)
print(f"DEBUG: Analysis completed for job {message.msg_id}, used {tokens_used} tokens") print(f"DEBUG: Analysis completed for job {message.msg_id}, used {tokens_used} tokens")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment