Spaces:
Sleeping
Sleeping
File size: 6,807 Bytes
d28c36c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
"""
Diagnostic des échecs des modèles spécialisés MCP
Analyse pourquoi les modèles plus grands et spécialisés échouent
"""
import sys
import os
def diagnose_model_failures():
"""Diagnostiquer les problèmes avec les modèles spécialisés MCP"""
print("🔍 DIAGNOSTIC DES ÉCHECS DES MODÈLES SPÉCIALISÉS MCP")
print("=" * 70)
# Modèles problématiques
problematic_models = [
{
'name': 'MCP-Instruct-v1',
'path': 'mcp-instruct-v1.Q4_K_M.gguf',
'issues': ['llama_decode returned -1']
},
{
'name': 'MCPR L-3B-Exa',
'path': 'mcprl-3b-exa.Q2_K.gguf',
'issues': ['texte corrompu', 'caractères spéciaux', 'sortie incohérente']
},
{
'name': 'Gemma-3n-E2B-it',
'path': 'gemma-3n-E2B-it-UD-IQ2_XXS.gguf',
'issues': ['réponses vides', 'pas de sortie']
}
]
# Analyse des problèmes potentiels
print("\n📋 ANALYSE DES PROBLÈMES IDENTIFIÉS:")
for model in problematic_models:
print(f"\n🧩 {model['name']}:")
if not os.path.exists(model['path']):
print(f" ❌ Fichier modèle non trouvé: {model['path']}")
continue
file_size_mb = os.path.getsize(model['path']) / (1024*1024)
print(f" 📏 Taille: {file_size_mb:.1f} MB")
print(f" 🔧 Problèmes détectés:")
for issue in model['issues']:
print(f" • {issue}")
# Causes potentielles
print("\n🔍 CAUSES POTENTIELLES DES ÉCHECS:")
print(" 1. FORMAT DE PROMPT INADÉQUAT")
print(" • Les modèles spécialisés MCP peuvent attendre un format de prompt différent")
print(" • Format actuel trop simple vs format de formation MCP spécialisé")
print(" • Besoin de tokens spéciaux ou de formatage MCP spécifique")
print("\n 2. PROBLÈMES DE CHARGEMENT DU MODÈLE")
print(" • llama_decode=-1: Erreur de décodeur LLAMA")
print(" • Modèles potentiellement incompatibles avec llama-cpp-python")
print(" • Paramètres d'initialisation incorrects")
print("\n 3. CONTEXTE ET TOKENS SPÉCIAUX")
print(" • Les modèles MCP peuvent nécessiter des tokens de début/fin spécifiques")
print(" • Format d'entrée différent de l'attente du modèle")
print(" • Besoin de format de conversation MCP structuré")
print("\n 4. QUANTISATION PROBLÉMATIQUE")
print(" • Q2_K pour MCPR L-3B-Exa peut être trop agressif")
print(" • IQ2_XXS pour Gemma-3n-E2B-it: très forte compression")
print(" • Perte de capacité avec quantisation extrême")
# Test de diagnostic avec prompts alternatifs
print("\n🚀 TEST DE DIAGNOSTIC AVEC PROMPTS ALTERNATIFS")
print("=" * 70)
from llama_cpp import Llama
# Formats de prompt alternatifs pour tester
prompt_formats = [
{
'name': 'Format actuel',
'template': '''You are an AI assistant for an RTS game using MCP (Model Context Protocol).
Available tools:
- get_game_state()
- move_units(unit_ids, target_x, target_y)
- attack_unit(attacker_ids, target_id)
- build_building(building_type, position_x, position_y)
User command: "{command}"
Respond with JSON only: {{"tool": "tool_name", "args": {{}}}}'''
},
{
'name': 'Format MCP structuré',
'template': '''<|im_start|>system
You are an AI assistant for an RTS game using the Model Context Protocol (MCP). You must respond with only JSON following this exact format:
{{"tool": "tool_name", "args": {{<arguments>}}}}
Available tools:
- get_game_state(): Get current game state
- move_units(unit_ids, target_x, target_y): Move units to coordinates
- attack_unit(attacker_ids, target_id): Attack a specific unit
- build_building(building_type, position_x, position_y): Construct a building
Always respond with valid JSON, no additional text.<|im_end|>
<|im_start|>user
{command}<|im_end|>
<|im_start|>assistant
'''
},
{
'name': 'Format simple JSON',
'template': '''User: {command}
Tools: get_game_state, move_units, attack_unit, build_building
Response (JSON only):'''
}
]
# Tester avec MCPR L-3B-Exa (le modèle qui sort du texte corrompu)
test_model = 'mcprl-3b-exa.Q2_K.gguf'
if os.path.exists(test_model):
print(f"\n🧪 Test avec {test_model}...")
try:
llm = Llama(
model_path=test_model,
n_ctx=1024,
n_threads=1,
verbose=False,
n_gpu_layers=0
)
test_command = "show game state"
for format_info in prompt_formats:
print(f"\n 📝 Format: {format_info['name']}")
prompt = format_info['template'].format(command=test_command)
try:
response = llm(
prompt,
max_tokens=50,
temperature=0.1,
stop=["</s>", "<|im_end|>", "```"]
)
response_text = response['choices'][0]['text'].strip()
print(f" Prompt (premiers 100 caractères): {prompt[:100]}...")
print(f" Réponse: {response_text[:200]}")
# Vérifier si c'est du JSON valide
try:
import json
json.loads(response_text)
print(f" ✅ JSON VALIDE!")
except:
print(f" ❌ JSON INVALIDE")
except Exception as e:
print(f" ❌ Erreur: {e}")
except Exception as e:
print(f" ❌ Impossible de charger le modèle: {e}")
# Recommandations
print("\n💡 RECOMMANDATIONS POUR CORRIGER:")
print(" 1. Essayer différentes versions de quantisation (Q4_K_M, Q8_0)")
print(" 2. Utiliser des formats de prompt structurés avec tokens MCP")
print(" 3. Augmenter la température (0.3-0.5) pour plus de variabilité")
print(" 4. Tester avec plus de tokens max (200-300)")
print(" 5. Vérifier la compatibilité avec llama-cpp-python")
print(" 6. Utiliser des modèles de taille similaire mais avec moins de compression")
if __name__ == "__main__":
diagnose_model_failures() |