{"record":{"id":"689da82f963d8a08","repo":"unslothai/unsloth","slug":"cfg-dropout-must-be-a-number-got-self-cfg-dropou","errorCode":null,"errorMessage":"cfg_dropout must be a number, got {self.cfg_dropout!r}","messagePattern":"cfg_dropout must be a number, got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/training/diffusion_train_common.py","lineNumber":1164,"sourceCode":"            flow_shift = flow_shift.strip().lower()\n            if flow_shift != \"auto\":\n                try:\n                    flow_shift = float(flow_shift)\n                except ValueError as exc:\n                    raise ValueError(\n                        f\"flow_shift must be a positive number or 'auto', got {self.flow_shift!r}\"\n                    ) from exc\n        if not isinstance(flow_shift, str):\n            flow_shift = float(flow_shift)\n            # isfinite as well as positive: JSON accepts 1e309, which floats to inf and would poison every sampled sigma while progress looks normal.\n            if not math.isfinite(flow_shift) or flow_shift <= 0:\n                raise ValueError(\n                    \"flow_shift must be a finite number > 0 (1.0 disables the shift), or 'auto'\"\n                )\n        try:\n            cfg_dropout = float(self.cfg_dropout or 0.0)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"cfg_dropout must be a number, got {self.cfg_dropout!r}\") from exc\n        if not 0.0 <= cfg_dropout <= 1.0:\n            raise ValueError(\"cfg_dropout must be between 0 and 1\")\n        weighting_scheme = str(self.weighting_scheme or \"none\").strip().lower()\n        if weighting_scheme not in (\"none\", \"bell\"):\n            raise ValueError(\"weighting_scheme must be one of none / bell\")\n        # A zero/negative gamma would zero out (or invert) the min-SNR weight and silently train on a degenerate loss; None is the documented disable.\n        if self.snr_gamma is not None and float(self.snr_gamma) <= 0:\n            raise ValueError(\"snr_gamma must be > 0, or null to disable min-SNR weighting\")\n        # learning_rate can arrive as a string (\"1e-4\") from the Studio config path, so coerce it before AdamW sees it.\n        try:\n            learning_rate = float(self.learning_rate)\n        except (TypeError, ValueError) as exc:\n            raise ValueError(f\"learning_rate must be a number, got {self.learning_rate!r}\") from exc\n        if learning_rate <= 0:\n            raise ValueError(\"learning_rate must be > 0\")\n        alpha = self.lora_alpha if self.lora_alpha is not None else self.lora_rank\n        targets = tuple(self.lora_target_modules) or DEFAULT_LORA_TARGETS\n        # A blank Hub token (the Studio default when none is configured) must load anonymously, not as an explicit empty credential.","sourceCodeStart":1146,"sourceCodeEnd":1182,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/training/diffusion_train_common.py#L1146-L1182","documentation":"cfg_dropout (probability of dropping CFG conditioning during training) is coerced with float(); if the value is neither numeric nor a numeric string, float() raises TypeError/ValueError and the config re-raises with the offending value shown. Note None defaults to 0.0 via 'or'.","triggerScenarios":"cfg_dropout set to a non-numeric value: a list, dict, or string like 'ten' or '5%'.","commonSituations":"Form or API payloads passing percent strings ('10%'), booleans passed as 'true'/'false' strings, or a nested object where a scalar was expected.","solutions":["Pass cfg_dropout as a number between 0 and 1 (e.g. 0.1), or None/omit it for 0.0.","Convert percentage input to a fraction (10% -> 0.1) before building the config.","Validate payload types at the API boundary before they reach DiffusionLoraConfig."],"exampleFix":"# before\ncfg = DiffusionLoraConfig(cfg_dropout='10%')\n# after\ncfg = DiffusionLoraConfig(cfg_dropout=0.1)","handlingStrategy":"validation","validationCode":"def coerce_dropout(v):\n    if v is None or v == '':\n        return 0.0\n    return float(v)  # let float() reject non-numeric input early","typeGuard":"def is_numeric(v) -> bool:\n    if isinstance(v, bool):\n        return False\n    if isinstance(v, (int, float)):\n        return True\n    try:\n        float(v)\n        return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":null,"preventionTips":["Validate numeric fields at the API/form boundary before they reach the trainer config.","Convert percentage input to fractions at the UI layer."],"tags":["training","config","validation","cfg"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}