LykosAI/StabilityMatrix · error · InvalidOperationException

Flux.2 VAE model not found

Error message

Flux.2 VAE model not found

What it means

SelectModels in Flux2KleinModelManager requires a locally installed Flux.2 VAE (a file matching IsFlux2Vae). If clientManager.VaeModels has no entry with a Local file matching that predicate, it throws this InvalidOperationException because the Klein pipeline cannot decode images without the VAE.

Solutions

  1. Download the Flux.2 VAE (e.g. ae.safetensors for Flux.2) into the VAE folder and refresh the index
  2. Rename the file so IsFlux2Vae matches, or move it to the directory the client manager scans
  3. Catch InvalidOperationException and direct the user to a one-click VAE download

Example fix

// before
var models = flux2KleinModelManager.SelectModels();
// after
if (!clientManager.VaeModels.Any(m => m.Local != null && IsFlux2Vae(m.FileName)))
{
    await DownloadFlux2VaeAsync(); // ensure ae.safetensors exists locally
}
var models = flux2KleinModelManager.SelectModels();
Defensive patterns

Strategy: validation

Validate before calling

var vae = clientManager.VaeModels.FirstOrDefault(m => m.Local != null && IsFlux2Vae(m.FileName));
if (vae is null) throw new UserDownloadableError("Flux.2 VAE is not installed; download ae.safetensors first.");

Type guard

bool HasLocalFlux2Vae(IEnumerable<HybridModelFile> models) => models.Any(m => m.Local != null && IsFlux2Vae(m.FileName));

Try / catch

try
{
    var models = flux2KleinModelManager.SelectModels();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Flux.2 VAE model not found"))
{
    // trigger VAE download flow
}

Prevention

When it happens

Trigger: Calling SelectModels while no VaeModels entry has Local != null and a filename matching IsFlux2Vae — e.g. ae.safetensors / Flux2 VAE never downloaded or placed in a folder ComfyUI doesn't index.

Common situations: User installs the UNET and text encoder but skips the VAE; VAE downloaded under a non-matching filename or into the wrong directory; stale model index after moving files.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of LykosAI/StabilityMatrix@af93d6ef57 (2026-09-12). Data as JSON: /api/errors/783e4a2b950aeb34. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Avalonia/Services/Flux2KleinModelManager.cs:168

    /// <summary>
    /// Select the best available models for Flux.2 Klein (only LOCAL models).
    /// When the selected UNET is the 9B variant, prefers the matching qwen_3_8b text encoder;
    /// when 4B, prefers qwen_3_4b. Falls back to whichever encoder is present.
    /// </summary>
    internal SelectedModels SelectModels(
        IInferenceClientManager clientManager,
        HybridModelFile? preferredUnet = null
    )
    {
        var unetModel =
            preferredUnet
            ?? clientManager.UnetModels.FirstOrDefault(m => m.Local != null && IsKleinUnet(m.FileName))
            ?? throw new InvalidOperationException("Flux.2 Klein UNET model not found");

        var vaeModel =
            clientManager.VaeModels.FirstOrDefault(m => m.Local != null && IsFlux2Vae(m.FileName))
            ?? throw new InvalidOperationException("Flux.2 VAE model not found");

        // Match the text encoder to the selected UNET variant. The 4B UNET expects
        // qwen_3_4b (~4B params, hidden_dim 2560) and the 9B UNET expects qwen_3_8b
        // (~8B params, hidden_dim 4096) — pairing the wrong size produces a tensor
        // shape mismatch deep inside the sampler, so we fail fast here with a clear
        // message rather than silently substituting the other size.
        var preferredEncoderSize = GetExpectedEncoderSize(unetModel);

        var clipModel =
            clientManager.ClipModels.FirstOrDefault(m =>
                m.Local != null
                && IsKleinTextEncoder(m.FileName)
                && MatchesEncoderSize(m.FileName, preferredEncoderSize)
            )
            ?? throw new InvalidOperationException(
                preferredEncoderSize == "8b"
                    ? "Klein 9B requires the qwen_3_8b text encoder, which isn't installed. Download qwen_3_8b_fp8mixed.safetensors (or _fp4mixed / _bf16) from huggingface.co/Comfy-Org/flux2-klein-9B and place it in your TextEncoders folder."
                    : "Klein 4B requires the qwen_3_4b text encoder, which isn't installed. Download qwen_3_4b.safetensors (or _fp4_flux2) from huggingface.co/Comfy-Org/flux2-klein-4B and place it in your TextEncoders folder."

View on GitHub (pinned to af93d6ef57)