{"record":{"id":"6359fd7c9816b552","repo":"cocoindex-io/cocoindex","slug":"fraction-must-be-in-0-1-0-got-fraction","errorCode":null,"errorMessage":"fraction must be in (0, 1.0], got {fraction}","messagePattern":"fraction must be in \\(0, 1\\.0\\], got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/cocoindex/_internal/runner.py","lineNumber":407,"sourceCode":"    ``coco.GPU`` is shorthand for ``GPURunner(fraction=1.0)``.\n    ``coco.GPU(0.5)`` creates a runner requesting half a GPU.\n\n    The assigned GPU id(s) are available inside the function via\n    ``coco.current_gpu()`` (first id) and ``coco.current_gpus()`` (full list).\n    The allocated fraction is available via ``coco.current_gpu_fraction()``.\n    For multi-GPU subprocess mode (where ``CUDA_VISIBLE_DEVICES`` must be set\n    per-process), use in-process mode (the default) until per-GPU subprocess\n    pools are implemented.\n    \"\"\"\n\n    _fraction: float\n    _use_subprocess: bool | None\n    _gpu_executor: ThreadPoolExecutor | None\n\n    def __init__(self, fraction: float = 1.0) -> None:\n        super().__init__()\n        if not (0 < fraction <= 1.0):\n            raise ValueError(f\"fraction must be in (0, 1.0], got {fraction}\")\n        self._fraction = fraction\n        self._use_subprocess = None\n        self._gpu_executor = None\n\n    def __call__(self, fraction: float = 1.0) -> GPURunner:\n        return GPURunner(fraction=fraction)\n\n    def _should_use_subprocess(self) -> bool:\n        \"\"\"Check if subprocess mode is enabled (reads env var lazily on first call).\"\"\"\n        if self._use_subprocess is None:\n            self._use_subprocess = (\n                os.environ.get(\"COCOINDEX_RUN_GPU_IN_SUBPROCESS\") == \"1\"\n            )\n        return self._use_subprocess\n\n    def _get_gpu_executor(self) -> ThreadPoolExecutor:\n        \"\"\"Get or create the dedicated GPU thread pool.\"\"\"\n        if self._gpu_executor is None:","sourceCodeStart":389,"sourceCodeEnd":425,"githubUrl":"https://github.com/cocoindex-io/cocoindex/blob/e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b/python/cocoindex/_internal/runner.py#L389-L425","documentation":"GPURunner supports fractional GPU allocation (e.g. MIG-style shares) but a fraction must be a positive value no greater than 1.0. Values outside (0, 1.0] — 0, negative, NaN, or >1 — raise a ValueError at construction.","triggerScenarios":"GPURunner(fraction=0), GPURunner(fraction=1.5), GPURunner(fraction=-0.2), or a float('nan') passed from config or a percentage conversion bug (e.g. 150 passed instead of 1.5 meaning 150%).","commonSituations":"Confusing percentages with fractions (passing 150 instead of 1.5 or 0.5 instead of 50), dividing by zero when computing the share, or parsing an invalid config value.","solutions":["Pass a fraction in (0, 1.0], e.g. GPURunner(fraction=0.5).","Convert percentages by dividing by 100 and clamp: fraction = min(max(pct/100, 1e-9), 1.0).","Validate the configured value before constructing the runner and surface a clear config error.","Guard against NaN/zero results from upstream division in your config loading."],"exampleFix":"// before\npct = cfg[\"gpu_share\"]  # e.g. 150\nrunner = GPURunner(fraction=pct)  # ValueError\n\n// after\nfraction = min(max(cfg[\"gpu_share_pct\"] / 100.0, 1e-9), 1.0)\nrunner = GPURunner(fraction=fraction)","handlingStrategy":"validation","validationCode":"import math\nif not (isinstance(fraction, float) and math.isfinite(fraction) and 0 < fraction <= 1.0):\n    raise ValueError(f\"fraction must be in (0, 1.0], got {fraction}\")","typeGuard":"def valid_fraction(x: object) -> bool:\n    return isinstance(x, (int, float)) and math.isfinite(x) and 0 < x <= 1.0","tryCatchPattern":"try:\n    runner = GPURunner(fraction=fraction)\nexcept ValueError as e:\n    logging.error(\"bad GPU fraction: %s\", e)\n    runner = GPURunner(fraction=1.0)","preventionTips":["Store fractions (0.5), never percentages (50), in config","Clamp computed shares to (0, 1.0] after division","Check for NaN when the value is computed dynamically"],"tags":["python","gpu","validation","value-error"],"backgroundTag":"value-out-of-range","analyzedSha":"e84aa99b3292c5270a4b313b2a7137ad9ce8ab3b","analyzedAt":"2026-09-08T15:59:19.997Z","contentChangedAt":"2026-09-08T15:59:19.997Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}