{"record":{"id":"ba8deff6714ebb7d","repo":"LykosAI/StabilityMatrix","slug":"flux-2-klein-unet-model-not-found","errorCode":null,"errorMessage":"Flux.2 Klein UNET model not found","messagePattern":"Flux\\.2 Klein UNET model not found","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"StabilityMatrix.Avalonia/Services/Flux2KleinModelManager.cs","lineNumber":164,"sourceCode":"            ?? clientManager.UnetModels.FirstOrDefault(m => m.Local != null && IsKleinUnet(m.FileName));\n\n        return unet != null ? GetExpectedEncoderSize(unet) : \"4b\";\n    }\n\n    /// <summary>\n    /// Select the best available models for Flux.2 Klein (only LOCAL models).\n    /// When the selected UNET is the 9B variant, prefers the matching qwen_3_8b text encoder;\n    /// when 4B, prefers qwen_3_4b. Falls back to whichever encoder is present.\n    /// </summary>\n    internal SelectedModels SelectModels(\n        IInferenceClientManager clientManager,\n        HybridModelFile? preferredUnet = null\n    )\n    {\n        var unetModel =\n            preferredUnet\n            ?? clientManager.UnetModels.FirstOrDefault(m => m.Local != null && IsKleinUnet(m.FileName))\n            ?? throw new InvalidOperationException(\"Flux.2 Klein UNET model not found\");\n\n        var vaeModel =\n            clientManager.VaeModels.FirstOrDefault(m => m.Local != null && IsFlux2Vae(m.FileName))\n            ?? throw new InvalidOperationException(\"Flux.2 VAE model not found\");\n\n        // Match the text encoder to the selected UNET variant. The 4B UNET expects\n        // qwen_3_4b (~4B params, hidden_dim 2560) and the 9B UNET expects qwen_3_8b\n        // (~8B params, hidden_dim 4096) — pairing the wrong size produces a tensor\n        // shape mismatch deep inside the sampler, so we fail fast here with a clear\n        // message rather than silently substituting the other size.\n        var preferredEncoderSize = GetExpectedEncoderSize(unetModel);\n\n        var clipModel =\n            clientManager.ClipModels.FirstOrDefault(m =>\n                m.Local != null\n                && IsKleinTextEncoder(m.FileName)\n                && MatchesEncoderSize(m.FileName, preferredEncoderSize)\n            )","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/LykosAI/StabilityMatrix/blob/af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002/StabilityMatrix.Avalonia/Services/Flux2KleinModelManager.cs#L146-L182","documentation":"Flux2KleinModelManager.SelectModels must locate a locally installed Flux.2 Klein UNET among the ComfyUI client's known models. If no model with a Local file matching IsKleinUnet exists (and no preferredUnet was supplied), it throws this InvalidOperationException because a Klein workflow cannot be built without the UNET.","triggerScenarios":"Calling SelectModels (directly or via selectedModels) with no preferredUnet while clientManager.UnetModels contains no entry with Local != null whose FileName matches IsKleinUnet — i.e. the Klein UNET checkpoint was never downloaded or is registered without a local file.","commonSituations":"User selects the Flux.2 Klein workflow before downloading the UNET; model downloaded into the wrong folder so it isn't indexed as local; stale ComfyUI model index where the remote entry exists but Local is null.","solutions":["Download a Flux.2 Klein UNET safetensors into the ComfyUI models folder and refresh the model index","Pass an explicit preferredUnet (HybridModelFile with Local set) to SelectModels","Catch InvalidOperationException and prompt the user to install the missing UNET before launching the workflow"],"exampleFix":"// before\nvar models = flux2KleinModelManager.SelectModels();\n// after\nif (!clientManager.UnetModels.Any(m => m.Local != null && IsKleinUnet(m.FileName)))\n{\n    throw new UserDownloadableError(\"Flux.2 Klein UNET is not installed. Download it before running this workflow.\");\n}\nvar models = flux2KleinModelManager.SelectModels();","handlingStrategy":"validation","validationCode":"var unet = clientManager.UnetModels.FirstOrDefault(m => m.Local != null && IsKleinUnet(m.FileName));\nif (unet is null) throw new UserDownloadableError(\"Flux.2 Klein UNET is not installed; download it before running.\");","typeGuard":"bool HasLocalKleinUnet(IEnumerable<HybridModelFile> models) => models.Any(m => m.Local != null && IsKleinUnet(m.FileName));","tryCatchPattern":"try\n{\n    var models = flux2KleinModelManager.SelectModels();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Klein UNET model not found\"))\n{\n    // trigger UNET download flow\n}","preventionTips":["Check model presence (Local != null) before invoking SelectModels","Auto-download required models when the Klein workflow is selected","Refresh the ComfyUI model index after file moves"],"tags":["comfyui","models","flux"],"backgroundTag":"resource-not-found","analyzedSha":"af93d6ef57c01cd890d7e0ad0a9ea8c9fcda3002","analyzedAt":"2026-09-12T19:02:43.389Z","contentChangedAt":"2026-09-12T19:02:43.389Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}