{"record":{"id":"e04430ebb1fe1124","repo":"unslothai/unsloth","slug":"flow-shift-must-be-a-positive-number-or-auto-go","errorCode":null,"errorMessage":"flow_shift must be a positive number or 'auto', got {self.flow_shift!r}","messagePattern":"flow_shift must be a positive number or 'auto', got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/training/diffusion_train_common.py","lineNumber":1151,"sourceCode":"            # scheme cleared only for rendering reach a trainer.\n            from core.inference.diffusion_transformer_quant import _family_train_denied\n\n            if _family_train_denied(resolved_family, base_precision):\n                raise ValueError(\n                    f\"base_precision={base_precision!r} is not validated for training \"\n                    f\"{resolved_family}. Use 'nf4', 'int8', 'bf16', or 'auto'.\"\n                )\n        # flow_shift: None resolves to the family default (\"auto\" only for qwen-image, whose scheduler skips its static shift under use_dynamic_shifting); an explicit value is validated and kept.\n        flow_shift = self.flow_shift\n        if flow_shift is None:\n            flow_shift = \"auto\" if resolved_family in AUTO_FLOW_SHIFT_FAMILIES else 1.0\n        if isinstance(flow_shift, str):\n            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\")","sourceCodeStart":1133,"sourceCodeEnd":1169,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/training/diffusion_train_common.py#L1133-L1169","documentation":"flow_shift accepts a positive number or the string 'auto' (family-default dynamic shift). If a string is supplied that is neither 'auto' nor parseable by float(), the config raises with the original value echoed. Numbers pass through a separate finite/positive check.","triggerScenarios":"Setting flow_shift to a non-numeric string such as 'default', '1,0' (locale decimal comma), or '' (empty string after strip/lower) in DiffusionLoraConfig.","commonSituations":"Studio UI or hand-edited YAML/JSON config with a typo'd or localized number; passing None-like placeholder strings; copy-pasting a scheduler name into the field.","solutions":["Set flow_shift to a positive float (e.g. 1.0) or the literal string 'auto'.","Omit flow_shift (None) to take the family default: 'auto' for AUTO_FLOW_SHIFT_FAMILIES like qwen-image, 1.0 otherwise.","If the value comes from user input, normalize locale decimal separators and strip whitespace before assigning."],"exampleFix":"# before\ncfg.flow_shift = '1,5'  # or 'default'\n# after\ncfg.flow_shift = 1.5  # or 'auto', or None for the family default","handlingStrategy":"type-guard","validationCode":"def normalize_flow_shift(v):\n    if v is None:\n        return None\n    if isinstance(v, str):\n        s = v.strip().lower()\n        if s == 'auto':\n            return 'auto'\n        v = float(s)  # raises here instead of inside the trainer\n    return float(v)","typeGuard":"def is_valid_flow_shift(v) -> bool:\n    if v is None:\n        return True\n    if isinstance(v, str):\n        s = v.strip().lower()\n        if s == 'auto':\n            return True\n        try:\n            v = float(s)\n        except ValueError:\n            return False\n    return isinstance(v, (int, float))","tryCatchPattern":null,"preventionTips":["Normalize locale-formatted numbers (replace ',' with '.') and strip whitespace before assigning flow_shift.","Prefer passing a float or omitting the field; only send the string 'auto' explicitly."],"tags":["training","config","flow-matching","validation","scheduler"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}