KINETIC / scripts /setup_bitnet_light.ps1
AshrafGalibSk's picture
Publish Kinetic modular VLA stack (source, no weights)
9019b27 verified
Raw
History Blame Contribute Delete
4.63 kB
# Setup lightweight BitNet for Kinetic (local repo: F:\Kinetic\BitNet)
# Prefer smallest instruct model: Falcon-E-1B-Instruct (1B, 1.58-bit)
#
# Usage (from repo root, VS2022 Developer PowerShell recommended on Windows):
# powershell -ExecutionPolicy Bypass -File scripts\setup_bitnet_light.ps1
# powershell -File scripts\setup_bitnet_light.ps1 -Model Falcon1B
# powershell -File scripts\setup_bitnet_light.ps1 -Model BitNet2B -SkipBuild
param(
# BitNetLarge (~0.7B) is lightest with pretuned x86 kernels in-repo
[ValidateSet("BitNetLarge", "Falcon1B", "BitNet2B")]
[string]$Model = "BitNetLarge",
[switch]$SkipBuild,
[switch]$SkipDownload,
[string]$BitNetRoot = "F:\Kinetic\BitNet"
)
$ErrorActionPreference = "Stop"
if (-not (Test-Path $BitNetRoot)) {
Write-Error "BitNet not found at $BitNetRoot"
}
Set-Location $BitNetRoot
Write-Host "==> BitNet root: $BitNetRoot" -ForegroundColor Cyan
# Map light models → HF repos used by setup_env.py
$hfMap = @{
"Falcon1B" = "tiiuae/Falcon-E-1B-Instruct"
"BitNetLarge" = "1bitLLM/bitnet_b1_58-large" # ~0.7B
"BitNet2B" = "microsoft/BitNet-b1.58-2B-4T"
}
$hf = $hfMap[$Model]
Write-Host "==> Lightweight model choice: $Model ($hf)" -ForegroundColor Cyan
# Submodules (llama.cpp)
Write-Host "==> git submodule update --init --recursive" -ForegroundColor Cyan
git submodule update --init --recursive
if ($LASTEXITCODE -ne 0) { Write-Error "submodule update failed" }
# Python deps (minimal for convert + download)
Write-Host "==> pip install huggingface_hub gguf deps" -ForegroundColor Cyan
python -m pip install -q huggingface_hub
if (Test-Path "3rdparty\llama.cpp\gguf-py") {
python -m pip install -q "3rdparty\llama.cpp\gguf-py"
}
# Prefer MinGW clang build (no VS ClangCL) — see scripts/build_bitnet_mingw.ps1
if (-not $SkipBuild) {
Write-Host "==> MinGW/clang build (build_bitnet_mingw.ps1)" -ForegroundColor Cyan
& "$PSScriptRoot\build_bitnet_mingw.ps1" -BitNetRoot $BitNetRoot
if ($LASTEXITCODE -ne 0) { Write-Error "build failed" }
}
if (-not $SkipDownload) {
Write-Host "==> Download + convert light model: $hf" -ForegroundColor Cyan
$name = switch ($Model) {
"Falcon1B" { "Falcon-E-1B-Instruct" }
"BitNetLarge" { "bitnet_b1_58-large" }
"BitNet2B" { "BitNet-b1.58-2B-4T" }
}
$dest = Join-Path "models" $name
New-Item -ItemType Directory -Force -Path $dest | Out-Null
python -c "from huggingface_hub import snapshot_download; snapshot_download('$hf', local_dir=r'$dest'); print('ok')"
$i2s = Join-Path $dest "ggml-model-i2_s.gguf"
if (-not (Test-Path $i2s)) {
python -m pip install -q safetensors
python utils/convert-hf-to-gguf-bitnet.py $dest --outtype f32
$f32 = Join-Path $dest "ggml-model-f32.gguf"
$quant = Join-Path $BitNetRoot "build\bin\llama-quantize.exe"
if (-not (Test-Path $quant)) { $quant = Join-Path $BitNetRoot "build\bin\Release\llama-quantize.exe" }
& $quant $f32 $i2s I2_S 1
}
}
# Resolve GGUF for Kinetic config
$ggufs = Get-ChildItem -Path models -Recurse -Filter "*.gguf" -ErrorAction SilentlyContinue |
Sort-Object Length
if ($ggufs) {
$best = $ggufs | Select-Object -First 1
# Prefer i2_s if present
$i2 = $ggufs | Where-Object { $_.Name -like "*i2_s*" } | Select-Object -First 1
if ($i2) { $best = $i2 }
Write-Host "==> GGUF: $($best.FullName) ($([math]::Round($best.Length/1MB,1)) MB)" -ForegroundColor Green
$env:KINETIC_BITNET_REPO = $BitNetRoot
$env:KINETIC_BITNET_MODEL = $best.FullName
Write-Host "Set for this session:" -ForegroundColor Green
Write-Host " `$env:KINETIC_BITNET_REPO = '$BitNetRoot'"
Write-Host " `$env:KINETIC_BITNET_MODEL = '$($best.FullName)'"
} else {
Write-Host "==> No GGUF found yet under models/" -ForegroundColor Yellow
}
# Patch Kinetic bitnet.yaml model_path if GGUF exists
$cfg = "F:\Kinetic\configs\bitnet.yaml"
if ((Test-Path $cfg) -and $ggufs) {
Write-Host "==> Update configs/bitnet.yaml model_path" -ForegroundColor Cyan
$posix = ($best.FullName -replace "\\", "/")
$text = Get-Content $cfg -Raw
$text = $text -replace "model_path:.*", "model_path: $posix"
Set-Content -Path $cfg -Value $text -NoNewline
}
Write-Host ""
Write-Host "Next:" -ForegroundColor Cyan
Write-Host " cd F:\Kinetic"
Write-Host " python -m kinetic.cli bitnet-info --config configs/bitnet.yaml"
Write-Host " python -m kinetic.cli reason -i `"Pick up the bottle`" --config configs/bitnet.yaml --json"
Write-Host " python -m kinetic.demos.pick_bottle --config configs/bitnet.yaml"