mudler/LocalAI · warning

Invalid sample method, using default: %s\n

Error message

Invalid sample method, using default: %s\n

What it means

Warning during generation setup: the sampler string did not match any sample method in str_to_sample_method(), so sd_get_default_sample_method(sd_ctx) picks the model's default sampler. Generation proceeds; results may differ from the requested sampler (quality/speed characteristics change).

Source

Thrown at backend/go/stablediffusion-ggml/cpp/gosd.cpp:690

    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);
    if (sched != SCHEDULER_COUNT) {
        scheduler = sched;
        fprintf(stderr, "Found scheduler: %s\n", scheduler_str);
    }
    if (scheduler == SCHEDULER_COUNT) {
        scheduler = sd_get_default_scheduler(sd_ctx, sample_method);
        fprintf(stderr, "Invalid scheduler, using default: %s\n", sd_scheduler_name(scheduler));
    }

    sd_c = sd_ctx;

    return 0;
}

View on GitHub (pinned to 44413a9d06)

Solutions

  1. Use a sampler name exactly as the vendored str_to_sample_method expects (e.g. euler_a, dpm++2m)
  2. Or omit the sampler to deliberately take the model default
  3. Confirm the fix via the 'Found sampler:' log line

Example fix

// before
sampler = "Euler a";  // not matched

// after
sampler = "euler_a";
Defensive patterns

Strategy: validation

Validate before calling

// Go caller: whitelist samplers before the request reaches the backend
validSamplers := map[string]bool{"euler_a": true, "euler": true, "heun": true, "dpm2": true, "dpm++2m": true, "lcm": true}
if req.Sampler != "" && !validSamplers[req.Sampler] {
    return fmt.Errorf("unknown sampler %q", req.Sampler)
}

Prevention

When it happens

Trigger: Passing sampler='euler_a'-style names with the wrong spelling/case for this build, or a sampler name introduced in a newer stable-diffusion.cpp than the vendored one.

Common situations: API requests or model configs copied from other UIs (A1111/ComfyUI) whose sampler names differ (e.g. 'Euler a' vs 'euler_a'); version drift of sampler enums.

Related errors


AI-assisted analysis of mudler/LocalAI@44413a9d06 (2026-08-15). Data as JSON: /api/errors/d17957f9e66ff233. Report an issue: GitHub.