{"record":{"id":"3b0e4a420cc9936e","repo":"PaddlePaddle/PaddleOCR","slug":"expected-float-between-0-and-1-pct-start-but-got","errorCode":null,"errorMessage":"Expected float between 0 and 1 pct_start, but got {}","messagePattern":"Expected float between 0 and 1 pct_start, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ppocr/optimizer/lr_scheduler.py","lineNumber":119,"sourceCode":"                },\n            ]\n        else:\n            self._schedule_phases = [\n                {\n                    \"end_step\": float(pct_start * self.total_steps) - 1,\n                    \"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):","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/ppocr/optimizer/lr_scheduler.py#L101-L137","documentation":"Thrown by OneCycleDecay.__init__ in PaddleOCR's LR scheduler when the pct_start argument fails validation. The guard requires pct_start to be a Python float AND strictly within [0, 1]. Because the isinstance(pct_start, float) check is part of the same condition, even an in-range int (0 or 1) is rejected, as are strings like '0.2' that some config loaders deliver.","triggerScenarios":"Constructing OneCycleDecay (directly or via a training config with scheduler.name: OneCycleDecay) with pct_start that is out of range, an int (e.g. pct_start=1), or a non-numeric type such as a string loaded from a config file.","commonSituations":"YAML/JSON config where pct_start is quoted ('0.3') so it arrives as a string; passing whole-number boundaries 0 or 1 as int; hand-written training scripts passing div results or ints from argparse (argparse type=int).","solutions":["Pass pct_start as an explicit float literal, e.g. pct_start=0.1 or pct_start=1.0 for the boundary values.","If the value comes from a config file, unquote it (pct_start: 0.1, not pct_start: '0.1') so YAML parses it as a float.","If it may be computed dynamically, coerce before constructing: pct_start = float(pct_start)."],"exampleFix":"# before\nOneCycleDecay(max_lr=0.001, total_steps=10000, pct_start=1)  # int -> ValueError\n\n# after\nOneCycleDecay(max_lr=0.001, total_steps=10000, pct_start=1.0)  # float literal","handlingStrategy":"type-guard","validationCode":"def valid_pct_start(v) -> float:\n    v = float(v)  # raises early with a clear message if non-numeric\n    if not (0.0 <= v <= 1.0):\n        raise ValueError(f\"pct_start must be within [0,1], got {v}\")\n    return v\n\npct = valid_pct_start(cfg['Optimizer']['scheduler'].get('pct_start', 0.1))","typeGuard":"def is_valid_pct_start(v) -> bool:\n    return isinstance(v, float) and 0.0 <= v <= 1.0","tryCatchPattern":null,"preventionTips":["Normalize numeric config values with float() before passing them to scheduler constructors.","Keep a config schema check at startup that validates scheduler kwargs before training begins.","Write pct_start as an unquoted decimal literal in YAML so it parses as float."],"tags":["lr-scheduler","config","type-validation","training"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}