kvn420 commited on
Commit
c38572d
·
verified ·
1 Parent(s): 4c516c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +222 -197
app.py CHANGED
@@ -44,7 +44,7 @@ def check_and_import_dependencies():
44
  """Vérifie et importe toutes les dépendances"""
45
  global numpy, torch, NUMPY_AVAILABLE, TORCH_AVAILABLE, TRANSFORMERS_AVAILABLE
46
  global DATASETS_AVAILABLE, HF_HUB_AVAILABLE, PIL_AVAILABLE, LIBROSA_AVAILABLE, CV2_AVAILABLE
47
- global AutoTokenizer, AutoModel, AutoProcessor, AutoModelForCausalLM
48
  global TrainingArguments, Trainer, DataCollatorForLanguageModeling
49
  global Dataset, load_dataset, concatenate_datasets, HfApi, Image, librosa, cv2
50
 
@@ -67,14 +67,14 @@ def check_and_import_dependencies():
67
  # Transformers
68
  try:
69
  from transformers import (
70
- AutoTokenizer, AutoModel, AutoProcessor,
71
  AutoModelForCausalLM, TrainingArguments, Trainer,
72
  DataCollatorForLanguageModeling
73
  )
74
  TRANSFORMERS_AVAILABLE = True
75
  except ImportError:
76
  TRANSFORMERS_AVAILABLE = False
77
- AutoTokenizer = AutoModel = AutoProcessor = None
78
  AutoModelForCausalLM = TrainingArguments = Trainer = None
79
  DataCollatorForLanguageModeling = None
80
 
@@ -144,16 +144,17 @@ class MultimodalTrainer:
144
  """Installe les dépendances manquantes"""
145
  installation_results = []
146
 
147
- # Mapping des packages
148
  package_mapping = {
149
- "torch": "torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu",
150
- "transformers": "transformers",
151
- "datasets": "datasets",
152
- "accelerate": "accelerate",
153
- "pillow": "pillow",
154
- "librosa": "librosa",
155
- "opencv": "opencv-python",
156
- "huggingface_hub": "huggingface_hub"
 
157
  }
158
 
159
  for package in packages_to_install:
@@ -167,7 +168,7 @@ class MultimodalTrainer:
167
  try:
168
  subprocess.check_call([
169
  sys.executable, "-m", "pip", "install",
170
- "torch", "torchvision", "torchaudio",
171
  "--index-url", "https://download.pytorch.org/whl/cpu",
172
  "--quiet"
173
  ])
@@ -230,145 +231,222 @@ class MultimodalTrainer:
230
  status += f"🚀 GPU: {torch.cuda.get_device_name()}\n"
231
  status += f"🔋 VRAM: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f}GB\n"
232
 
 
 
 
 
 
233
  return status
234
 
235
- def load_model(self, model_name: str, model_type: str = "causal"):
236
- """Charge un modèle depuis Hugging Face"""
237
  if not TRANSFORMERS_AVAILABLE:
238
- return "❌ Transformers non installé! Utilisez l'outil d'installation."
239
 
240
  if not TORCH_AVAILABLE or not torch:
241
- return "❌ PyTorch non installé! Utilisez l'outil d'installation."
242
 
243
- if not model_name.strip():
244
- return "❌ Veuillez entrer un nom de modèle"
245
-
246
  try:
247
- logger.info(f"Chargement du modèle: {model_name}")
248
 
249
- # Stratégies de chargement multiples
250
- model_loaded = False
251
- error_messages = []
 
 
 
252
 
253
- # Stratégie 1: AutoModelForCausalLM avec trust_remote_code
254
- if model_type == "causal" and not model_loaded:
255
- try:
256
- self.current_model = AutoModelForCausalLM.from_pretrained(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  model_name,
258
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
259
  device_map="auto" if torch.cuda.is_available() else None,
260
- trust_remote_code=True
 
261
  )
262
- model_loaded = True
263
- except Exception as e:
264
- error_messages.append(f"AutoModelForCausalLM: {str(e)}")
265
-
266
- # Stratégie 2: AutoModel générique
267
- if not model_loaded:
268
- try:
269
- self.current_model = AutoModel.from_pretrained(
270
  model_name,
 
271
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
272
  device_map="auto" if torch.cuda.is_available() else None,
273
- trust_remote_code=True
 
 
274
  )
275
- model_loaded = True
276
- except Exception as e:
277
- error_messages.append(f"AutoModel: {str(e)}")
278
-
279
- # Stratégie 3: Détection automatique basée sur le nom
280
- if not model_loaded and any(x in model_name.lower() for x in ['llama', 'mistral', 'qwen', 'phi']):
281
- try:
282
- # Pour les modèles de type LLaMA/Mistral/Qwen
283
- from transformers import LlamaForCausalLM, MistralForCausalLM
284
-
285
- if 'llama' in model_name.lower():
286
- self.current_model = LlamaForCausalLM.from_pretrained(
287
- model_name,
288
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
289
- device_map="auto" if torch.cuda.is_available() else None,
290
- trust_remote_code=True
291
- )
292
- elif 'mistral' in model_name.lower():
293
- self.current_model = MistralForCausalLM.from_pretrained(
294
- model_name,
295
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
296
- device_map="auto" if torch.cuda.is_available() else None,
297
- trust_remote_code=True
298
- )
299
- model_loaded = True
300
- except Exception as e:
301
- error_messages.append(f"Modèle spécifique: {str(e)}")
302
-
303
- # Stratégie 4: Configuration manuelle
304
- if not model_loaded:
305
- try:
306
- # Télécharge la configuration d'abord
307
- from transformers import AutoConfig
308
- config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
309
-
310
- # Force le model_type si manquant
311
- if not hasattr(config, 'model_type') or config.model_type is None:
312
- # Détection basée sur l'architecture
313
- if hasattr(config, 'architectures') and config.architectures:
314
- arch = config.architectures[0].lower()
315
- if 'llama' in arch:
316
- config.model_type = 'llama'
317
- elif 'mistral' in arch:
318
- config.model_type = 'mistral'
319
- elif 'qwen' in arch:
320
- config.model_type = 'qwen2'
321
- elif 'phi' in arch:
322
- config.model_type = 'phi'
323
- else:
324
- config.model_type = 'llama' # Par défaut
325
-
326
- self.current_model = AutoModelForCausalLM.from_pretrained(
327
  model_name,
328
- config=config,
329
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
330
  device_map="auto" if torch.cuda.is_available() else None,
331
- trust_remote_code=True
 
332
  )
333
- model_loaded = True
 
 
 
 
 
 
 
 
 
334
  except Exception as e:
335
- error_messages.append(f"Configuration manuelle: {str(e)}")
 
 
336
 
337
- if not model_loaded:
338
- return f"❌ Impossible de charger le modèle. Erreurs:\n" + "\n".join(error_messages)
339
 
340
- # Charge le tokenizer
 
341
  try:
342
- self.current_tokenizer = AutoTokenizer.from_pretrained(
343
- model_name, trust_remote_code=True
344
- )
345
- if self.current_tokenizer.pad_token is None:
346
- self.current_tokenizer.pad_token = self.current_tokenizer.eos_token
347
  except Exception as e:
348
- logger.warning(f"Tokenizer non trouvé: {e}")
349
- try:
350
- # Essaye avec un tokenizer générique
351
- from transformers import LlamaTokenizer
352
- self.current_tokenizer = LlamaTokenizer.from_pretrained(
353
- model_name, trust_remote_code=True
354
- )
355
- except:
356
- logger.warning("Aucun tokenizer trouvé")
357
-
358
- # Charge le processor
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  try:
360
- self.current_processor = AutoProcessor.from_pretrained(
361
- model_name, trust_remote_code=True
362
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
  except Exception as e:
364
- logger.warning(f"Processor non trouvé: {e}")
365
 
366
- return f"✅ Modèle {model_name} chargé avec succès!\nType: {type(self.current_model).__name__}\nArchitecture: {getattr(self.current_model.config, 'architectures', ['Inconnue'])[0] if hasattr(self.current_model, 'config') else 'Inconnue'}"
 
 
 
 
 
 
 
 
367
 
368
  except Exception as e:
369
- error_msg = f"❌ Erreur lors du chargement: {str(e)}"
370
- logger.error(error_msg)
371
- return error_msg
372
 
373
  def load_single_dataset(self, dataset_name: str, split: str = "train"):
374
  """Charge un dataset individuel"""
@@ -437,56 +515,8 @@ class MultimodalTrainer:
437
  info += f"\n📊 DONNÉES:\n"
438
  info += f"📈 Exemples: {len(self.training_data):,}\n"
439
  info += f"📝 Colonnes: {list(self.training_data.column_names)}\n"
440
-
441
- def diagnose_model(self, model_name: str):
442
- """Diagnostique un modèle avant chargement"""
443
- if not model_name.strip():
444
- return "❌ Veuillez entrer un nom de modèle"
445
-
446
- try:
447
- from transformers import AutoConfig
448
- import requests
449
-
450
- result = f"🔍 DIAGNOSTIC DU MODÈLE: {model_name}\n\n"
451
 
452
- # Vérification de l'existence
453
- try:
454
- config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
455
- result += "✅ Modèle accessible\n"
456
-
457
- # Informations sur la configuration
458
- result += f"📋 Type de modèle: {getattr(config, 'model_type', 'Non défini')}\n"
459
- result += f"🏗️ Architecture: {getattr(config, 'architectures', ['Inconnue'])}\n"
460
- result += f"📚 Vocabulaire: {getattr(config, 'vocab_size', 'Inconnu')}\n"
461
- result += f"🧠 Couches cachées: {getattr(config, 'hidden_size', 'Inconnu')}\n"
462
- result += f"🔢 Nombre de couches: {getattr(config, 'num_hidden_layers', 'Inconnu')}\n"
463
-
464
- # Recommandations
465
- if not hasattr(config, 'model_type') or config.model_type is None:
466
- result += "\n⚠️ PROBLÈME: model_type manquant\n"
467
- result += "💡 SOLUTION: Le chargeur essaiera de détecter automatiquement\n"
468
-
469
- if hasattr(config, 'architectures') and config.architectures:
470
- arch = config.architectures[0].lower()
471
- if 'llama' in arch:
472
- result += "🎯 Type détecté: LLaMA\n"
473
- elif 'mistral' in arch:
474
- result += "🎯 Type détecté: Mistral\n"
475
- elif 'qwen' in arch:
476
- result += "🎯 Type détecté: Qwen\n"
477
- elif 'phi' in arch:
478
- result += "🎯 Type détecté: Phi\n"
479
-
480
- result += "\n✅ Chargement possible avec les stratégies multiples"
481
-
482
- except Exception as e:
483
- result += f"❌ Erreur d'accès: {str(e)}\n"
484
- result += "💡 Vérifiez que le modèle existe et est public\n"
485
-
486
- return result
487
-
488
- except Exception as e:
489
- return f"❌ Erreur diagnostic: {str(e)}"
490
 
491
  # Initialisation
492
  trainer = MultimodalTrainer()
@@ -497,17 +527,18 @@ def create_interface():
497
 
498
  gr.Markdown("""
499
  # 🔥 Multimodal Training Hub
500
- ### Plateforme d'entraînement de modèles multimodaux
501
 
502
  🤖 Modèles • 📊 Datasets • 🏋️ Training • 🛠️ Outils
503
  """)
504
 
505
  with gr.Tab("🔧 Diagnostic"):
506
- gr.Markdown("### 🩺 Vérification du système")
507
 
508
  with gr.Row():
509
  check_deps_btn = gr.Button("🔍 Vérifier dépendances", variant="primary")
510
  install_core_btn = gr.Button("📦 Installer packages critiques", variant="secondary")
 
511
 
512
  deps_status = gr.Textbox(
513
  label="État des dépendances",
@@ -545,28 +576,41 @@ def create_interface():
545
  lambda: trainer.install_dependencies(["torch", "transformers", "datasets", "accelerate"]),
546
  outputs=install_status
547
  )
 
 
 
 
548
 
549
  with gr.Tab("🤖 Modèle"):
550
  with gr.Row():
551
  with gr.Column():
552
  model_input = gr.Textbox(
553
  label="Nom du modèle HuggingFace",
554
- placeholder="microsoft/DialoGPT-medium",
555
- value="microsoft/DialoGPT-medium"
556
  )
557
  model_type = gr.Dropdown(
558
  label="Type de modèle",
559
  choices=["causal", "base"],
560
  value="causal"
561
  )
562
- load_model_btn = gr.Button("🔄 Charger le modèle", variant="primary")
563
- diagnose_btn = gr.Button("🔍 Diagnostiquer le modèle", variant="secondary")
 
 
 
 
 
 
 
 
 
564
 
565
  with gr.Column():
566
  model_status = gr.Textbox(
567
  label="Status du modèle",
568
  interactive=False,
569
- lines=8
570
  )
571
 
572
  info_btn = gr.Button("ℹ️ Info modèle")
@@ -659,23 +703,4 @@ def create_interface():
659
 
660
  with gr.Column():
661
  training_status = gr.Textbox(
662
- label="Status de l'entraînement",
663
- interactive=False,
664
- lines=12
665
- )
666
-
667
- train_btn.click(
668
- trainer.simulate_training,
669
- inputs=[output_dir, num_epochs, learning_rate, batch_size],
670
- outputs=training_status
671
- )
672
-
673
- # Auto-check au démarrage
674
- app.load(trainer.check_dependencies, outputs=deps_status)
675
-
676
- return app
677
-
678
- # Lancement
679
- if __name__ == "__main__":
680
- app = create_interface()
681
- app.launch(share=True, server_name="0.0.0.0", server_port=7860)
 
44
  """Vérifie et importe toutes les dépendances"""
45
  global numpy, torch, NUMPY_AVAILABLE, TORCH_AVAILABLE, TRANSFORMERS_AVAILABLE
46
  global DATASETS_AVAILABLE, HF_HUB_AVAILABLE, PIL_AVAILABLE, LIBROSA_AVAILABLE, CV2_AVAILABLE
47
+ global AutoTokenizer, AutoModel, AutoProcessor, AutoModelForCausalLM, AutoConfig
48
  global TrainingArguments, Trainer, DataCollatorForLanguageModeling
49
  global Dataset, load_dataset, concatenate_datasets, HfApi, Image, librosa, cv2
50
 
 
67
  # Transformers
68
  try:
69
  from transformers import (
70
+ AutoTokenizer, AutoModel, AutoProcessor, AutoConfig,
71
  AutoModelForCausalLM, TrainingArguments, Trainer,
72
  DataCollatorForLanguageModeling
73
  )
74
  TRANSFORMERS_AVAILABLE = True
75
  except ImportError:
76
  TRANSFORMERS_AVAILABLE = False
77
+ AutoTokenizer = AutoModel = AutoProcessor = AutoConfig = None
78
  AutoModelForCausalLM = TrainingArguments = Trainer = None
79
  DataCollatorForLanguageModeling = None
80
 
 
144
  """Installe les dépendances manquantes"""
145
  installation_results = []
146
 
147
+ # Mapping des packages avec versions spécifiques
148
  package_mapping = {
149
+ "torch": "torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cpu",
150
+ "transformers": "transformers>=4.46.2",
151
+ "datasets": "datasets>=2.21.0",
152
+ "accelerate": "accelerate>=1.1.0",
153
+ "pillow": "pillow>=10.1.0",
154
+ "librosa": "librosa>=0.10.1",
155
+ "opencv": "opencv-python-headless>=4.8.1.78",
156
+ "huggingface_hub": "huggingface_hub>=0.26.0",
157
+ "qwen": "qwen-vl-utils>=0.0.8"
158
  }
159
 
160
  for package in packages_to_install:
 
168
  try:
169
  subprocess.check_call([
170
  sys.executable, "-m", "pip", "install",
171
+ "torch==2.1.0", "torchvision==0.16.0", "torchaudio==2.1.0",
172
  "--index-url", "https://download.pytorch.org/whl/cpu",
173
  "--quiet"
174
  ])
 
231
  status += f"🚀 GPU: {torch.cuda.get_device_name()}\n"
232
  status += f"🔋 VRAM: {torch.cuda.get_device_properties(0).total_memory / 1e9:.1f}GB\n"
233
 
234
+ # Versions spécifiques
235
+ if TRANSFORMERS_AVAILABLE:
236
+ import transformers
237
+ status += f"🤗 Transformers: {transformers.__version__}\n"
238
+
239
  return status
240
 
241
+ def load_model_safe(self, model_name: str):
242
+ """Chargement sécurisé du modèle avec gestion d'erreurs avancée"""
243
  if not TRANSFORMERS_AVAILABLE:
244
+ return "❌ Transformers non installé! Utilisez l'outil d'installation.", None, None
245
 
246
  if not TORCH_AVAILABLE or not torch:
247
+ return "❌ PyTorch non installé! Utilisez l'outil d'installation.", None, None
248
 
 
 
 
249
  try:
250
+ logger.info(f"Chargement sécurisé du modèle: {model_name}")
251
 
252
+ # Étape 1: Vérification de la configuration
253
+ try:
254
+ config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
255
+ logger.info(f"Configuration chargée: {config.model_type}")
256
+ except Exception as e:
257
+ return f"❌ Erreur configuration: {str(e)}", None, None
258
 
259
+ # Étape 2: Chargement du tokenizer
260
+ tokenizer = None
261
+ try:
262
+ tokenizer = AutoTokenizer.from_pretrained(
263
+ model_name,
264
+ trust_remote_code=True,
265
+ use_fast=False
266
+ )
267
+ if tokenizer.pad_token is None:
268
+ tokenizer.pad_token = tokenizer.eos_token
269
+ logger.info("Tokenizer chargé avec succès")
270
+ except Exception as e:
271
+ logger.warning(f"Tokenizer non trouvé: {e}")
272
+ return f"❌ Erreur tokenizer: {str(e)}", None, None
273
+
274
+ # Étape 3: Chargement du modèle avec stratégies multiples
275
+ model = None
276
+ loading_strategies = [
277
+ {
278
+ "name": "AutoModelForCausalLM standard",
279
+ "loader": lambda: AutoModelForCausalLM.from_pretrained(
280
  model_name,
281
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
282
  device_map="auto" if torch.cuda.is_available() else None,
283
+ trust_remote_code=True,
284
+ low_cpu_mem_usage=True
285
  )
286
+ },
287
+ {
288
+ "name": "AutoModelForCausalLM avec config explicite",
289
+ "loader": lambda: AutoModelForCausalLM.from_pretrained(
 
 
 
 
290
  model_name,
291
+ config=config,
292
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
293
  device_map="auto" if torch.cuda.is_available() else None,
294
+ trust_remote_code=True,
295
+ low_cpu_mem_usage=True,
296
+ attn_implementation="eager"
297
  )
298
+ },
299
+ {
300
+ "name": "AutoModel générique",
301
+ "loader": lambda: AutoModel.from_pretrained(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  model_name,
 
303
  torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
304
  device_map="auto" if torch.cuda.is_available() else None,
305
+ trust_remote_code=True,
306
+ low_cpu_mem_usage=True
307
  )
308
+ }
309
+ ]
310
+
311
+ last_error = None
312
+ for strategy in loading_strategies:
313
+ try:
314
+ logger.info(f"Tentative: {strategy['name']}")
315
+ model = strategy["loader"]()
316
+ logger.info(f"✅ Succès avec: {strategy['name']}")
317
+ break
318
  except Exception as e:
319
+ last_error = str(e)
320
+ logger.warning(f"❌ Échec {strategy['name']}: {e}")
321
+ continue
322
 
323
+ if model is None:
324
+ return f"❌ Toutes les stratégies ont échoué. Dernière erreur: {last_error}", None, None
325
 
326
+ # Étape 4: Chargement du processor (optionnel)
327
+ processor = None
328
  try:
329
+ processor = AutoProcessor.from_pretrained(model_name, trust_remote_code=True)
330
+ logger.info("Processor chargé avec succès")
 
 
 
331
  except Exception as e:
332
+ logger.warning(f"Processor non disponible: {e}")
333
+
334
+ return "✅ Modèle chargé avec succès!", model, tokenizer, processor
335
+
336
+ except Exception as e:
337
+ error_msg = f"❌ Erreur critique: {str(e)}"
338
+ logger.error(error_msg)
339
+ return error_msg, None, None
340
+
341
+ def load_model(self, model_name: str, model_type: str = "causal"):
342
+ """Charge un modèle depuis Hugging Face avec gestion d'erreurs améliorée"""
343
+ if not model_name.strip():
344
+ return "❌ Veuillez entrer un nom de modèle"
345
+
346
+ # Utilise la méthode sécurisée
347
+ result = self.load_model_safe(model_name)
348
+
349
+ if len(result) == 4: # Succès
350
+ message, model, tokenizer, processor = result
351
+ self.current_model = model
352
+ self.current_tokenizer = tokenizer
353
+ self.current_processor = processor
354
+
355
+ # Informations détaillées
356
+ info = f"{message}\n"
357
+ info += f"🏷️ Type: {type(model).__name__}\n"
358
+ if hasattr(model, 'config'):
359
+ info += f"🏗️ Architecture: {getattr(model.config, 'architectures', ['Inconnue'])[0] if hasattr(model.config, 'architectures') else 'Inconnue'}\n"
360
+ info += f"📋 Model type: {getattr(model.config, 'model_type', 'Non défini')}\n"
361
+
362
+ if TORCH_AVAILABLE and torch:
363
+ info += f"💾 Device: {next(model.parameters()).device}\n"
364
+ total_params = sum(p.numel() for p in model.parameters())
365
+ info += f"🔢 Paramètres: {total_params:,}\n"
366
+
367
+ return info
368
+ else:
369
+ # Erreur
370
+ return result[0]
371
+
372
+ def diagnose_model(self, model_name: str):
373
+ """Diagnostique avancé d'un modèle"""
374
+ if not model_name.strip():
375
+ return "❌ Veuillez entrer un nom de modèle"
376
+
377
+ try:
378
+ result = f"🔍 DIAGNOSTIC APPROFONDI: {model_name}\n\n"
379
+
380
+ # Vérification de l'existence
381
  try:
382
+ config = AutoConfig.from_pretrained(model_name, trust_remote_code=True)
383
+ result += "✅ Modèle accessible sur Hugging Face\n\n"
384
+
385
+ # Analyse de la configuration
386
+ result += "📋 CONFIGURATION:\n"
387
+ result += f"🏷️ Model type: {getattr(config, 'model_type', '❌ NON DÉFINI')}\n"
388
+ result += f"🏗️ Architectures: {getattr(config, 'architectures', ['❌ NON DÉFINI'])}\n"
389
+ result += f"📚 Vocab size: {getattr(config, 'vocab_size', 'Inconnu'):,}\n"
390
+ result += f"🧠 Hidden size: {getattr(config, 'hidden_size', 'Inconnu')}\n"
391
+ result += f"🔢 Layers: {getattr(config, 'num_hidden_layers', 'Inconnu')}\n"
392
+ result += f"🎯 Attention heads: {getattr(config, 'num_attention_heads', 'Inconnu')}\n"
393
+
394
+ # Vérification des problèmes courants
395
+ result += "\n🔧 ANALYSE DES PROBLÈMES:\n"
396
+
397
+ if not hasattr(config, 'model_type') or config.model_type is None:
398
+ result += "⚠️ PROBLÈME: model_type manquant\n"
399
+ if hasattr(config, 'architectures') and config.architectures:
400
+ arch = config.architectures[0].lower()
401
+ suggested_type = None
402
+ if 'qwen' in arch:
403
+ suggested_type = 'qwen2' if 'qwen2' in arch else 'qwen'
404
+ elif 'llama' in arch:
405
+ suggested_type = 'llama'
406
+ elif 'mistral' in arch:
407
+ suggested_type = 'mistral'
408
+ elif 'phi' in arch:
409
+ suggested_type = 'phi'
410
+
411
+ if suggested_type:
412
+ result += f"💡 Type suggéré: {suggested_type}\n"
413
+ else:
414
+ result += f"✅ Model type défini: {config.model_type}\n"
415
+
416
+ # Vérification de la compatibilité avec Transformers
417
+ if hasattr(config, 'architectures') and config.architectures:
418
+ arch = config.architectures[0]
419
+ if 'Qwen2_5OmniForCausalLM' in arch:
420
+ result += "⚠️ Architecture Qwen2.5-Omni détectée\n"
421
+ result += "💡 Nécessite Transformers >= 4.45.0\n"
422
+ if TRANSFORMERS_AVAILABLE:
423
+ import transformers
424
+ current_version = transformers.__version__
425
+ result += f"📦 Version actuelle: {current_version}\n"
426
+
427
+ # Stratégies de chargement recommandées
428
+ result += "\n🎯 STRATÉGIES DE CHARGEMENT:\n"
429
+ result += "1️⃣ AutoModelForCausalLM avec trust_remote_code=True\n"
430
+ result += "2️⃣ Configuration explicite si model_type manquant\n"
431
+ result += "3️⃣ Fallback vers AutoModel générique\n"
432
+
433
+ result += "\n✅ Diagnostic terminé - Chargement possible avec adaptations"
434
+
435
  except Exception as e:
436
+ result += f" Erreur d'accès: {str(e)}\n"
437
 
438
+ # Suggestions basées sur l'erreur
439
+ if "404" in str(e):
440
+ result += "💡 Le modèle n'existe pas ou n'est pas public\n"
441
+ elif "token" in str(e).lower():
442
+ result += "💡 Un token d'authentification pourrait être nécessaire\n"
443
+ else:
444
+ result += "💡 Vérifiez le nom du modèle et votre connexion\n"
445
+
446
+ return result
447
 
448
  except Exception as e:
449
+ return f"❌ Erreur diagnostic: {str(e)}"
 
 
450
 
451
  def load_single_dataset(self, dataset_name: str, split: str = "train"):
452
  """Charge un dataset individuel"""
 
515
  info += f"\n📊 DONNÉES:\n"
516
  info += f"📈 Exemples: {len(self.training_data):,}\n"
517
  info += f"📝 Colonnes: {list(self.training_data.column_names)}\n"
 
 
 
 
 
 
 
 
 
 
 
518
 
519
+ return info
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
 
521
  # Initialisation
522
  trainer = MultimodalTrainer()
 
527
 
528
  gr.Markdown("""
529
  # 🔥 Multimodal Training Hub
530
+ ### Plateforme d'entraînement de modèles multimodaux optimisée pour Qwen2.5-Omni
531
 
532
  🤖 Modèles • 📊 Datasets • 🏋️ Training • 🛠️ Outils
533
  """)
534
 
535
  with gr.Tab("🔧 Diagnostic"):
536
+ gr.Markdown("### 🩺 Vérification du système et installation")
537
 
538
  with gr.Row():
539
  check_deps_btn = gr.Button("🔍 Vérifier dépendances", variant="primary")
540
  install_core_btn = gr.Button("📦 Installer packages critiques", variant="secondary")
541
+ install_qwen_btn = gr.Button("🎯 Support Qwen2.5", variant="secondary")
542
 
543
  deps_status = gr.Textbox(
544
  label="État des dépendances",
 
576
  lambda: trainer.install_dependencies(["torch", "transformers", "datasets", "accelerate"]),
577
  outputs=install_status
578
  )
579
+ install_qwen_btn.click(
580
+ lambda: trainer.install_dependencies(["transformers", "qwen"]),
581
+ outputs=install_status
582
+ )
583
 
584
  with gr.Tab("🤖 Modèle"):
585
  with gr.Row():
586
  with gr.Column():
587
  model_input = gr.Textbox(
588
  label="Nom du modèle HuggingFace",
589
+ placeholder="kvn420/Tenro_V4.1",
590
+ value="kvn420/Tenro_V4.1"
591
  )
592
  model_type = gr.Dropdown(
593
  label="Type de modèle",
594
  choices=["causal", "base"],
595
  value="causal"
596
  )
597
+
598
+ with gr.Row():
599
+ load_model_btn = gr.Button("🔄 Charger le modèle", variant="primary")
600
+ diagnose_btn = gr.Button("🔍 Diagnostiquer", variant="secondary")
601
+
602
+ gr.Markdown("""
603
+ 💡 **Modèles testés:**
604
+ - `kvn420/Tenro_V4.1` (Qwen2.5-Omni)
605
+ - `Qwen/Qwen2.5-7B-Instruct`
606
+ - `microsoft/DialoGPT-medium`
607
+ """)
608
 
609
  with gr.Column():
610
  model_status = gr.Textbox(
611
  label="Status du modèle",
612
  interactive=False,
613
+ lines=10
614
  )
615
 
616
  info_btn = gr.Button("ℹ️ Info modèle")
 
703
 
704
  with gr.Column():
705
  training_status = gr.Textbox(
706
+ label="Status