{"record":{"id":"704521cd57074cd2","repo":"mudler/LocalAI","slug":"failed-loading-model-generic-error-n","errorCode":null,"errorMessage":"failed loading model (generic error)\\n","messagePattern":"failed loading model \\(generic error\\)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"backend/go/stablediffusion-ggml/cpp/gosd.cpp","lineNumber":676,"sourceCode":"    ctx_params.diffusion_flash_attn = diffusion_flash_attn;\n    ctx_params.tae_preview_only = tae_preview_only;\n    ctx_params.diffusion_conv_direct = diffusion_conv_direct;\n    ctx_params.vae_conv_direct = vae_conv_direct;\n    ctx_params.force_sdxl_vae_conv_scale = force_sdxl_vae_conv_scale;\n    // Chroma knobs: upstream dropped the dedicated chroma_use_dit_mask /\n    // chroma_use_t5_mask / chroma_t5_mask_pad struct fields and now reads them\n    // from the generic model_args key=value spec (parse_key_value_args). Emit\n    // them there so the existing chroma options keep working. This string must\n    // outlive new_sd_ctx() below.\n    std::string model_args_spec =\n        \"chroma_use_dit_mask=\" + std::string(chroma_use_dit_mask ? \"true\" : \"false\") +\n        \",chroma_use_t5_mask=\" + std::string(chroma_use_t5_mask ? \"true\" : \"false\") +\n        \",chroma_t5_mask_pad=\" + std::to_string(chroma_t5_mask_pad);\n    ctx_params.model_args = model_args_spec.c_str();\n    sd_ctx_t* sd_ctx = new_sd_ctx(&ctx_params);\n\n    if (sd_ctx == NULL) {\n        fprintf (stderr, \"failed loading model (generic error)\\n\");\n        // TODO: Clean up allocated memory\n        return 1;\n    }\n    fprintf (stderr, \"Created context: OK\\n\");\n\n    int sample_method_found = -1;\n    sample_method_t sm = str_to_sample_method(sampler);\n    if (sm != SAMPLE_METHOD_COUNT) {\n        sample_method_found = (int)sm;\n        fprintf(stderr, \"Found sampler: %s\\n\", sampler);\n    }\n    if (sample_method_found == -1) {\n        sample_method_found = sd_get_default_sample_method(sd_ctx);\n        fprintf(stderr, \"Invalid sample method, using default: %s\\n\", sd_sample_method_name((sample_method_t)sample_method_found));\n    }\n    sample_method = (sample_method_t)sample_method_found;\n\n    scheduler_t sched = str_to_scheduler(scheduler_str);","sourceCodeStart":658,"sourceCodeEnd":694,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/go/stablediffusion-ggml/cpp/gosd.cpp#L658-L694","documentation":"Fatal load error: new_sd_ctx() returned NULL, meaning the upstream stable-diffusion.cpp library refused to create a context. The shim prints this generic message (upstream's own, more specific errors appear earlier on stderr) and returns 1, aborting the load. Typical root causes are unreadable/corrupt model files, missing VAE/CLIP components, unsupported architecture, or out-of-memory during weight loading.","triggerScenarios":"Calling load with model_path/vae_path/clip paths that do not exist or are corrupt; passing a Flux/Chroma pipeline missing its diffusion-model or text-encoder components; requesting a quantization that fails on this hardware; exhausting RAM/VRAM while loading weights.","commonSituations":"Wrong path in gallery YAML; partially downloaded .safetensors/.gguf; using a diffusers-only model without converting; small machines loading large fp16 models; missing embeddings_connectors/pulid/control-net files referenced in options.","solutions":["Read the upstream stderr lines immediately above this message — they name the actual failing file or reason","Verify every configured path (model, vae, taesd, control_net, etc.) exists and is a supported format","Check free RAM/VRAM and try a quantized wtype or smaller model","Re-download the model if the file is truncated/corrupt (compare size/checksum with the source)"],"exampleFix":"# before: model file missing\noptions: \"model=/models/sdxl.safetensors,vae=/models/vae.safetensors\"\n# -> failed loading model (generic error)\n\n# after: verify paths exist\nls -la /models/sdxl.safetensors /models/vae.safetensors\noptions: \"model=/models/sdxl.safetensors,vae=/models/vae.safetensors\"","handlingStrategy":"validation","validationCode":"// Go caller: verify every configured model file before calling load\npaths := []string{opts.Model, opts.Vae, opts.Taesd, opts.ControlNet}\nfor _, p := range paths {\n    if p == \"\" { continue }\n    if fi, err := os.Stat(p); err != nil || fi.Size() == 0 {\n        return fmt.Errorf(\"model file %q missing or empty\", p)\n    }\n}\n// rough memory pre-check: weights ~ file size * (1..2)\nif m := opts.ExpectedWeightMemoryGB; m > 0 && memAvailableGB() < m {\n    return fmt.Errorf(\"insufficient memory: need ~%dGB\", m)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stat-check and size-check every model path before load; empty files mean a broken download","Keep the full stderr log — upstream sd.cpp prints the specific failing component above the generic message","Validate downloaded weights against published checksums/sizes","Load one large model at a time and free previous contexts first"],"tags":["stablediffusion","model-loading","fatal","memory"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}