Download diagnose_gpu.py from lhc-lab/AI-Colab: direct link, hf CLI and curl.
- Browser
- Download file 5.22 kB
-
https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/diagnose_gpu.py
- Command line
-
hf download hf://datasets/lhc-lab/AI-Colab/diagnose_gpu.py
-
curl -L -o diagnose_gpu.py https://huggingface.co/datasets/lhc-lab/AI-Colab/resolve/main/diagnose_gpu.py
5.22 kB
| #!/usr/bin/env python3 | |
| """ | |
| Полная диагностика GPU, CUDA и llama.cpp (Fixed for Windows Encoding) | |
| """ | |
| import subprocess | |
| import sys | |
| import json | |
| import platform | |
| import os | |
| def run_command(cmd, description): | |
| """Запустить команду и вернуть результат""" | |
| print(f"\n--- {description} ---") | |
| print(f" Команда: {cmd}") | |
| try: | |
| # На Windows используем shell=True и не форсируем utf-8 если не уверены | |
| result = subprocess.run(cmd, shell=True, capture_output=True, text=True, errors='replace') | |
| print(f" Код возврата: {result.returncode}") | |
| if result.stdout: | |
| print(f" Вывод:\n{result.stdout[:500]}") | |
| if result.stderr: | |
| print(f" Ошибки:\n{result.stderr[:500]}") | |
| return result.returncode == 0, result.stdout | |
| except Exception as e: | |
| print(f" Исключение: {e}") | |
| return False, str(e) | |
| def main(): | |
| print("=" * 80) | |
| print("DIAGNOSTICS: GPU AND LLAMA.CPP") | |
| print("=" * 80) | |
| # 1. Системная информация | |
| print(f"\nSYSTEM INFO:") | |
| print(f" OS: {platform.system()} {platform.release()}") | |
| print(f" CPU: {platform.processor()}") | |
| print(f" Python: {sys.version}") | |
| # 2. Проверка NVIDIA драйверов | |
| run_command("nvidia-smi", "NVIDIA Driver Check") | |
| # 3. Проверка CUDA Toolkit | |
| run_command("nvcc --version", "CUDA Compiler Check") | |
| # 4. Проверка PyTorch | |
| run_command(f'"{sys.executable}" -c "import torch; print(f\\"CUDA available: {{torch.cuda.is_available()}}\\")"', "PyTorch CUDA Check") | |
| # 5. Проверка llama-cpp-python сборки | |
| run_command(f'"{sys.executable}" -c "from llama_cpp import Llama; print(\\"Llama imported successfully\\")"', "Llama-cpp-python Import Check") | |
| # 6. Проверка метаданных llama-cpp-python | |
| run_command(f'"{sys.executable}" -c "import llama_cpp; print(dir(llama_cpp))"', "llama_cpp Structure") | |
| # 7. Тестовая загрузка простой модели для проверки GPU | |
| print("\nTEST MODEL LOAD:") | |
| # Ищем модель | |
| model_path_rel = "integrations/models/SmolLM2-360M-Instruct-GGUF/smollm2-360m-instruct-q8_0.gguf" | |
| if not os.path.exists(model_path_rel): | |
| # Попробуем найти любую | |
| models_dir = os.path.join(os.getcwd(), "integrations", "models") | |
| found = False | |
| if os.path.exists(models_dir): | |
| for root, dirs, files in os.walk(models_dir): | |
| for f in files: | |
| if f.endswith(".gguf"): | |
| model_path_rel = os.path.relpath(os.path.join(root, f), os.getcwd()) | |
| found = True | |
| break | |
| if found: break | |
| print(f" Using model for test: {model_path_rel}") | |
| # Создай временный конфиг для теста | |
| test_config = { | |
| "active_models": [ | |
| { | |
| "key": "test_gpu", | |
| "model_id": model_path_rel, | |
| "provider": "gptoss", | |
| "n_gpu_layers": 20, | |
| "n_ctx": 2048 | |
| } | |
| ] | |
| } | |
| with open("test_gpu_config.json", "w") as f: | |
| json.dump(test_config, f) | |
| # Тестовый скрипт загрузки | |
| test_script = """ | |
| import sys | |
| import os | |
| sys.path.insert(0, os.getcwd()) | |
| import json | |
| try: | |
| from core.llm_integrations.gptoss_adapter import GptOssModel | |
| except ImportError: | |
| from integrations.gptoss_adapter import GptOssModel | |
| print("Loading test config...") | |
| with open("test_gpu_config.json", "r") as f: | |
| config = json.load(f) | |
| model_config = config["active_models"][0] | |
| print(f"Model config: {model_config}") | |
| print("\\nCreating model instance...") | |
| model = GptOssModel(model_config) | |
| print("\\nAttempting to load model...") | |
| try: | |
| model.load_model() | |
| print("SUCCESS: Model loaded") | |
| if hasattr(model, 'model'): | |
| print(f"Model type: {type(model.model)}") | |
| else: | |
| print("WARNING: Model instance has no 'model' attribute") | |
| model.unload_model() | |
| print("Model unloaded") | |
| except Exception as e: | |
| print(f"FAILURE: Load error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| """ | |
| with open("test_gpu_load.py", "w") as f: | |
| f.write(test_script) | |
| run_command(f'"{sys.executable}" test_gpu_load.py', "Test Model Loading") | |
| # 8. Проверка версии llama-cpp-python и поддержки CUDA | |
| run_command(f'"{sys.executable}" -m pip show llama-cpp-python', "Package Info") | |
| # 9. Проверка окружения | |
| print("\nENVIRONMENT VARIABLES:") | |
| env_vars = ["CUDA_PATH", "PATH", "LD_LIBRARY_PATH", "CUDA_HOME"] | |
| for var in env_vars: | |
| value = os.environ.get(var, "not set") | |
| print(f" {var}: {value[:100]}..." if len(str(value)) > 100 else f" {var}: {value}") | |
| print("\n" + "=" * 80) | |
| print("DIAGNOSTICS COMPLETED") | |
| print("=" * 80) | |
| if __name__ == "__main__": | |
| main() | |