{"record":{"id":"64ec0b1d5a972d15","repo":"unslothai/unsloth","slug":"flow-shift-must-be-a-finite-number-0-1-0-disabl","errorCode":null,"errorMessage":"flow_shift must be a finite number > 0 (1.0 disables the shift), or 'auto'","messagePattern":"flow_shift must be a finite number > 0 \\(1\\.0 disables the shift\\), or 'auto'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/training/diffusion_train_common.py","lineNumber":1158,"sourceCode":"                )\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\")\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:","sourceCodeStart":1140,"sourceCodeEnd":1176,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/training/diffusion_train_common.py#L1140-L1176","documentation":"After successful float conversion, flow_shift must be finite and strictly positive. JSON parsers happily accept 1e309, which Python floats to inf — an infinite shift would poison every sampled sigma while training progress looks normal — so math.isfinite is enforced explicitly. 1.0 disables the shift.","triggerScenarios":"flow_shift = float('inf'), float('nan'), 0, a negative number, or a JSON value like 1e309 / -0.0 that floats to a non-finite or non-positive value.","commonSituations":"Programmatic config generation that divides by zero or overflows; hand-written JSON with huge exponents; treating 0 as 'no shift' when 1.0 is the actual disable value.","solutions":["Use flow_shift=1.0 to disable shifting — not 0.","Ensure computed values are bounded: clamp or validate with math.isfinite before assigning.","For qwen-image dynamic shifting, prefer flow_shift='auto' rather than a hand-picked extreme value."],"exampleFix":"# before\ncfg.flow_shift = 0  # intended 'no shift'\n# after\ncfg.flow_shift = 1.0  # 1.0 disables the shift","handlingStrategy":"validation","validationCode":"import math\ndef safe_flow_shift(v):\n    if isinstance(v, str):\n        v = None if v.strip().lower() == 'auto' else float(v)\n    if v is not None and (not math.isfinite(v) or v <= 0):\n        raise ValueError('flow_shift must be finite and > 0; use 1.0 to disable')\n    return v","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember 1.0 disables the shift; 0 is invalid, not 'off'.","Validate computed shift values with math.isfinite — JSON inputs can carry 1e309."],"tags":["training","flow-matching","validation","numeric-safety"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}