LykosAI/StabilityMatrix · error · InvalidOperationException

Flux VAE model not found

Error message

Flux VAE model not found

What it means

SelectModels in FluxKontextModelManager requires the Flux autoencoder (ae.safetensors) to be locally installed among VaeModels. Without it the workflow cannot encode/decode latents, so it throws this InvalidOperationException.

Solutions

  1. Download ae.safetensors (Flux VAE) into the VAE folder and refresh the model index
  2. Rename the existing VAE file to exactly ae.safetensors (name match is exact, not substring)
  3. Catch InvalidOperationException and trigger an in-app VAE download

Example fix

// before
var models = fluxKontextModelManager.SelectModels();
// after
if (!clientManager.VaeModels.Any(m => m.Local != null && m.FileName.Equals("ae.safetensors", StringComparison.OrdinalIgnoreCase)))
{
    await sharedFolders.DownloadModelAsync(FluxVaeUri, SharedFolderType.Vae); // ae.safetensors
}
var models = fluxKontextModelManager.SelectModels();
Defensive patterns

Strategy: validation

Validate before calling

var vae = clientManager.VaeModels.FirstOrDefault(m => m.Local != null
    && m.FileName.Equals("ae.safetensors", StringComparison.OrdinalIgnoreCase));
if (vae is null) throw new UserDownloadableError("Flux VAE ae.safetensors is not installed.");

Type guard

bool HasFluxVae(IEnumerable<HybridModelFile> models) => models.Any(m => m.Local != null && m.FileName.Equals("ae.safetensors", StringComparison.OrdinalIgnoreCase));

Try / catch

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

Prevention

When it happens

Trigger: Calling SelectModels when no VaeModels entry has Local != null and a filename exactly equal (case-insensitive) to 'ae.safetensors'.

Common situations: User downloads the Kontext UNET but not the shared Flux ae.safetensors VAE; the VAE file was renamed (e.g. ae_flux1.safetensors) so the exact-name match fails; files moved outside the scanned VAE directory.

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/98f0a87eaf441315. Report an issue: GitHub.

Appendix: source

Thrown at StabilityMatrix.Avalonia/Services/FluxKontextModelManager.cs:178

    /// <summary>
    /// Select the best available models for Flux Kontext (only selects LOCAL models)
    /// </summary>
    internal FluxKontextWorkflowBuilder.SelectedModels SelectModels(IInferenceClientManager clientManager)
    {
        var unetModel =
            clientManager.UnetModels.FirstOrDefault(m =>
                m.Local != null
                && (
                    m.FileName.Contains("flux1-dev-kontext", StringComparison.OrdinalIgnoreCase)
                    || m.FileName.Contains("flux-kontext", StringComparison.OrdinalIgnoreCase)
                )
            ) ?? throw new InvalidOperationException("Flux Kontext UNET model not found");

        var vaeModel =
            clientManager.VaeModels.FirstOrDefault(m =>
                m.Local != null && m.FileName.Equals("ae.safetensors", StringComparison.OrdinalIgnoreCase)
            ) ?? throw new InvalidOperationException("Flux VAE model not found");

        var clip1Model =
            clientManager.ClipModels.FirstOrDefault(m =>
                m.Local != null && m.FileName.Contains("clip_l", StringComparison.OrdinalIgnoreCase)
            ) ?? throw new InvalidOperationException("CLIP-L model not found");

        var clip2Model =
            clientManager.ClipModels.FirstOrDefault(m =>
                m.Local != null
                && (
                    m.FileName.Contains("t5xxl", StringComparison.OrdinalIgnoreCase)
                    || m.FileName.Contains("t5-xxl", StringComparison.OrdinalIgnoreCase)
                )
            ) ?? throw new InvalidOperationException("T5-XXL model not found");

        return new FluxKontextWorkflowBuilder.SelectedModels(unetModel, vaeModel, clip1Model, clip2Model);
    }
}

View on GitHub (pinned to af93d6ef57)