{"record":{"id":"d51ee9ae7ce3907a","repo":"PaddlePaddle/PaddleOCR","slug":"anneal-strategy-must-by-one-of-cos-or-linear","errorCode":null,"errorMessage":"anneal_strategy must by one of 'cos' or 'linear', instead got {}","messagePattern":"anneal_strategy must by one of 'cos' or 'linear', instead got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/optimizer/lr_scheduler.py","lineNumber":125,"sourceCode":"                    \"start_lr\": self.initial_lr,\n                    \"end_lr\": self.max_lr,\n                },\n                {\n                    \"end_step\": self.total_steps - 1,\n                    \"start_lr\": self.max_lr,\n                    \"end_lr\": self.min_lr,\n                },\n            ]\n\n        # Validate pct_start\n        if pct_start < 0 or pct_start > 1 or not isinstance(pct_start, float):\n            raise ValueError(\n                \"Expected float between 0 and 1 pct_start, but got {}\".format(pct_start)\n            )\n\n        # Validate anneal_strategy\n        if anneal_strategy not in [\"cos\", \"linear\"]:\n            raise ValueError(\n                \"anneal_strategy must by one of 'cos' or 'linear', instead got {}\".format(\n                    anneal_strategy\n                )\n            )\n        elif anneal_strategy == \"cos\":\n            self.anneal_func = self._annealing_cos\n        elif anneal_strategy == \"linear\":\n            self.anneal_func = self._annealing_linear\n\n        super(OneCycleDecay, self).__init__(max_lr, last_epoch, verbose)\n\n    def _annealing_cos(self, start, end, pct):\n        \"Cosine anneal from `start` to `end` as pct goes from 0.0 to 1.0.\"\n        cos_out = math.cos(math.pi * pct) + 1\n        return end + (start - end) / 2.0 * cos_out\n\n    def _annealing_linear(self, start, end, pct):\n        \"Linearly anneal from `start` to `end` as pct goes from 0.0 to 1.0.\"","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/optimizer/lr_scheduler.py#L107-L143","documentation":"Thrown by OneCycleDecay.__init__ when anneal_strategy is not exactly 'cos' or 'linear'. The string comparison is case-sensitive with no normalization, so any other spelling, casing, or whitespace causes the ValueError before the scheduler is built.","triggerScenarios":"Setting scheduler.anneal_strategy in the training config to anything other than the exact lowercase strings 'cos' or 'linear', e.g. 'Cos', 'cosine', 'lin', or a value with trailing whitespace.","commonSituations":"Copy-pasted configs from tutorials that use PyTorch/fastai vocabulary ('cosine'), typos, or uppercase values from templating. Paddle's own CosineAnnealingDecay configs often lead users to write 'cosine' here.","solutions":["Set anneal_strategy to the exact lowercase string 'cos' or 'linear' in the scheduler config block.","Check for invisible whitespace/case issues if the value is generated programmatically: anneal_strategy.strip().lower().","Consult the OneCycleDecay docstring/config template for the accepted values before editing."],"exampleFix":"# before\nOptimizer:\n  scheduler:\n    name: OneCycleDecay\n    anneal_strategy: cosine  # rejected\n\n# after\nOptimizer:\n  scheduler:\n    name: OneCycleDecay\n    anneal_strategy: cos","handlingStrategy":"validation","validationCode":"ANNEAL_STRATEGIES = {\"cos\", \"linear\"}\nstrategy = cfg['Optimizer']['scheduler'].get('anneal_strategy', 'cos').strip().lower()\nassert strategy in ANNEAL_STRATEGIES, f\"anneal_strategy must be one of {ANNEAL_STRATEGIES}, got {strategy!r}\"","typeGuard":"def is_valid_anneal_strategy(v) -> bool:\n    return isinstance(v, str) and v.strip().lower() in {\"cos\", \"linear\"}","tryCatchPattern":null,"preventionTips":["Normalize enum-like config strings (strip + lower) before use.","Copy scheduler blocks from the official PaddleOCR config templates rather than retyping."],"tags":["lr-scheduler","config","enum-validation","training"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}