File size: 5,828 Bytes
2072243
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# setup_env.ps1 β€” FusionNet Python virtual environment setup (Windows)
# Creates a venv, upgrades pip, and installs all dependencies.
# Run this ONCE before any other script.
#
# Usage (run from repo root in PowerShell):
#   .\scripts\setup_env.ps1             # CPU-only (any machine)
#   .\scripts\setup_env.ps1 -Backend cuda  # NVIDIA GPU (CUDA 12.8)
#   .\scripts\setup_env.ps1 -Backend rocm  # AMD GPU (ROCm via WSL2)
#
# If you get an execution policy error, run first:
#   Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

param(
    [ValidateSet("cpu", "cuda", "rocm")]
    [string]$Backend = "cpu"
)

$ErrorActionPreference = "Stop"

Write-Host "==================================================" -ForegroundColor Cyan
Write-Host "  FusionNet - Environment Setup (Windows)         " -ForegroundColor Cyan
Write-Host "  Backend: $($Backend.ToUpper())                  " -ForegroundColor Cyan
Write-Host "==================================================" -ForegroundColor Cyan

$repoRoot = Split-Path -Parent $PSScriptRoot
$venvPath = Join-Path $repoRoot "venv"

# ── 1. Check Python ───────────────────────────────────────────────────────────
if (-not (Get-Command python -ErrorAction SilentlyContinue)) {
    Write-Error @"

Python 3.10+ not found.

Download from: https://www.python.org/downloads/

Make sure to check 'Add Python to PATH' during installation.

"@
    exit 1
}
$pyVer = python --version
Write-Host "`n[1/5] Python found: $pyVer" -ForegroundColor Green

# ── 2. Create virtual environment ─────────────────────────────────────────────
if (Test-Path $venvPath) {
    Write-Host "`n[2/5] venv already exists at: $venvPath (skipping creation)" -ForegroundColor Yellow
} else {
    Write-Host "`n[2/5] Creating virtual environment at: $venvPath" -ForegroundColor Yellow
    python -m venv $venvPath
    Write-Host "      venv created." -ForegroundColor Green
}

# ── 3. Activate venv ──────────────────────────────────────────────────────────
$activateScript = Join-Path $venvPath "Scripts\Activate.ps1"
Write-Host "`n[3/5] Activating venv..." -ForegroundColor Yellow
& $activateScript
Write-Host "      venv active." -ForegroundColor Green

# ── 4. Upgrade pip + install PyTorch backend ──────────────────────────────────
Write-Host "`n[4/5] Installing PyTorch ($($Backend.ToUpper()) build)..." -ForegroundColor Yellow
python -m pip install --upgrade pip

switch ($Backend) {
    "cuda" {
        # CUDA 12.8 β€” RTX 30xx/40xx/50xx (driver >= 560)
        pip install torch==2.11.0+cu128 torchvision==0.26.0+cu128 torchaudio==2.11.0+cu128 `
            --index-url https://download.pytorch.org/whl/cu128
    }
    "rocm" {
        # PyTorch ROCm wheels are Linux-only.
        # On Windows, install CPU wheel. For GPU, use WSL2 + setup_rocm.sh.
        Write-Host "  NOTE: PyTorch ROCm wheels are Linux-only." -ForegroundColor Yellow
        Write-Host "  Installing CPU build. For AMD GPU acceleration use WSL2." -ForegroundColor Yellow
        pip install torch torchvision torchaudio
    }
    default {
        # Plain CPU build β€” works on any Windows PC
        pip install torch torchvision torchaudio
    }
}

# ── 5. Install project dependencies ──────────────────────────────────────────
Write-Host "`n[5/5] Installing FusionNet dependencies..." -ForegroundColor Yellow
pip install -r (Join-Path $repoRoot "requirements.txt")
pip install -r (Join-Path $repoRoot "fusionnet-client\requirements.txt")

# ── Verification ──────────────────────────────────────────────────────────────
Write-Host "`n--------------------------------------------------" -ForegroundColor Cyan
Write-Host "  Verification" -ForegroundColor Cyan
Write-Host "--------------------------------------------------" -ForegroundColor Cyan

python -c @"

import sys, torch

is_rocm = getattr(torch.version, 'hip', None) is not None

backend = 'ROCm' if is_rocm else ('CUDA' if torch.cuda.is_available() else 'CPU')

print(f'Python   : {sys.version.split()[0]}')

print(f'PyTorch  : {torch.__version__}')

print(f'Backend  : {backend}')

if torch.cuda.is_available():

    p = torch.cuda.get_device_properties(0)

    print(f'GPU      : {p.name} ({p.total_memory/1024**3:.1f} GB)')

else:

    import psutil

    ram = psutil.virtual_memory().total / 1024**3

    print(f'RAM      : {ram:.1f} GB (CPU mode)')

"@

Write-Host "`n==================================================" -ForegroundColor Green
Write-Host "  Setup complete! Next steps:" -ForegroundColor Green
Write-Host "==================================================" -ForegroundColor Green
Write-Host ""
Write-Host "  Activate venv in future sessions:" -ForegroundColor White
Write-Host "    .\venv\Scripts\Activate.ps1" -ForegroundColor Cyan
Write-Host ""
Write-Host "  Run the client node:" -ForegroundColor White
Write-Host "    cd fusionnet-client" -ForegroundColor Cyan
Write-Host "    python main.py --client-id 0 --num-clients 4" -ForegroundColor Cyan
Write-Host ""
Write-Host "  Launch a full FL round:" -ForegroundColor White
Write-Host "    .\scripts\launch_fl_round.ps1 -NumClients 4" -ForegroundColor Cyan