Spaces:
Sleeping
Sleeping
| """ | |
| Script de débogage pour identifier le problème de chargement du modèle Qwen2.5 0.5B | |
| """ | |
| import sys | |
| import os | |
| import traceback | |
| print("🔍 DÉBOGAGE DU CHARGEMENT DU MODÈLE QWEN2.5 0.5B") | |
| print("=" * 60) | |
| # Vérifier l'existence du modèle | |
| model_path = "qwen2.5-0.5b-instruct-q4_0.gguf" | |
| if not os.path.exists(model_path): | |
| print("❌ Modèle non trouvé à l'emplacement attendu") | |
| print(f" Recherché: {os.path.abspath(model_path)}") | |
| sys.exit(1) | |
| print(f"✅ Modèle trouvé: {os.path.abspath(model_path)}") | |
| print(f"📏 Taille: {os.path.getsize(model_path) / (1024*1024):.1f} MB") | |
| # Test 1: Importation de llama_cpp | |
| print("\n🧪 TEST 1: Importation de llama_cpp") | |
| try: | |
| import llama_cpp | |
| print("✅ llama_cpp importé avec succès") | |
| print(f" Version: {llama_cpp.__version__}") | |
| except Exception as e: | |
| print(f"❌ Erreur d'importation: {e}") | |
| traceback.print_exc() | |
| sys.exit(1) | |
| # Test 2: Test de chargement simple | |
| print("\n🧪 TEST 2: Chargement direct du modèle") | |
| try: | |
| from llama_cpp import Llama | |
| # Essayer différentes configurations | |
| configs = [ | |
| {"n_threads": 1, "n_ctx": 2048}, | |
| {"n_threads": 2, "n_ctx": 2048}, | |
| {"n_threads": 1, "n_ctx": 1024}, | |
| {"n_threads": 1, "n_ctx": 512}, | |
| ] | |
| for i, config in enumerate(configs, 1): | |
| print(f"\n Configuration {i}: threads={config['n_threads']}, ctx={config['n_ctx']}") | |
| try: | |
| llm = Llama( | |
| model_path=model_path, | |
| n_ctx=config['n_ctx'], | |
| n_threads=config['n_threads'] | |
| ) | |
| print(" ✅ Modèle chargé avec succès") | |
| # Test d'inférence simple | |
| print(" 🧠 Test d'inférence...") | |
| response = llm( | |
| "Réponds avec 'TEST_RÉUSSI': ", | |
| max_tokens=10, | |
| temperature=0.1, | |
| echo=False | |
| ) | |
| # Gérer la réponse (peut être un générateur ou un dict) | |
| if hasattr(response, '__iter__') and not isinstance(response, dict): | |
| # C'est un générateur, prendre le premier élément | |
| response = next(response) | |
| if isinstance(response, dict) and 'choices' in response: | |
| text = response['choices'][0]['text'].strip() | |
| print(f" 📝 Réponse: {text}") | |
| if "TEST_RÉUSSI" in text: | |
| print(" ✅ Test d'inférence réussi!") | |
| break | |
| else: | |
| print(f" ⚠️ Format de réponse inattendu: {type(response)}") | |
| except Exception as e: | |
| print(f" ❌ Erreur: {e}") | |
| traceback.print_exc() | |
| else: | |
| print("❌ Toutes les configurations ont échoué") | |
| except Exception as e: | |
| print(f"❌ Erreur lors du chargement: {e}") | |
| traceback.print_exc() | |
| # Test 3: Vérification de l'environnement | |
| print("\n🧪 TEST 3: Vérification de l'environnement") | |
| print(f" Python: {sys.version}") | |
| print(f" Répertoire de travail: {os.getcwd()}") | |
| print(f" Variables d'environnement PATH: {os.environ.get('PATH', 'Non défini')}") | |
| # Test 4: Vérification des permissions | |
| print("\n🧪 TEST 4: Vérification des permissions") | |
| try: | |
| # Tester la lecture du fichier | |
| with open(model_path, 'rb') as f: | |
| header = f.read(100) | |
| print(f" ✅ Fichier lisible, header: {header[:20]}...") | |
| # Tester les permissions | |
| import stat | |
| st = os.stat(model_path) | |
| permissions = stat.filemode(st.st_mode) | |
| print(f" Permissions: {permissions}") | |
| # Vérifier l'espace mémoire | |
| import shutil | |
| total, used, free = shutil.disk_usage(".") | |
| print(f" Espace disque libre: {free / (1024**3):.1f} GB") | |
| except Exception as e: | |
| print(f" ❌ Erreur de lecture: {e}") | |
| print("\n" + "=" * 60) | |
| print("🔍 RÉSUMÉ DU DÉBOGAGE") | |
| print("=" * 60) |