{"record":{"id":"121ccd28f8db5ba2","repo":"unslothai/unsloth","slug":"snr-gamma-must-be-0-or-null-to-disable-min-snr","errorCode":null,"errorMessage":"snr_gamma must be > 0, or null to disable min-SNR weighting","messagePattern":"snr_gamma must be > 0, or null to disable min-SNR weighting","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/training/diffusion_train_common.py","lineNumber":1172,"sourceCode":"        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.\n        token = self.hf_token.strip() if isinstance(self.hf_token, str) else self.hf_token\n        from core.inference.diffusion_families import (\n            _is_local_path,\n            mirror_repo,\n            prefer_ungated_mirror,\n            upstream_is_gated,\n        )\n","sourceCodeStart":1154,"sourceCodeEnd":1190,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/training/diffusion_train_common.py#L1154-L1190","documentation":"snr_gamma controls min-SNR loss weighting. A zero or negative gamma would zero out or invert the min-SNR weight, silently training on a degenerate loss, so it must be strictly positive. None is the documented way to disable min-SNR weighting.","triggerScenarios":"snr_gamma=0 (attempting to disable) or a negative value in the config.","commonSituations":"Users set 0 expecting 'off' behavior; the API uses None for off, not 0.","solutions":["Set snr_gamma=None to disable min-SNR weighting.","Use a positive value such as 5.0 (the common default in the literature) to enable it."],"exampleFix":"# before\ncfg = DiffusionLoraConfig(snr_gamma=0)\n# after\ncfg = DiffusionLoraConfig(snr_gamma=None)  # disable, or 5.0 to enable","handlingStrategy":"type-guard","validationCode":"if snr_gamma is not None:\n    assert float(snr_gamma) > 0, 'snr_gamma must be > 0, or None to disable'","typeGuard":"def is_valid_snr_gamma(v) -> bool:\n    return v is None or (isinstance(v, (int, float)) and not isinstance(v, bool) and v > 0)","tryCatchPattern":null,"preventionTips":["Use None, never 0, to disable min-SNR weighting.","Prefer the standard value 5.0 unless you have a reason to tune it."],"tags":["training","config","loss-weighting","min-snr","validation"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}