Second-Me/docker/app/check_torch_cuda.py
Zachary Pitroda 053090937d
Added CUDA support (#228)
* Add CUDA support

- CUDA detection
- Memory handling
- Ollama model release after training

* Fix logging issue

added cuda support flag so log accurately reflected cuda toggle

* Update llama.cpp rebuild

Changed llama.cpp to only check if cuda support is enabled and if so rebuild during the first build rather than each run

* Improved vram management

Enabled memory pinning and optimizer state offload

* Fix CUDA check

rewrote llama.cpp rebuild logic, added manual y/n toggle if user wants to enable cuda support

* Added fast restart and fixed CUDA check command

Added make docker-restart-backend-fast to restart the backend and reflect code changes without causing a full llama.cpp rebuild

Fixed make docker-check-cuda command to correctly reflect cuda support

* Added docker-compose.gpu.yml

Added docker-compose.gpu.yml to fix error on machines without nvidia gpu and made sure "\n" is added before .env modification

* Fixed cuda toggle

Last push accidentally broke cuda toggle

* Code review fixes

Fixed errors resulting from removed code:
- Added return save_path to end of save_hf_model function
- Rolled back download_file_with_progress function

* Update Makefile

Use cuda by default when using docker-restart-backend-fast

* Minor cleanup

Removed unnecessary makefile command and fixed gpu logging

* Delete .gpu_selected

* Simplified cuda training code

- Removed dtype setting to let torch automatically handle it
- Removed vram logging
- Removed Unnecessary/old comments

* Fixed gpu/cpu selection

Made "make docker-use-gpu/cpu" command work with .gpu_selected flag and changed "make docker-restart-backend-fast" command to respect flag instead of always using gpu

* Fix Ollama embedding error

Added custom exception class for Ollama embeddings, which seemed to be returning keyword arguments while the Python exception class only accepts positional ones

* Fixed model selection & memory error

Fixed training defaulting to 0.5B model regardless of selection and fixed "free(): double free detected in tcache 2" error caused by cuda flag being passed incorrectly
2025-04-25 10:20:36 +08:00

52 lines
No EOL
1.8 KiB
Python

#!/usr/bin/env python3
import torch
import subprocess
import sys
import os
print("=== PyTorch CUDA Version Information ===")
print(f"PyTorch version: {torch.__version__}")
if torch.cuda.is_available():
print(f"CUDA available: Yes")
print(f"CUDA version used by PyTorch: {torch.version.cuda}")
print(f"cuDNN version: {torch.backends.cudnn.version() if torch.backends.cudnn.is_available() else 'Not available'}")
print(f"GPU device name: {torch.cuda.get_device_name(0)}")
# Try to check system CUDA version
try:
nvcc_output = subprocess.check_output(["nvcc", "--version"]).decode("utf-8")
print("\nSystem NVCC version:")
print(nvcc_output)
except:
print("\nNVCC not found in PATH")
# Check CUDA libraries
try:
print("\nChecking required CUDA libraries:")
for lib in ["libcudart.so", "libcublas.so", "libcublasLt.so"]:
print(f"\nSearching for {lib}:")
find_result = subprocess.run(f"find /usr -name '{lib}*'", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if find_result.returncode == 0 and find_result.stdout:
print(find_result.stdout.decode("utf-8"))
else:
print(f"No {lib} found in /usr")
except Exception as e:
print(f"Error checking libraries: {e}")
# Check LD_LIBRARY_PATH
print("\nLD_LIBRARY_PATH:")
print(os.environ.get("LD_LIBRARY_PATH", "Not set"))
else:
print("CUDA not available")
# Check system CUDA installation
print("\n=== System CUDA Information ===")
try:
nvidia_smi = subprocess.check_output(["nvidia-smi"]).decode("utf-8")
print("NVIDIA-SMI output:")
print(nvidia_smi)
except:
print("nvidia-smi not found or not working")