mudler/LocalAI · critical
failed loading model (generic error)\n
Error message
failed loading model (generic error)\n
What it means
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.
Source
Thrown at backend/go/stablediffusion-ggml/cpp/gosd.cpp:676
ctx_params.diffusion_flash_attn = diffusion_flash_attn;
ctx_params.tae_preview_only = tae_preview_only;
ctx_params.diffusion_conv_direct = diffusion_conv_direct;
ctx_params.vae_conv_direct = vae_conv_direct;
ctx_params.force_sdxl_vae_conv_scale = force_sdxl_vae_conv_scale;
// Chroma knobs: upstream dropped the dedicated chroma_use_dit_mask /
// chroma_use_t5_mask / chroma_t5_mask_pad struct fields and now reads them
// from the generic model_args key=value spec (parse_key_value_args). Emit
// them there so the existing chroma options keep working. This string must
// outlive new_sd_ctx() below.
std::string model_args_spec =
"chroma_use_dit_mask=" + std::string(chroma_use_dit_mask ? "true" : "false") +
",chroma_use_t5_mask=" + std::string(chroma_use_t5_mask ? "true" : "false") +
",chroma_t5_mask_pad=" + std::to_string(chroma_t5_mask_pad);
ctx_params.model_args = model_args_spec.c_str();
sd_ctx_t* sd_ctx = new_sd_ctx(&ctx_params);
if (sd_ctx == NULL) {
fprintf (stderr, "failed loading model (generic error)\n");
// TODO: Clean up allocated memory
return 1;
}
fprintf (stderr, "Created context: OK\n");
int sample_method_found = -1;
sample_method_t sm = str_to_sample_method(sampler);
if (sm != SAMPLE_METHOD_COUNT) {
sample_method_found = (int)sm;
fprintf(stderr, "Found sampler: %s\n", sampler);
}
if (sample_method_found == -1) {
sample_method_found = sd_get_default_sample_method(sd_ctx);
fprintf(stderr, "Invalid sample method, using default: %s\n", sd_sample_method_name((sample_method_t)sample_method_found));
}
sample_method = (sample_method_t)sample_method_found;
scheduler_t sched = str_to_scheduler(scheduler_str);View on GitHub (pinned to 44413a9d06)
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)
Example fix
# before: model file missing options: "model=/models/sdxl.safetensors,vae=/models/vae.safetensors" # -> failed loading model (generic error) # after: verify paths exist ls -la /models/sdxl.safetensors /models/vae.safetensors options: "model=/models/sdxl.safetensors,vae=/models/vae.safetensors"
Defensive patterns
Strategy: validation
Validate before calling
// Go caller: verify every configured model file before calling load
paths := []string{opts.Model, opts.Vae, opts.Taesd, opts.ControlNet}
for _, p := range paths {
if p == "" { continue }
if fi, err := os.Stat(p); err != nil || fi.Size() == 0 {
return fmt.Errorf("model file %q missing or empty", p)
}
}
// rough memory pre-check: weights ~ file size * (1..2)
if m := opts.ExpectedWeightMemoryGB; m > 0 && memAvailableGB() < m {
return fmt.Errorf("insufficient memory: need ~%dGB", m)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [acestep-cpp] FATAL: failed to load condition encoder\n
- Failed to allocate memory for resized image\n
- model snapshot does not exist: {model_ref}
- model snapshot must contain exactly one {suffix} file; found
- model_id is required to load a pipeline
AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15).
Data as JSON: /api/errors/704521cd57074cd2.
Report an issue: GitHub.