#!/usr/bin/env bash
# Kandinsky 6.0 VSR (2-step distilled) x2 on a DGX Spark (GB10, aarch64), as tested for the LEJ Video Lab, Nov 12 2026.
# Standalone, not ComfyUI. Venv: torch 2.11.0+cu130, diffusers 0.42.1,
#   pip install "kandinsky-6-sr @ git+https://github.com/kandinskylab/kandinsky-6-sr"   (we ran commit b15e2aa, v1.1.0)
# Weights: huggingface.co/kandinskylab/Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers (17.5 GB, MIT), downloaded to $BUNDLE.
# One clip per call, at most 5 s (121 frames at 24 fps). Every call loads and compiles again (~2.5 min before the first tile).
# Usage: k6vsr-2x.sh input.mp4 out_dir
set -euo pipefail
IN="$1"; OUT="$2"; BUNDLE="${BUNDLE:-./Kandinsky-6.0-VSR-distilled2steps-5s-Diffusers}"
cat > /tmp/k6sr_x2.yaml <<YAML
sr:
  checkpoint_path: $BUNDLE
  resolution_scale: 2
  device: cuda:0
  vae_backend: torch
  seed: 42
  tiles_batch_size: 1
  decode_spatial_splits: 2   # halves the decoder's peak memory (README); we kept it on for unified memory
YAML
export HF_HUB_OFFLINE=1
# Watch free memory while it runs: on our 832x480 clip the process peaked at 46 GB and free memory fell by 62 GB.
/usr/bin/time -v kandy-sr from-video --input "$IN" --config /tmp/k6sr_x2.yaml --output-dir "$OUT"
