Files
aigen/scripts/setup-moss-image.ps1
T
TowstyandCursor 354f475866 Add MOSS-Image on the Image v2 path and stop the queue calling it Klein.
The bench queue labeled every engine except Krea, Qwen, MiniMax, and LTX as Klein, and the v2 starter treated any engine other than Krea as Flux.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-22 20:04:58 -05:00

128 lines
4.6 KiB
PowerShell

# Download Comfy-Org MOSS-Image INT8 SFT weights into the Comfy models tree.
# Prefers the single-file repack (not the Diffusers folders).
#
# powershell -ExecutionPolicy Bypass -File scripts\setup-moss-image.ps1
# powershell -File scripts\setup-moss-image.ps1 -SkipDownload
[CmdletBinding()]
param(
[string]$ComfyRoot = '',
[string]$ModelsRoot = '',
[switch]$SkipDownload,
[switch]$Force
)
$ErrorActionPreference = 'Stop'
function Write-Step([string]$Message) {
Write-Host ""
Write-Host "==> $Message" -ForegroundColor Cyan
}
function Write-Ok([string]$Message) {
Write-Host " $Message" -ForegroundColor Green
}
function Resolve-ModelsRoot([string]$Hint) {
$shared = Join-Path $env:LOCALAPPDATA 'Comfy-Desktop\ComfyUI-Shared\models'
$candidates = @(
$Hint,
$env:COMFY_MODELS_ROOT,
$shared
) | Where-Object { $_ } | ForEach-Object { $_.TrimEnd('\', '/') }
foreach ($path in $candidates) {
if (Test-Path $path) { return (Resolve-Path $path).Path }
}
New-Item -ItemType Directory -Force -Path $shared | Out-Null
return (Resolve-Path $shared).Path
}
function Find-HfCli {
foreach ($name in @('hf', 'huggingface-cli')) {
$cmd = Get-Command $name -ErrorAction SilentlyContinue
if ($cmd) { return $cmd.Source }
}
throw "Hugging Face CLI not found (hf / huggingface-cli). Install with: pip install -U huggingface_hub"
}
function Ensure-Dir([string]$Path) {
if (-not (Test-Path $Path)) {
New-Item -ItemType Directory -Force -Path $Path | Out-Null
}
}
function Assert-ModelFile([string]$Path, [long]$MinBytes) {
if (-not (Test-Path $Path)) { throw "Missing model file: $Path" }
$item = Get-Item $Path
if ($item.Length -lt $MinBytes) {
throw "Suspicious size for $Path ($($item.Length) bytes). Expected >= $MinBytes. Delete and re-run."
}
Write-Ok ("{0} {1:N0} bytes" -f $item.FullName, $item.Length)
}
function Invoke-HfFile {
param(
[string]$Cli,
[string]$Repo,
[string]$File,
[string]$ModelsRoot,
[long]$MinBytes
)
$dest = Join-Path $ModelsRoot ($File -replace '/', '\')
Ensure-Dir (Split-Path $dest -Parent)
if ((Test-Path $dest) -and -not $Force -and (Get-Item $dest).Length -ge $MinBytes) {
Write-Ok "Already present: $dest"
return
}
Write-Step "hf download $Repo $File"
# Repo paths are folder/file. local-dir is the models root so the file is not nested again.
& $Cli download $Repo $File --local-dir $ModelsRoot
if ($LASTEXITCODE -ne 0) { throw "hf download failed for $Repo / $File (exit $LASTEXITCODE)" }
if (-not (Test-Path $dest)) { throw "hf download did not write $dest" }
}
Write-Step "Resolve models root"
$models = Resolve-ModelsRoot $ModelsRoot
Write-Ok $models
$diff = Join-Path $models 'diffusion_models'
$te = Join-Path $models 'text_encoders'
$vae = Join-Path $models 'vae'
Ensure-Dir $diff
Ensure-Dir $te
Ensure-Dir $vae
if (-not $SkipDownload) {
$cli = Find-HfCli
Write-Ok "HF CLI: $cli"
Invoke-HfFile -Cli $cli -Repo 'Comfy-Org/MOSS-Image' -File 'diffusion_models/moss_image_sft_int8_convrot.safetensors' -ModelsRoot $models -MinBytes 5000000000
$w4 = Join-Path $te 'qwen3.5_9b_w4a8_gptq.safetensors'
if ((Test-Path $w4) -and -not $Force -and (Get-Item $w4).Length -ge 7000000000) {
Write-Ok "Already present: $w4"
} else {
try {
Invoke-HfFile -Cli $cli -Repo 'Comfy-Org/MOSS-Image' -File 'text_encoders/qwen3.5_9b_w4a8_gptq.safetensors' -ModelsRoot $models -MinBytes 7000000000
} catch {
Write-Host " w4a8 text encoder missing; falling back to int8_convrot" -ForegroundColor Yellow
Invoke-HfFile -Cli $cli -Repo 'Comfy-Org/MOSS-Image' -File 'text_encoders/qwen3.5_9b_int8_convrot.safetensors' -ModelsRoot $models -MinBytes 9000000000
}
}
$vaeSmall = Join-Path $vae 'flux2-vae_small.safetensors'
if ((Test-Path $vaeSmall) -and -not $Force -and (Get-Item $vaeSmall).Length -ge 200000000) {
Write-Ok "Already present: $vaeSmall"
} else {
Invoke-HfFile -Cli $cli -Repo 'Comfy-Org/MOSS-Image' -File 'vae/flux2-vae_small.safetensors' -ModelsRoot $models -MinBytes 200000000
}
}
Write-Step "Verify weights"
Assert-ModelFile (Join-Path $diff 'moss_image_sft_int8_convrot.safetensors') 5000000000
$clip = Join-Path $te 'qwen3.5_9b_w4a8_gptq.safetensors'
if (-not (Test-Path $clip)) { $clip = Join-Path $te 'qwen3.5_9b_int8_convrot.safetensors' }
Assert-ModelFile $clip 7000000000
$vaeFile = Join-Path $vae 'flux2-vae_small.safetensors'
if (-not (Test-Path $vaeFile)) { $vaeFile = Join-Path $vae 'flux2-vae.safetensors' }
Assert-ModelFile $vaeFile 200000000
Write-Host ""
Write-Host "Done. ComfyUI 0.42+ is required for CLIPLoader type moss_image." -ForegroundColor Cyan
Write-Host "ModelsRoot=$models"