{"record":{"id":"532e58d55ba90137","repo":"unslothai/unsloth","slug":"unsupported-diffusion-memory-mode-value-use-o","errorCode":null,"errorMessage":"Unsupported diffusion memory_mode '{value}'. Use one of: {valid}.","messagePattern":"Unsupported diffusion memory_mode '(.+?)'\\. Use one of: (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":400,"severity":"error","filePath":"studio/backend/core/inference/diffusion_memory.py","lineNumber":66,"sourceCode":"DEFAULT_GROUP_BLOCKS = 1\n\nDEFAULT_IMAGE_WIDTH = 1024\nDEFAULT_IMAGE_HEIGHT = 1024\n# Flat allowance for fixed pipeline costs (scheduler, embeddings, CUDA context, fragmentation).\nDEFAULT_BASE_OVERHEAD_MIB = 2048\n\n\ndef normalize_memory_mode(value: Optional[str]) -> Optional[str]:\n    \"\"\"Lower/strip a requested mode (accepting dashes); None passes through. Raises ValueError\n    for an unsupported mode so the route rejects it as a 4xx before any GPU work.\"\"\"\n    if value is None:\n        return None\n    normalized = str(value).strip().lower().replace(\"-\", \"_\")\n    if not normalized:\n        return None\n    if normalized not in MEMORY_MODES:\n        valid = \", \".join(MEMORY_MODES)\n        raise ValueError(f\"Unsupported diffusion memory_mode '{value}'. Use one of: {valid}.\")\n    return normalized\n\n\n@dataclass(frozen = True)\nclass DeviceMemory:\n    \"\"\"Point-in-time view of the active device's memory, in MiB.\n\n    ``memory_kind`` distinguishes discrete VRAM (CPU offload helps) from unified / system memory\n    (offload moves bytes within the same pool, so it does not).\"\"\"\n\n    backend: str\n    device: str\n    memory_kind: str  # \"discrete_vram\" | \"unified_memory\" | \"system_memory\" | \"unknown\"\n    free_mib: Optional[int] = None\n    total_mib: Optional[int] = None\n\n    @property\n    def is_unified(self) -> bool:","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/inference/diffusion_memory.py#L48-L84","documentation":"normalize_memory_mode validates the user-supplied memory_mode parameter for diffusion loads before any GPU work happens. It lowercases, strips, and converts dashes to underscores, then requires membership in MEMORY_MODES ('auto', 'fast', 'balanced', 'low_vram'). An unknown value raises ValueError so the HTTP route rejects it as 4xx cheaply.","triggerScenarios":"POSTing a diffusion load/generate request with memory_mode like 'lowvram', 'LOW-VRAM', 'medium', or 'high' — anything not normalizing to auto/fast/balanced/low_vram.","commonSituations":"Clients forwarding UI strings that don't match the API vocabulary; version drift where older/newer clients send a mode name this build doesn't know; typo'd config files.","solutions":["Send one of: auto, fast, balanced, low_vram (dashes like 'low-vram' are accepted)","Omit memory_mode entirely to take the default (auto)","Update the client to the mode vocabulary of the deployed backend version"],"exampleFix":"// before\n{\"memory_mode\": \"lowvram\"}\n// after\n{\"memory_mode\": \"low_vram\"}","handlingStrategy":"validation","validationCode":"MODES = {\"auto\", \"fast\", \"balanced\", \"low_vram\"}\n\ndef valid_memory_mode(v: str | None) -> bool:\n    if v is None:\n        return True\n    n = v.strip().lower().replace(\"-\", \"_\")\n    return n == \"\" or n in MODES","typeGuard":"def is_memory_mode(v) -> bool:\n    return v is None or (isinstance(v, str) and (v.strip().lower().replace(\"-\", \"_\") in {\"\", \"auto\", \"fast\", \"balanced\", \"low_vram\"}))","tryCatchPattern":"try:\n        normalize_memory_mode(req.memory_mode)\n    except ValueError as e:\n        return JSONResponse(status_code=400, content={\"detail\": str(e)})","preventionTips":["Validate enum-ish params client-side against the documented mode list","Send snake_case values; the API tolerates dashes but not new names","Version-pin the client and backend vocabulary together"],"tags":["validation","diffusion","memory","api"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}