Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions docs/flux3-image-klein-q5km.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@ specify a separate **Qwen3-VL-4B-Instruct text encoder** and **FLUX.2 VAE**.
1. Diffusion GGUF: **existing**, no copy or automatic download:
`$HOME/.lmstudio/models/unsloth/flux-3-image-klein-GGUF/flux-3-image-klein-Q5_K_M.gguf`
(Unsloth Q5_K_M; approximately 4.22 decimal GB).
2. Text encoder: `unsloth/Qwen3-VL-4B-Instruct-GGUF`,
`Qwen3-VL-4B-Instruct-Q4_K_M.gguf`, managed target
`~/.local-llm/models/flux-3-image-klein-gguf-q5km/text_encoder/Qwen3-VL-4B-Instruct-Q4_K_M.gguf`.
Registry revision `cc8371d67a57fc6ae05fc5a9c2df763914928539`.
3. VAE: `unsloth/flux-3-image-klein`, `ae.safetensors`, managed target
`~/.local-llm/models/flux-3-image-klein-gguf-q5km/vae/ae.safetensors`.
**Its upstream SHA256/revision are not yet locked**, so do not treat this
provisional source entry as immutable-provenance evidence.
2. Text encoder: [`Qwen/Qwen3-VL-4B-Instruct-GGUF`](https://huggingface.co/Qwen/Qwen3-VL-4B-Instruct-GGUF/blob/bdc46888d3da9c4578c765ca9eb9f5a385a64e6c/Qwen3VL-4B-Instruct-Q4_K_M.gguf),
`Qwen3VL-4B-Instruct-Q4_K_M.gguf` (~2.5 GB), managed target
`~/.local-llm/models/flux-3-image-klein-gguf-q5km/text_encoder/Qwen3VL-4B-Instruct-Q4_K_M.gguf`.
Pinned revision `bdc46888d3da9c4578c765ca9eb9f5a385a64e6c`,
SHA256 `66358cb18bb6b3b1b6675aa412c7a88ef01d228f481184d13668e5201c730a0a`.
3. FLUX.2 VAE: [`Comfy-Org/Flux-2-Dev`](https://huggingface.co/Comfy-Org/Flux-2-Dev/blob/ab9055628ea245000e610f2aa2c96f4746093546/split_files/vae/flux2-vae.safetensors),
upstream file `split_files/vae/flux2-vae.safetensors` (~336 MB), managed target
`~/.local-llm/models/flux-3-image-klein-gguf-q5km/vae/flux2-vae.safetensors`.
Pinned revision `ab9055628ea245000e610f2aa2c96f4746093546`,
SHA256 `d64f3a68e1cc4f9f4e29b6e0da38a0204fe9a49f2d4053f0ec1fa1ca02f9c4b5`.
This is a FLUX.2 VAE, **not** the Qwen Image VAE. Byte-for-byte equivalence
with the gated BFL `ae.safetensors` has **not** been established.

Both auxiliary components must be present to start image inference. The
registry path is resolved relative to **the current user's home**, not a
Expand All @@ -36,14 +40,15 @@ this is *not yet full artifact integrity verification*.
```bash
cd ~/Projects/experiments/korgis
git fetch origin
git switch feat/flux3-klein-q5km-lmstudio-20261119
git switch main
git pull --ff-only

# Check the local transformer is present; no model inference runs here.
ls -lh "$HOME/.lmstudio/models/unsloth/flux-3-image-klein-GGUF/flux-3-image-klein-Q5_K_M.gguf"

# First run: Korgis may download the separate 4B encoder and VAE to its
# own managed bundle. It never re-downloads the existing LM Studio GGUF.
# First run: Korgis downloads the pinned 4B encoder and FLUX.2 VAE when absent,
# or verifies existing copies by SHA256. It never copies/downloads the LM Studio GGUF.
# No symlink is needed: model_sources.py resolves the GGUF directly from LM Studio.
uv run --frozen local-llm serve \
--model flux-3-image-klein-gguf-q5km \
--host 127.0.0.1 --port 1235 \
Expand All @@ -52,9 +57,9 @@ uv run --frozen local-llm serve \

For a strictly offline run *after* the two auxiliary artifacts exist, add
`--no-download` to the command. If they are not installed, the error will
show the exact missing managed path. Source repository downloads could be
gated or unavailable; use an approved Hugging Face client to fetch those two
files explicitly if Korgis cannot obtain them. The pinned native
show the exact missing managed path. Both pinned sources are publicly listed on Hugging Face. If a download fails,
obtain each file from the verified source and place it at its managed target path.
A checksum mismatch must be fixed; never bypass integrity verification. The pinned native
stable-diffusion.cpp build must include FLUX.3 (upstream support introduced
October 2026). A filename or revision alone does not establish binary support.

Expand Down Expand Up @@ -88,8 +93,8 @@ not a benchmarked peak or a license to turn off host protections.

## Experiments comparison

Check out Experiments branch
`feat/imagegen-flux3-klein-q5km-20261119`. In the Image Generation
Use Experiments `main` (the `korgis` submodule points at the merged image
runtime). In the Image Generation
Playground select **FLUX.3 Image Klein GGUF Q5_K_M**, or pick it as an
additional arm in **Compare models**. To generate a FLUX vs Gemini vs GPT
comparison, start FLUX in Korgis and configure server-side cloud API keys.
Expand All @@ -110,9 +115,11 @@ so prompt-upsampled BFL service examples are not identical to this setup.
- [x] Registered distinct model and 16-step preset, without altering Qwen
- [x] Deterministic path resolution and local-only GGUF startup checks
- [x] Separate encoder/VAE dependencies, per-model metadata and benchmark arm
- [ ] CI test verification and complete native Mac startup
- [x] Previous Korgis integration CI on main passed; bundle update requires fresh CI
- [ ] Complete native Mac startup with the corrected pinned bundle
- [ ] 512px generation at seed 43 with correct 16-step sampling
- [ ] Measured RSS, unified-memory pressure, swap and runtime latency
- [ ] Validate outputs at 768/1024 before quality comparisons
- [ ] Lock the upstream VAE revision/checksum and local GGUF digest
- [x] Lock the encoder and Comfy-Org FLUX.2 VAE revisions and published SHA256
- [ ] Record the local LM Studio GGUF digest and validate Comfy-Org VAE compatibility with a native image
- [ ] Validate native image editing separately; it is not enabled by this PR
19 changes: 11 additions & 8 deletions src/local_llm_server/models_registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,15 +428,17 @@ models:
lmstudio_relative_path: "unsloth/flux-3-image-klein-GGUF/flux-3-image-klein-Q5_K_M.gguf"
lmstudio_required: true
text_encoder:
repo: "unsloth/Qwen3-VL-4B-Instruct-GGUF"
revision: "cc8371d67a57fc6ae05fc5a9c2df763914928539"
filename: "Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
local_path: "text_encoder/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
repo: "Qwen/Qwen3-VL-4B-Instruct-GGUF"
revision: "bdc46888d3da9c4578c765ca9eb9f5a385a64e6c"
filename: "Qwen3VL-4B-Instruct-Q4_K_M.gguf"
local_path: "text_encoder/Qwen3VL-4B-Instruct-Q4_K_M.gguf"
sha256: "66358cb18bb6b3b1b6675aa412c7a88ef01d228f481184d13668e5201c730a0a"
vae:
repo: "unsloth/flux-3-image-klein"
revision: main # lock to a verified commit/checksum before general release
filename: "ae.safetensors"
local_path: "vae/ae.safetensors"
repo: "Comfy-Org/Flux-2-Dev"
revision: "ab9055628ea245000e610f2aa2c96f4746093546"
filename: "split_files/vae/flux2-vae.safetensors"
local_path: "vae/flux2-vae.safetensors"
sha256: "d64f3a68e1cc4f9f4e29b6e0da38a0204fe9a49f2d4053f0ec1fa1ca02f9c4b5"
params:
# Provisional disk-backed envelope; requires real macOS RSS/unified
# memory and swap evidence before this estimate can be calibrated.
Expand All @@ -450,6 +452,7 @@ models:
image_max_pixels: 1048576
image_guidance_scale: 1.0
image_sampling_method: euler
image_verify_existing_artifacts: true
image_output_format: png
image_diffusion_flash_attention: true
image_offload_to_cpu: true
Expand Down
47 changes: 42 additions & 5 deletions tests/test_flux3_klein_local_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import pytest

from local_llm_server.config import build_config
from local_llm_server.model_sources import resolve_bundle_artifacts
from local_llm_server.model_sources import artifact_download_url, resolve_bundle_artifacts
from local_llm_server.registry import load_registry
from local_llm_server.stable_diffusion_cpp_compat import build_sd_server_command
from local_llm_server.stable_diffusion_cpp_image_engine import StableDiffusionCppImageEngine

Expand Down Expand Up @@ -37,9 +38,9 @@ def test_flux3_registry_reuses_local_gguf_without_copy_or_download(
assert cfg["model_source"] == "lmstudio"
assert Path(cfg["model_artifacts"]["diffusion_model"]) == local.resolve()
assert cfg["model_artifacts"]["text_encoder"].endswith(
"text_encoder/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
"text_encoder/Qwen3VL-4B-Instruct-Q4_K_M.gguf"
)
assert cfg["model_artifacts"]["vae"].endswith("vae/ae.safetensors")
assert cfg["model_artifacts"]["vae"].endswith("vae/flux2-vae.safetensors")
assert cfg["model_downloaded"] is False # two auxiliary files are missing
assert cfg["image_num_inference_steps"] == 16
assert cfg["image_max_inference_steps"] == 16
Expand Down Expand Up @@ -101,9 +102,9 @@ def test_flux3_native_command_has_three_matching_components_and_no_qwen_projecto
"flux-3-image-klein-Q5_K_M.gguf"
)
assert command[command.index("--llm") + 1].endswith(
"Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
"Qwen3VL-4B-Instruct-Q4_K_M.gguf"
)
assert command[command.index("--vae") + 1].endswith("ae.safetensors")
assert command[command.index("--vae") + 1].endswith("flux2-vae.safetensors")
assert "--llm_vision" not in command
assert "--disable-prefetch" in command
assert "diffusion=disk,te=cpu,vae=cpu" in command
Expand All @@ -127,3 +128,39 @@ def test_bundle_lmstudio_path_cannot_escape_user_model_root(
spec["artifacts"]["diffusion_model"]["lmstudio_relative_path"] = "/etc/passwd"
with pytest.raises(ValueError, match="must be relative"):
resolve_bundle_artifacts("unsafe", spec, tmp_path / "managed")


def test_flux3_auxiliary_artifacts_are_pinned_to_public_matching_weights() -> None:
entry = load_registry()["models"][FLUX]
artifacts = entry["artifacts"]
encoder = artifacts["text_encoder"]
vae = artifacts["vae"]

assert entry["params"]["image_verify_existing_artifacts"] is True
assert (encoder["repo"], encoder["revision"], encoder["filename"]) == (
"Qwen/Qwen3-VL-4B-Instruct-GGUF",
"bdc46888d3da9c4578c765ca9eb9f5a385a64e6c",
"Qwen3VL-4B-Instruct-Q4_K_M.gguf",
)
assert encoder["sha256"] == (
"66358cb18bb6b3b1b6675aa412c7a88ef01d228f481184d13668e5201c730a0a"
)
assert (vae["repo"], vae["revision"], vae["filename"]) == (
"Comfy-Org/Flux-2-Dev",
"ab9055628ea245000e610f2aa2c96f4746093546",
"split_files/vae/flux2-vae.safetensors",
)
assert vae["sha256"] == (
"d64f3a68e1cc4f9f4e29b6e0da38a0204fe9a49f2d4053f0ec1fa1ca02f9c4b5"
)
assert encoder["local_path"] == "text_encoder/Qwen3VL-4B-Instruct-Q4_K_M.gguf"
assert vae["local_path"] == "vae/flux2-vae.safetensors"
assert artifacts["diffusion_model"]["lmstudio_required"] is True
assert artifacts["diffusion_model"]["lmstudio_relative_path"].endswith(
"flux-3-image-klein-Q5_K_M.gguf"
)
for component in (encoder, vae):
assert artifact_download_url(component) == (
f"https://huggingface.co/{component['repo']}/resolve/"
f"{component['revision']}/{component['filename']}?download=true"
)
Loading