syncing latest revisions - dk123
This commit is contained in:
@@ -3,18 +3,21 @@ import os
|
||||
import sys
|
||||
import subprocess
|
||||
import torch
|
||||
import tracker
|
||||
|
||||
def check_gpu_health():
|
||||
"""
|
||||
Performs a robust check for GPU availability and prints detailed troubleshooting
|
||||
info if issues are detected, specific to Bazzite/VS Code environments.
|
||||
"""
|
||||
print("Checking GPU health...")
|
||||
tracker.logger.info("Checking GPU health...")
|
||||
|
||||
# 1. Check if the OS/Driver sees the GPU
|
||||
nvidia_smi_ok = False
|
||||
try:
|
||||
subprocess.run(["nvidia-smi"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
||||
in_flatpak = os.path.exists("/.flatpak-info")
|
||||
cmd = ["flatpak-spawn", "--host", "nvidia-smi"] if in_flatpak else ["nvidia-smi"]
|
||||
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
|
||||
nvidia_smi_ok = True
|
||||
except (subprocess.CalledProcessError, FileNotFoundError):
|
||||
nvidia_smi_ok = False
|
||||
@@ -23,36 +26,36 @@ def check_gpu_health():
|
||||
torch_cuda_ok = torch.cuda.is_available()
|
||||
|
||||
if torch_cuda_ok:
|
||||
print(f"✅ GPU is accessible: {torch.cuda.get_device_name(0)}")
|
||||
print(f" CUDA Version: {torch.version.cuda}")
|
||||
tracker.logger.info(f"✅ GPU is accessible: {torch.cuda.get_device_name(0)}")
|
||||
tracker.logger.info(f" CUDA Version: {torch.version.cuda}")
|
||||
return True
|
||||
|
||||
# --- Troubleshooting Block ---
|
||||
print("\n⚠️ WARNING: GPU not detected by PyTorch. Falling back to CPU.")
|
||||
print(" Transcription will be significantly slower.\n")
|
||||
tracker.logger.warning("\n⚠️ WARNING: GPU not detected by PyTorch. Falling back to CPU.")
|
||||
tracker.logger.warning(" Transcription will be significantly slower.\n")
|
||||
|
||||
print("--- Diagnostic Report ---")
|
||||
tracker.logger.info("--- Diagnostic Report ---")
|
||||
if nvidia_smi_ok:
|
||||
print("1. [OK] 'nvidia-smi' command works. The system driver is installed and visible.")
|
||||
print("2. [FAIL] PyTorch cannot see the GPU.")
|
||||
print(" -> Likely Cause: You might have installed the CPU-only version of PyTorch.")
|
||||
print(" -> Solution: Reinstall PyTorch with CUDA support:")
|
||||
print(" pip uninstall torch torchvision torchaudio")
|
||||
print(" pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118")
|
||||
tracker.logger.info("1. [OK] 'nvidia-smi' command works. The system driver is installed and visible.")
|
||||
tracker.logger.info("2. [FAIL] PyTorch cannot see the GPU.")
|
||||
tracker.logger.info(" -> Likely Cause: You might have installed the CPU-only version of PyTorch.")
|
||||
tracker.logger.info(" -> Solution: Reinstall PyTorch with CUDA support:")
|
||||
tracker.logger.info(" pip uninstall torch torchvision torchaudio")
|
||||
tracker.logger.info(" pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118")
|
||||
else:
|
||||
print("1. [FAIL] 'nvidia-smi' command failed or not found.")
|
||||
print(" -> Likely Cause: Nvidia drivers are missing, or the container/sandbox cannot access the GPU.")
|
||||
tracker.logger.info("1. [FAIL] 'nvidia-smi' command failed or not found.")
|
||||
tracker.logger.info(" -> Likely Cause: Nvidia drivers are missing, or the container/sandbox cannot access the GPU.")
|
||||
|
||||
print("\n --- Bazzite / VS Code / Container Specific Checks ---")
|
||||
print(" a. If you are running inside a dev container (DevBox/Distrobox/Toolbox):")
|
||||
print(" Ensure the container was created with nvidia support.")
|
||||
print(" (Bazzite usually handles this for 'distrobox', but check your config).")
|
||||
print(" b. If you are using VS Code Flatpak:")
|
||||
print(" Flatpak might be restricting access. Check Flatseal permissions for VS Code.")
|
||||
print(" c. Driver Check:")
|
||||
print(" Run 'rpm -qa | grep nvidia' in your host terminal to verify drivers are installed.")
|
||||
tracker.logger.info("\n --- Bazzite / VS Code / Container Specific Checks ---")
|
||||
tracker.logger.info(" a. If you are running inside a dev container (DevBox/Distrobox/Toolbox):")
|
||||
tracker.logger.info(" Ensure the container was created with nvidia support.")
|
||||
tracker.logger.info(" (Bazzite usually handles this for 'distrobox', but check your config).")
|
||||
tracker.logger.info(" b. If you are using VS Code Flatpak:")
|
||||
tracker.logger.info(" Flatpak might be restricting access. Check Flatseal permissions for VS Code.")
|
||||
tracker.logger.info(" c. Driver Check:")
|
||||
tracker.logger.info(" Run 'rpm -qa | grep nvidia' in your host terminal to verify drivers are installed.")
|
||||
|
||||
print("-------------------------\n")
|
||||
tracker.logger.info("-------------------------\n")
|
||||
return False
|
||||
|
||||
def get_vram_gb():
|
||||
@@ -80,7 +83,7 @@ def get_optimal_model_size():
|
||||
if vram == 0:
|
||||
return "base"
|
||||
|
||||
print(f"Detected GPU with {vram:.2f} GB VRAM.")
|
||||
tracker.logger.info(f"Detected GPU with {vram:.2f} GB VRAM.")
|
||||
|
||||
if vram >= 11:
|
||||
return "large"
|
||||
@@ -113,7 +116,7 @@ def save_as_srt(result, output_path):
|
||||
f.write(f"{i}\n")
|
||||
f.write(f"{start} --> {end}\n")
|
||||
f.write(f"{text}\n\n")
|
||||
print(f"SRT saved to: {output_path}")
|
||||
tracker.logger.info(f"SRT saved to: {output_path}")
|
||||
|
||||
def load_whisper_model(model_size="auto"):
|
||||
"""
|
||||
@@ -123,17 +126,17 @@ def load_whisper_model(model_size="auto"):
|
||||
|
||||
if model_size == "auto":
|
||||
model_size = get_optimal_model_size()
|
||||
print(f"Auto-selected model: '{model_size}'")
|
||||
tracker.logger.info(f"Auto-selected model: '{model_size}'")
|
||||
|
||||
print(f"Loading Whisper model ('{model_size}')...")
|
||||
tracker.logger.info(f"Loading Whisper model ('{model_size}')...")
|
||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||
print(f"Using device: {device}")
|
||||
tracker.logger.info(f"Using device: {device}")
|
||||
|
||||
try:
|
||||
model = whisper.load_model(model_size, device=device)
|
||||
return model
|
||||
except Exception as e:
|
||||
print(f"Error loading model: {e}")
|
||||
tracker.logger.error(f"Error loading model: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
def transcribe_audio(audio_path, model_size="auto", language=None, loaded_model=None):
|
||||
@@ -156,12 +159,12 @@ def transcribe_audio(audio_path, model_size="auto", language=None, loaded_model=
|
||||
if model is None:
|
||||
model = load_whisper_model(model_size)
|
||||
|
||||
print(f"Transcribing {audio_path}...")
|
||||
tracker.logger.info(f"Transcribing {audio_path}...")
|
||||
try:
|
||||
# Enable verbose=True to show progress in terminal
|
||||
result = model.transcribe(audio_path, language=language, verbose=True)
|
||||
print("Transcription complete.")
|
||||
# Disable verbose to prevent line-by-line output
|
||||
result = model.transcribe(audio_path, language=language, verbose=False)
|
||||
tracker.logger.info("Transcription complete.")
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"Error during transcription: {e}")
|
||||
tracker.logger.error(f"Error during transcription: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user