{"record":{"id":"4b2723378757f191","repo":"mudler/LocalAI","slug":"invalid-scheduler-k-if-is-karras-else-nam","errorCode":null,"errorMessage":"Invalid scheduler '{'k_' if is_karras else ''}{name}'","messagePattern":"Invalid scheduler '(.+?)(.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/python/diffusers/backend.py","lineNumber":211,"sourceCode":"        # Equivalent to DPM2 in K-Diffusion\n        sched_class = KDPM2DiscreteScheduler\n    elif name == DiffusionScheduler.dpm_2_a:\n        # Equivalent to `DPM2 a`` in K-Diffusion\n        sched_class = KDPM2AncestralDiscreteScheduler\n    elif name == DiffusionScheduler.dpmpp_2m:\n        # Equivalent to `DPM++ 2M` in K-Diffusion\n        sched_class = DPMSolverMultistepScheduler\n        config[\"algorithm_type\"] = \"dpmsolver++\"\n        config[\"solver_order\"] = 2\n    elif name == DiffusionScheduler.dpmpp_sde:\n        # Equivalent to `DPM++ SDE` in K-Diffusion\n        sched_class = DPMSolverSinglestepScheduler\n    elif name == DiffusionScheduler.dpmpp_2m_sde:\n        # Equivalent to `DPM++ 2M SDE` in K-Diffusion\n        sched_class = DPMSolverMultistepScheduler\n        config[\"algorithm_type\"] = \"sde-dpmsolver++\"\n    else:\n        raise ValueError(f\"Invalid scheduler '{'k_' if is_karras else ''}{name}'\")\n\n    return sched_class.from_config(config)\n\n\n# Implement the BackendServicer class with the service methods\nclass BackendServicer(backend_pb2_grpc.BackendServicer):\n\n    def _load_pipeline(self, request, model_ref, from_single_file, local_only, torchType, variant, device_map=None):\n        \"\"\"\n        Load a diffusers pipeline dynamically using the dynamic loader.\n\n        This method uses load_diffusers_pipeline() for most pipelines, falling back\n        to explicit handling only for pipelines requiring custom initialization\n        (e.g., quantization, special VAE handling).\n\n        Args:\n            request: The gRPC request containing pipeline configuration\n            model_ref: Repository ID or local model file/directory","sourceCodeStart":193,"sourceCodeEnd":229,"githubUrl":"https://github.com/mudler/LocalAI/blob/44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26/backend/python/diffusers/backend.py#L193-L229","documentation":"Raised by the diffusers backend's scheduler factory when the requested scheduler name does not match any branch of the if/elif chain mapping DiffusionScheduler enum values to diffusers scheduler classes. The message echoes the name with a 'k_' prefix when K-Diffusion Karras scheduling was requested.","triggerScenarios":"Requesting a scheduler value that the backend's mapping table does not cover — e.g. a newly added or experimental DiffusionScheduler member, or a raw string scheduler name passed through from the request that is not in the enum branches.","commonSituations":"Version mismatch: the request (or a newer LocalAI frontend) uses a scheduler name this backend build predates; a typo in the scheduler field of the request; or a K-Diffusion scheduler name (e.g. 'k_dpmpp_2m') passed where the diffusers backend expects the non-Karras enum spelling.","solutions":["Use one of the supported scheduler names visible in the if/elif chain (e.g. dpmpp_2m, dpmpp_sde, dpmpp_2m_sde and the other branches above line 211).","Update the backend image/repo so newly mapped schedulers are available.","Check the exact enum value being sent — log request.Scheduler before the mapping; compare against the DiffusionScheduler enum definition.","If a Karras variant was intended, verify the correct base name is passed and the is_karras flag is set rather than baking 'k_' into the name."],"exampleFix":"# before\nrequest.Scheduler = \"dpm++_2m_karras\"  # typo / raw KD name\n\n# after\nrequest.Scheduler = \"dpmpp_2m\"  # matches DiffusionScheduler.dpmpp_2m branch","handlingStrategy":"validation","validationCode":"valid_schedulers = {s.value for s in DiffusionScheduler}\nassert request.Scheduler in valid_schedulers, f\"unsupported scheduler {request.Scheduler!r}\"","typeGuard":"def is_supported_scheduler(name: str) -> bool:\n    return name in {s.value for s in DiffusionScheduler}","tryCatchPattern":"try:\n    scheduler = build_scheduler(name, is_karras)\nexcept ValueError as e:\n    return error_reply(f\"{e}; supported: {sorted(s.value for s in DiffusionScheduler)}\")","preventionTips":["Expose the DiffusionScheduler enum values in the API/UI so users pick from valid names.","Keep backend and frontend versions aligned when new schedulers are added.","Reject unknown scheduler names at request validation, not deep in the factory."],"tags":["diffusers","scheduler","validation","image-generation"],"backgroundTag":null,"analyzedSha":"44413a9d06bf5bc52ce088ba8ca74e5a2e8bee26","analyzedAt":"2026-08-15T10:13:50.291Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}