Spaces:
Sleeping
Sleeping
File size: 6,846 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 |
"""
Investigation détaillée des échecs des modèles spécialisés MCP
Analyse pourquoi MCP-Instruct-v1, Gemma-3n-E2B-it et MCPR L-3B-Exa échouent
"""
import sys
import os
import json
import time
from llama_cpp import Llama
def analyze_model_failures():
"""Analyser en détail les échecs des modèles MCP"""
print("🔍 INVESTIGATION DÉTAILLÉE DES ÉCHECS MCP")
print("=" * 70)
# Modèles problématiques avec analyse détaillée
problematic_models = [
{
'name': 'MCP-Instruct-v1',
'path': 'mcp-instruct-v1.Q4_K_M.gguf',
'size_mb': 697.0,
'issues': ['llama_decode returned -1'],
'hypothesis': 'Incompatibilité technique avec llama-cpp-python'
},
{
'name': 'MCPR L-3B-Exa',
'path': 'mcprl-3b-exa.Q2_K.gguf',
'size_mb': 1215.7,
'issues': ['texte corrompu', 'caractères spéciaux', 'sortie incohérente'],
'hypothesis': 'Quantisation Q2_K trop agressive pour ce modèle'
},
{
'name': 'Gemma-3n-E2B-it',
'path': 'gemma-3n-E2B-it-UD-IQ2_XXS.gguf',
'size_mb': 1958.3,
'issues': ['réponses vides', 'pas de sortie'],
'hypothesis': 'Format de prompt incompatible avec le modèle'
}
]
# Analyse technique détaillée
print("\n📊 ANALYSE TECHNIQUE DÉTAILLÉE:")
for model in problematic_models:
print(f"\n🧩 {model['name']}:")
print(f" 📏 Taille: {model['size_mb']:.1f} MB")
print(f" 🔧 Problèmes: {', '.join(model['issues'])}")
print(f" 💭 Hypothèse: {model['hypothesis']}")
if not os.path.exists(model['path']):
print(f" ❌ Fichier non trouvé")
continue
# Test de chargement basique
print(f" 🔄 Test de chargement...")
try:
llm = Llama(
model_path=model['path'],
n_ctx=2048,
n_threads=1,
verbose=False,
n_gpu_layers=0
)
print(f" ✅ Chargement réussi")
# Test de génération très simple
print(f" 🧪 Test de génération basique...")
try:
response = llm(
"Hello",
max_tokens=10,
temperature=0.1
)
# Extraire la réponse correctement
response_text = str(response)
if hasattr(response, 'choices') and response.choices:
response_text = response.choices[0].text if hasattr(response.choices[0], 'text') else str(response.choices[0])
elif isinstance(response, dict) and 'choices' in response:
choice = response['choices'][0]
response_text = choice.get('text', str(choice))
print(f" 📝 Réponse: '{response_text.strip()}'")
except Exception as e:
print(f" ❌ Erreur génération: {e}")
except Exception as e:
print(f" ❌ Erreur chargement: {e}")
# Analyse comparative avec modèle qui fonctionne
print(f"\n🔍 COMPARAISON AVEC MODÈLE FONCTIONNEL:")
working_model = 'qwen2.5-coder-0.5b-instruct-q4_0.gguf'
if os.path.exists(working_model):
print(f"\n✅ Qwen2.5-Coder-0.5B (fonctionne):")
try:
llm = Llama(
model_path=working_model,
n_ctx=1024,
n_threads=1,
verbose=False,
n_gpu_layers=0
)
# Test avec le même prompt MCP
prompt = '''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: "show game state"
Respond with JSON only: {"tool": "tool_name", "args": {}}}'''
response = llm(
prompt,
max_tokens=50,
temperature=0.1
)
# Extraire la réponse correctement
response_text = str(response)
if hasattr(response, 'choices') and response.choices:
response_text = response.choices[0].text if hasattr(response.choices[0], 'text') else str(response.choices[0])
elif isinstance(response, dict) and 'choices' in response:
choice = response['choices'][0]
response_text = choice.get('text', str(choice))
print(f" 📝 Réponse: {response_text[:100]}...")
# Vérifier JSON
try:
json.loads(response_text)
print(f" ✅ JSON valide")
except:
print(f" ❌ JSON invalide")
except Exception as e:
print(f" ❌ Erreur: {e}")
# Conclusions et recommandations
print(f"\n🎯 CONCLUSIONS ET RECOMMANDATIONS:")
print("=" * 70)
print("\n1. MCP-INSTRUCT-V1 (Q4_K_M):")
print(" ❌ Problème: Erreur technique 'llama_decode returned -1'")
print(" 💡 Solution: Essayer version Q8_0 ou vérifier compatibilité llama-cpp-python")
print("\n2. MCPR L-3B-EXA (Q2_K):")
print(" ❌ Problème: Texte corrompu avec caractères spéciaux")
print(" 💡 Solution: Quantisation Q2_K trop agressive, essayer Q4_K_M ou Q8_0")
print("\n3. GEMMA-3N-E2B-IT (IQ2_XXS):")
print(" ❌ Problème: Réponses vides, modèle ne répond pas")
print(" 💡 Solution: Quantisation IQ2_XXS extrême, essayer version moins compressée")
print("\n4. POURQUOI LES MODÈLES CODE FONCTIONNENT MIEUX:")
print(" ✅ Habitués au format JSON et aux structures de données")
print(" ✅ Meilleure compréhension des formats structurés")
print(" ✅ Formation sur du code et des données techniques")
print("\n🚀 PLAN D'ACTION:")
print(" 1. Télécharger versions Q8_0 des modèles problématiques")
print(" 2. Tester avec formats de prompts MCP spécifiques")
print(" 3. Augmenter contexte (n_ctx) pour modèles plus grands")
print(" 4. Utiliser température légèrement plus élevée (0.3)")
print(f"\n📋 MODÈLES À TÉLÉCHARGER:")
print(" • mcp-instruct-v1.Q8_0.gguf")
print(" • mcprl-3b-exa.Q8_0.gguf")
print(" • google_gemma-3n-E2B-it-Q8_0.gguf")
if __name__ == "__main__":
analyze_model_failures() |