{"record":{"id":"323c427719c1c0a5","repo":"lllyasviel/Fooocus","slug":"error-invalid-scheduler","errorCode":null,"errorMessage":"error invalid scheduler","messagePattern":"error invalid scheduler","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"modules/sample_hijack.py","lineNumber":183,"sourceCode":"    if scheduler_name == \"karras\":\n        sigmas = k_diffusion_sampling.get_sigmas_karras(n=steps, sigma_min=float(model.model_sampling.sigma_min), sigma_max=float(model.model_sampling.sigma_max))\n    elif scheduler_name == \"exponential\":\n        sigmas = k_diffusion_sampling.get_sigmas_exponential(n=steps, sigma_min=float(model.model_sampling.sigma_min), sigma_max=float(model.model_sampling.sigma_max))\n    elif scheduler_name == \"normal\":\n        sigmas = normal_scheduler(model, steps)\n    elif scheduler_name == \"simple\":\n        sigmas = simple_scheduler(model, steps)\n    elif scheduler_name == \"ddim_uniform\":\n        sigmas = ddim_scheduler(model, steps)\n    elif scheduler_name == \"sgm_uniform\":\n        sigmas = normal_scheduler(model, steps, sgm=True)\n    elif scheduler_name == \"turbo\":\n        sigmas = SDTurboScheduler().get_sigmas(model=model, steps=steps, denoise=1.0)[0]\n    elif scheduler_name == \"align_your_steps\":\n        model_type = 'SDXL' if isinstance(model.latent_format, ldm_patched.modules.latent_formats.SDXL) else 'SD1'\n        sigmas = AlignYourStepsScheduler().get_sigmas(model_type=model_type, steps=steps, denoise=1.0)[0]\n    else:\n        raise TypeError(\"error invalid scheduler\")\n    return sigmas\n\n\nldm_patched.modules.samplers.calculate_sigmas_scheduler = calculate_sigmas_scheduler_hacked\nldm_patched.modules.samplers.sample = sample_hacked\n","sourceCodeStart":165,"sourceCodeEnd":189,"githubUrl":"https://github.com/lllyasviel/Fooocus/blob/ae05379cc97bc4361ec8b4ec90193dab21be763f/modules/sample_hijack.py#L165-L189","documentation":"Raised by calculate_sigmas_scheduler_hacked() in modules/sample_hijack.py:164-184, Fooocus's replacement for ldm_patched.modules.samplers.calculate_sigmas_scheduler. The function is a hand-maintained if/elif dispatch that only recognizes eight scheduler names: 'karras', 'exponential', 'normal', 'simple', 'ddim_uniform', 'sgm_uniform', 'turbo', and 'align_your_steps'. Any other string falls through to `raise TypeError(\"error invalid scheduler\")`. Note the mismatch risk: the UI dropdown is populated from modules/flags.py's scheduler_list = SCHEDULER_NAMES, which comes from the vendored ldm_patched package and may list more schedulers (e.g. 'beta', 'linear_quadratic') than this hacked dispatch implements, so a name can be selectable in the UI yet still crash here.","triggerScenarios":"process_diffusion(..., scheduler_name=...) in modules/default_pipeline.py calls calculate_sigmas -> calculate_sigmas_scheduler (the hacked one) with a scheduler string outside the eight supported names. This happens when: the UI dropdown offers a scheduler from SCHEDULER_NAMES that the fork's dispatch never implemented; a modified/hand-edited config.txt sets default_scheduler to an unsupported value (the config validator only checks membership in flags.scheduler_list, not in the hacked dispatch); metadata import (modules/meta_parser.py reading A1111/Civitai 'Scheduler' fields) or API-driven calls pass a scheduler string like 'beta', 'edm_playground_v2.5' pre-normalization, 'lcm' without the async_worker remap, or a typo/empty string.","commonSituations":"Upgrading ldm_patched (ComfyUI backend) adds SCHEDULER_NAMES entries without updating Fooocus's hacked dispatch; hand-editing mod user files or presets to try a new scheduler; loading a preset/metadata JSON produced on a newer Fooocus fork; calling the pipeline programmatically with a scheduler name copied from ComfyUI docs; passing 'lcm' or 'tcd' directly (these are valid in the dropdown but must be remapped to 'sgm_uniform' by patch_samplers() in modules/async_worker.py:774-790 before reaching this function).","solutions":["Set the scheduler in the UI/config to one of the eight implemented names: karras, exponential, normal, simple, ddim_uniform, sgm_uniform, turbo, or align_your_steps (edit config.txt's default_scheduler if the error appears at startup or generation).","If you need 'lcm' or 'tcd': keep the UI value but confirm you are going through the normal task pipeline, since modules/async_worker.py remaps them to 'sgm_uniform' and patches ModelSamplingDiscrete; bypassing that remap (direct core/default_pipeline calls) triggers this error.","If the failing name appears in the UI dropdown (e.g. 'beta' from a newer SCHEDULER_NAMES), either downgrade/re-sync ldm_patched to the vendored version, or extend calculate_sigmas_scheduler_hacked with the missing branch (e.g. beta_scheduler) before filing an issue.","When importing parameters from metadata (A1111/Civitai PNG info), override the Scheduler field instead of accepting it verbatim — imported strings are not validated against the hacked dispatch.","For programmatic callers, validate the scheduler string against an explicit allowlist (see defense) before invoking the pipeline."],"exampleFix":"# before: name from newer SCHEDULER_NAMES reaches the hacked dispatch\nsigmas = calculate_sigmas_scheduler(model, scheduler_name, steps)  # scheduler_name='beta' -> TypeError\n\n# after (option A - caller-side allowlist):\nFOOOCUS_SCHEDULERS = {'karras', 'exponential', 'normal', 'simple',\n                      'ddim_uniform', 'sgm_uniform', 'turbo', 'align_your_steps'}\nscheduler_name = scheduler_name if scheduler_name in FOOOCUS_SCHEDULERS else 'karras'\nsigmas = calculate_sigmas_scheduler(model, scheduler_name, steps)\n\n# after (option B - add the branch in modules/sample_hijack.py):\n# from ldm_patched.modules.samplers import beta_scheduler\n#     elif scheduler_name == \"beta\":\n#         sigmas = beta_scheduler(model, steps)","handlingStrategy":"validation","validationCode":"FOOOCUS_SCHEDULERS = ('karras', 'exponential', 'normal', 'simple',\n                      'ddim_uniform', 'sgm_uniform', 'turbo', 'align_your_steps')\n\n# modules/sample_hijack.py dispatch-compatible check, run BEFORE the pipeline call\ndef assert_scheduler_supported(scheduler_name):\n    if scheduler_name not in FOOOCUS_SCHEDULERS:\n        raise ValueError(\n            f'Unsupported scheduler {scheduler_name!r}; '\n            f'expected one of {FOOOCUS_SCHEDULERS}')\n\n# optional: auto-normalize instead of failing\ndef normalize_scheduler(name, default='karras'):\n    name = (name or '').strip().lower().replace('-', '_')\n    return name if name in FOOOCUS_SCHEDULERS else default","typeGuard":"from typing import Any\n\nSUPPORTED_SCHEDULERS = frozenset(\n    ('karras', 'exponential', 'normal', 'simple',\n     'ddim_uniform', 'sgm_uniform', 'turbo', 'align_your_steps'))\n\ndef is_supported_scheduler(value: Any) -> bool:\n    \"\"\"True when value reaches a branch in sample_hijack.calculate_sigmas_scheduler_hacked.\"\"\"\n    return isinstance(value, str) and value in SUPPORTED_SCHEDULERS","tryCatchPattern":"try:\n    sigmas = calculate_sigmas_scheduler(model, scheduler_name, steps)\nexcept TypeError as e:\n    if 'invalid scheduler' in str(e):\n        # fall back to Fooocus's default rather than aborting the whole job\n        sigmas = calculate_sigmas_scheduler(model, 'karras', steps)\n    else:\n        raise","preventionTips":["Treat the scheduler as a closed enum of the eight names implemented in modules/sample_hijack.py:164-184, not whatever the UI dropdown lists.","Never hand-edit default_scheduler in config.txt to a name you have not seen in a shipped preset; the config validator checks flags.scheduler_list, which can diverge from the hacked dispatch.","When copying parameters from ComfyUI or A1111 metadata, map scheduler names explicitly ('lcm'/'tcd' must go through async_worker's remap to 'sgm_uniform').","After upgrading the vendored ldm_patched package, diff SCHEDULER_NAMES against the if/elif chain in sample_hijack.py — new names are select-crash candidates."],"tags":["fooocus","scheduler","validation","enum","pipeline","typeerror"],"backgroundTag":null,"analyzedSha":"ae05379cc97bc4361ec8b4ec90193dab21be763f","analyzedAt":"2026-08-15T04:23:59.533Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}