@@ -137,6 +137,41 @@ function Write-ColorOutput {
137137 Add-Content - Path $MainLogFile - Value $FullMessage - ErrorAction SilentlyContinue
138138}
139139
140+ function Get-VllmContainerName {
141+ <#
142+ . SYNOPSIS
143+ Détecte automatiquement le nom du container vLLM medium
144+
145+ . DESCRIPTION
146+ Recherche le container créé par Docker Compose avec le projet "myia_vllm"
147+ et le service "medium". Retourne le nom réel du container.
148+
149+ . OUTPUTS
150+ String - Nom du container (ex: "myia_vllm-medium-qwen3")
151+ #>
152+
153+ # Méthode 1 : Détection via labels Docker Compose (plus fiable)
154+ $containerName = docker ps -- filter " label=com.docker.compose.project=myia_vllm" `
155+ -- filter " label=com.docker.compose.service=medium" `
156+ -- format " {{.Names}}" 2> $null | Select-Object - First 1
157+
158+ if ($containerName ) {
159+ return $containerName
160+ }
161+
162+ # Méthode 2 : Fallback - Recherche par pattern dans le nom
163+ $containerName = docker ps -- filter " name=medium" -- format " {{.Names}}" 2> $null |
164+ Where-Object { $_ -match " medium" } | Select-Object - First 1
165+
166+ if ($containerName ) {
167+ return $containerName
168+ }
169+
170+ # Méthode 3 : Fallback final - Nom hardcodé (basé sur la convention Docker Compose actuelle)
171+ Write-ColorOutput " ⚠️ Impossible de détecter automatiquement le container - Utilisation du nom par défaut" - Level Warning
172+ return " myia_vllm-medium-qwen3"
173+ }
174+
140175function Initialize-Environment {
141176 <#
142177 . SYNOPSIS
@@ -341,7 +376,7 @@ function Update-MediumConfig {
341376 $NewCommandLines += ' --tool-call-parser qwen3_xml'
342377 $NewCommandLines += ' --reasoning-parser qwen3'
343378 $NewCommandLines += ' --distributed-executor-backend=mp'
344- $NewCommandLines += ' --rope_scaling '' {\ "rope_type\":\ "yarn\",\ "factor\ ":4.0,\ "original_max_position_embeddings\ ":32768}'' '
379+ $NewCommandLines += ' --rope_scaling '' {"rope_type": "yarn", "factor":4.0,"original_max_position_embeddings":32768}'' '
345380 $NewCommandLines += ' --swap-space 16'
346381
347382 # enable-prefix-caching (si activé)
@@ -447,15 +482,15 @@ function Deploy-VLLMService {
447482 try {
448483 # Arrêter le service existant
449484 Write-ColorOutput " → Arrêt du service vllm-medium..." - Level Info
450- $DownOutput = docker compose - p myia_vllm -f $MediumYmlPath down -- remove-orphans 2>&1
485+ $DownOutput = docker compose - p myia_vllm -- env - file " $ProjectRoot \.env " - f $MediumYmlPath down -- remove-orphans 2>&1
451486
452487 if ($LASTEXITCODE -ne 0 ) {
453488 throw " Échec de docker compose down : $DownOutput "
454489 }
455490
456491 # Démarrer le nouveau service
457492 Write-ColorOutput " → Démarrage du service avec nouvelle configuration..." - Level Info
458- $UpOutput = docker compose - p myia_vllm -f $MediumYmlPath up - d 2>&1
493+ $UpOutput = docker compose - p myia_vllm -- env - file " $ProjectRoot \.env " - f $MediumYmlPath up - d 2>&1
459494
460495 if ($LASTEXITCODE -ne 0 ) {
461496 $Result.status = " failed"
@@ -477,6 +512,63 @@ function Deploy-VLLMService {
477512 return $Result
478513 }
479514}
515+ function Invoke-CleanupContainers {
516+ <#
517+ . SYNOPSIS
518+ Nettoie TOUS les containers vllm en garantissant qu'aucun orphelin ne subsiste.
519+ . DESCRIPTION
520+ Cette fonction assure un nettoyage complet et robuste des containers Docker,
521+ même en cas d'échec de docker compose down. Utilisée dans le bloc finally
522+ pour garantir un état propre après chaque configuration testée.
523+ #>
524+ param (
525+ [Parameter (Mandatory = $false )]
526+ [string ]$Context = " cleanup"
527+ )
528+
529+ Write-ColorOutput " [$Context ] Nettoyage complet des containers..." - Level Info
530+
531+ if ($DryRun ) {
532+ Write-ColorOutput " [$Context ] [DRY-RUN] Nettoyage simulé" - Level Info
533+ return $true
534+ }
535+
536+ try {
537+ # Étape 1: docker compose down standard
538+ Write-ColorOutput " [$Context ] → docker compose down..." - Level Info
539+ $DownOutput = docker compose - p myia_vllm -- env- file " $ProjectRoot \.env" -f $MediumYmlPath down -- remove-orphans -- volumes 2>&1
540+
541+ # Étape 2: Vérifier qu'aucun container myia_vllm ne subsiste
542+ Write-ColorOutput " [$Context ] → Vérification containers orphelins..." - Level Info
543+ $RemainingContainers = docker ps - a -- filter " name=myia_vllm" -- format " {{.Names}}" 2>&1
544+
545+ if ($RemainingContainers -and $RemainingContainers -match " myia_vllm" ) {
546+ Write-ColorOutput " [$Context ] ⚠️ Containers orphelins détectés - Suppression forcée..." - Level Warning
547+
548+ $ContainerList = $RemainingContainers -split " `n " | Where-Object { $_ -match " myia_vllm" }
549+ foreach ($container in $ContainerList ) {
550+ Write-ColorOutput " [$Context ] → Suppression forcée: $container " - Level Warning
551+ docker rm -f $container 2>&1 | Out-Null
552+ }
553+ }
554+
555+ # Étape 3: Vérification finale
556+ $FinalCheck = docker ps - a -- filter " name=myia_vllm" -- format " {{.Names}}" 2>&1
557+
558+ if ($FinalCheck -and $FinalCheck -match " myia_vllm" ) {
559+ Write-ColorOutput " [$Context ] ✗ ÉCHEC: Des containers subsistent encore!" - Level Error
560+ return $false
561+ }
562+
563+ Write-ColorOutput " [$Context ] ✓ Nettoyage terminé - Aucun container orphelin" - Level Success
564+ return $true
565+ }
566+ catch {
567+ Write-ColorOutput " [$Context ] ✗ Erreur durant le nettoyage: $_ " - Level Error
568+ return $false
569+ }
570+ }
571+
480572
481573function Wait-ContainerHealthy {
482574 <#
@@ -510,7 +602,7 @@ function Wait-ContainerHealthy {
510602 return $Result
511603 }
512604
513- $ContainerName = " vllm-medium "
605+ $ContainerName = Get-VllmContainerName
514606 $StartTime = Get-Date
515607 $TimeoutTime = $StartTime.AddSeconds ($TimeoutSeconds )
516608
@@ -757,9 +849,9 @@ function Parse-KVCacheOutput {
757849
758850 # Patterns pour extraire les métriques
759851 $Patterns = @ {
760- ttft_miss = ' TTFT\s+CACHE\s+MISS.*? (\d+\.?\d*)\s*ms'
761- ttft_hit = ' TTFT\s+CACHE\s+HIT.*? (\d+\.?\d*)\s*ms'
762- acceleration = ' Accélération.*? x\s*(\d+\.?\d*)'
852+ ttft_miss = ' Premier message \(MISS\)\s*:\s* (\d+\.?\d*)\s*ms'
853+ ttft_hit = ' Messages suivants \(HIT\)\s*:\s* (\d+\.?\d*)\s*ms'
854+ acceleration = ' Accélération\s*:\s* x\s*(\d+\.?\d*)'
763855 gain = ' Gain.*?(\d+\.?\d*)\s*%'
764856 }
765857
@@ -1314,6 +1406,25 @@ function Invoke-GridSearchWorkflow {
13141406
13151407 throw
13161408 }
1409+ finally {
1410+ # CLEANUP GARANTI - Exécuté TOUJOURS, même en cas d'erreur ou d'interruption
1411+ Write-ColorOutput " " - Level Info
1412+ Write-ColorOutput " ═══════════════════════════════════════════════════════════════" - Level Info
1413+ Write-ColorOutput " CLEANUP FINAL GARANTI" - Level Info
1414+ Write-ColorOutput " ═══════════════════════════════════════════════════════════════" - Level Info
1415+
1416+ # Nettoyer tous les containers vllm, même orphelins
1417+ $CleanupSuccess = Invoke-CleanupContainers - Context " FINALLY"
1418+
1419+ if (-not $CleanupSuccess ) {
1420+ Write-ColorOutput " ⚠️ ATTENTION: Le cleanup final a rencontré des problèmes" - Level Warning
1421+ Write-ColorOutput " Vérifiez manuellement l'état des containers avec:" - Level Warning
1422+ Write-ColorOutput " docker ps -a --filter 'name=myia_vllm'" - Level Warning
1423+ }
1424+
1425+ Write-ColorOutput " ═══════════════════════════════════════════════════════════════" - Level Info
1426+ Write-ColorOutput " " - Level Info
1427+ }
13171428}
13181429
13191430# =============================================================================
0 commit comments