Download scripts/gpu-kontrol.ps1 from SevdanurGenc/LLM-Automated-Test-Generation-Agent: direct link, hf CLI and curl.
- Browser
- Download file 4.84 kB
-
https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/scripts/gpu-kontrol.ps1
- Command line
-
hf download hf://SevdanurGenc/LLM-Automated-Test-Generation-Agent/scripts/gpu-kontrol.ps1
-
curl -L -o gpu-kontrol.ps1 https://huggingface.co/SevdanurGenc/LLM-Automated-Test-Generation-Agent/resolve/main/scripts/gpu-kontrol.ps1
4.84 kB
| # TestAjani - modelin ekran kartinda (GPU) calisip calismadigini kontrol eder. | |
| # Kullanim: scripts\gpu-kontrol.ps1 [-Model qwen2.5-coder:14b] | |
| # Ne yapar: ekran kartini gosterir, modeli kisa bir istekle yukler, GPU payini ve uretim hizini olcer. | |
| param( | |
| [string]$Model = $(if ($env:OLLAMA_MODEL) { $env:OLLAMA_MODEL } else { "" }) | |
| ) | |
| $ErrorActionPreference = 'Stop' | |
| $Ollama = 'http://localhost:11434' | |
| function Ok($m) { Write-Host " [TAMAM] $m" -ForegroundColor Green } | |
| function Warn($m) { Write-Host " [UYARI] $m" -ForegroundColor Yellow } | |
| function Bad($m) { Write-Host " [SORUN] $m" -ForegroundColor Red } | |
| Write-Host "" | |
| Write-Host "1) Ekran karti" -ForegroundColor Cyan | |
| $hasNvidia = $false | |
| if (Get-Command nvidia-smi -ErrorAction SilentlyContinue) { | |
| $gpu = (nvidia-smi --query-gpu=name,memory.used,memory.total,driver_version --format=csv,noheader) -join "; " | |
| Ok "NVIDIA: $gpu (bellek: kullanilan, toplam MiB; surucu)" | |
| $hasNvidia = $true | |
| } else { | |
| Warn "nvidia-smi bulunamadi. NVIDIA karti yoksa ya da surucu kurulu degilse model CPU'da calisir." | |
| } | |
| Write-Host "" | |
| Write-Host "2) Ollama" -ForegroundColor Cyan | |
| try { $tags = Invoke-RestMethod "$Ollama/api/tags" -TimeoutSec 5 } | |
| catch { | |
| Bad "Bilgisayardaki Ollama'ya ($Ollama) ulasilamadi." | |
| $c = docker ps --format "{{.Names}}" 2>$null | Select-String -Pattern 'ollama' | |
| if ($c) { Warn "Ollama Docker konteynerinde calisiyor. Konteyner Windows'ta GPU'yu genellikle KULLANMAZ: https://ollama.com/download adresinden Ollama'yi Windows'a kurun ve Baslat-Windows.bat'i yeniden calistirin." } | |
| else { Warn "Ollama uygulamasini acin (gorev cubugunda lama simgesi gorunmeli)." } | |
| exit 1 | |
| } | |
| Ok "Ollama calisiyor ($(@($tags.models).Count) model yuklu)" | |
| if (-not $Model) { | |
| $ps = Invoke-RestMethod "$Ollama/api/ps" | |
| $Model = if (@($ps.models).Count) { $ps.models[0].name } elseif (@($tags.models | Where-Object { $_.name -eq 'qwen2.5-coder:14b' }).Count) { 'qwen2.5-coder:14b' } else { $tags.models[0].name } | |
| } | |
| if (-not (@($tags.models | Where-Object { $_.name -eq $Model -or $_.name -eq "$($Model):latest" }).Count)) { | |
| Bad "Model yuklu degil: $Model -> ollama pull $Model"; exit 1 | |
| } | |
| Write-Host "" | |
| Write-Host "3) Model yukleme ve hiz olcumu: $Model" -ForegroundColor Cyan | |
| $body = @{ model = $Model; prompt = 'Write a Python function that returns the sum of a list.'; stream = $false; | |
| options = @{ num_predict = 120; num_ctx = 16384 }; keep_alive = '30m' } | ConvertTo-Json -Depth 4 | |
| $t0 = Get-Date | |
| $r = Invoke-RestMethod "$Ollama/api/generate" -Method Post -ContentType 'application/json' -Body $body -TimeoutSec 900 | |
| $secs = [math]::Round(((Get-Date) - $t0).TotalSeconds, 1) | |
| $tps = if ($r.eval_duration) { [math]::Round($r.eval_count / ($r.eval_duration / 1e9), 1) } else { 0 } | |
| Ok "Yanit alindi ($secs sn, ilk yukleme dahil). Uretim hizi: $tps token/sn" | |
| $ps = Invoke-RestMethod "$Ollama/api/ps" | |
| $m = @($ps.models | Where-Object { $_.name -eq $Model -or $_.name -eq "$($Model):latest" })[0] | |
| $pct = if ($m -and $m.size) { [math]::Round(100 * $m.size_vram / $m.size) } else { 0 } | |
| $vram = if ($m) { [math]::Round($m.size_vram / 1e9, 1) } else { 0 } | |
| $size = if ($m) { [math]::Round($m.size / 1e9, 1) } else { 0 } | |
| Write-Host "" | |
| Write-Host "Sonuc" -ForegroundColor Cyan | |
| if ($pct -ge 100) { | |
| Ok "Model TAMAMEN ekran kartinda: %100 GPU ($vram GB VRAM). Hiz $tps token/sn." | |
| } elseif ($pct -gt 0) { | |
| Warn "Modelin GPU payi yalnizca %$pct ($vram / $size GB); kalani CPU'da. Bu belirgin yavaslatir." | |
| Write-Host " Cozumler: GPU kullanan diger uygulamalari kapatin; baska bir modeli bosaltin (ollama stop <model>);" | |
| Write-Host " daha kucuk model secin (7b) ya da baglam penceresini kucultun (OLLAMA_NUM_CTX=8192)." | |
| } else { | |
| Bad "Model tamamen CPU'da calisiyor (%0 GPU). Hiz $tps token/sn." | |
| if ($hasNvidia) { Write-Host " NVIDIA surucunuzu guncelleyin ve Ollama'yi yeniden baslatin (gorev cubugu > Quit Ollama > yeniden acin)." } | |
| } | |
| Write-Host "" | |
| Write-Host "4) TestAjani uygulamasi" -ForegroundColor Cyan | |
| $want = (Get-Content (Join-Path (Split-Path -Parent $PSScriptRoot) 'VERSION') -ErrorAction SilentlyContinue | Select-Object -First 1) | |
| try { | |
| $h = Invoke-RestMethod 'http://localhost:8000/api/health' -TimeoutSec 30 | |
| if ($h.version -and $h.version -eq $want) { Ok "Uygulama guncel (surum $want)." } | |
| else { Warn "Acik olan uygulama ESKI surum ($(if ($h.version) { $h.version } else { 'bilinmiyor' }); klasordeki: $want). Baslat-Windows.bat'i calistirin - uygulama yeniden derlenir." } | |
| } catch { Warn "Uygulama calismiyor (http://localhost:8000). Baslat-Windows.bat ile baslatin." } | |
| Write-Host "" | |
| Write-Host "Ipucu: Uygulamanin ust cubugundaki GPU gostergesi bu bilgileri gercek zamanli gosterir." -ForegroundColor DarkGray | |