{"record":{"id":"35a97af45061a0fe","repo":"ultralytics/ultralytics","slug":"k-v-is-invalid-valid-k-values-are-quan","errorCode":null,"errorMessage":"'{k}={v}' is invalid. Valid '{k}' values are {QUANTIZE_VALID_VALUES}. See {QUANTIZE_DOCS_URL}","messagePattern":"'(.+?)=(.+?)' is invalid\\. Valid '(.+?)' values are (.+?)\\. See (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ultralytics/cfg/__init__.py","lineNumber":494,"sourceCode":"                        f\"'{k}' must be a bool (i.e. '{k}=True' or '{k}=False')\"\n                    )\n                cfg[k] = bool(v)\n            elif k in CFG_STR_KEYS and not isinstance(v, str):\n                if hard:\n                    raise TypeError(f\"'{k}={v}' is of invalid type {type(v).__name__}. '{k}' must be a str.\")\n                cfg[k] = str(v)\n            elif k == \"compile\" and not isinstance(v, (bool, str)):  # False=off, True=\"default\", or a mode string\n                if hard:\n                    raise TypeError(\n                        f\"'{k}={v}' is of invalid type {type(v).__name__}. \"\n                        f\"'{k}' must be a bool or str (i.e. '{k}=True' or '{k}=max-autotune')\"\n                    )\n                cfg[k] = bool(v)\n            elif k == \"quantize\":  # canonicalize 8/16/32 or w-notation to a scheme (unset stays None for FP32)\n                scheme = QUANTIZE_ALIASES.get(str(v).lower())\n                if scheme is None:\n                    if hard:\n                        raise ValueError(\n                            f\"'{k}={v}' is invalid. Valid '{k}' values are {QUANTIZE_VALID_VALUES}. \"\n                            f\"See {QUANTIZE_DOCS_URL}\"\n                        )\n                else:\n                    cfg[k] = scheme\n\n\ndef get_save_dir(args: SimpleNamespace, name: str | None = None) -> Path:\n    \"\"\"Return the directory path for saving outputs, derived from arguments or default settings.\n\n    Args:\n        args (SimpleNamespace): Namespace object containing configurations such as 'project', 'name', 'task', 'mode',\n            and 'save_dir'.\n        name (str | None): Optional name for the output directory. If not provided, it defaults to 'args.name' or the\n            'args.mode'.\n\n    Returns:\n        (Path): Directory path where outputs should be saved.","sourceCodeStart":476,"sourceCodeEnd":512,"githubUrl":"https://github.com/ultralytics/ultralytics/blob/0449ea011cfd6c9a0d50a0bf1043aca5190cd476/ultralytics/cfg/__init__.py#L476-L512","documentation":"The `quantize` key canonicalizes numeric precisions (8/16/32) and w-notation (e.g. w8, w16) through the QUANTIZE_ALIASES map into a scheme. A value that matches no alias (after lowercasing and str()) raises ValueError in hard mode; in soft mode an unknown value is silently left as-is. Unset (None) stays None meaning FP32. The message points at QUANTIZE_VALID_VALUES and the docs URL.","triggerScenarios":"export(quantize='int4'), train/predict overrides with quantize='fp8', quantize='q4_k_m' or other values not in QUANTIZE_ALIASES, passed through hard validation (API overrides, cfg YAML). Case-insensitive: 'W8' works, 'int4' does not if 4-bit is unsupported.","commonSituations":"Requesting precisions the build does not support (4-bit, fp8); mixing GGLM/GGUF quantization mnemonics (q4_0) with ultralytics quantize syntax; typos like 'w8a8' when only plain w-notation is aliased.","solutions":["Use one of the values listed in the error (QUANTIZE_VALID_VALUES), e.g. quantize=8/16/32 or 'w8'/'w16'.","Omit quantize (or pass None) for default FP32.","Check the linked docs page (QUANTIZE_DOCS_URL in the message) for the current alias table before inventing notation.","Verify the target export format actually supports the requested scheme."],"exampleFix":"# before\nmodel.export(format=\"onnx\", quantize=\"int4\")\n\n# after\nmodel.export(format=\"onnx\", quantize=\"w8\")  # use a supported alias","handlingStrategy":"validation","validationCode":"from ultralytics.cfg import QUANTIZE_ALIASES  # alias map used by check_cfg\n\nvalid = set(QUANTIZE_ALIASES) | {None}\nif cfg.get(\"quantize\") not in valid and str(cfg.get(\"quantize\")).lower() not in QUANTIZE_ALIASES:\n    raise ValueError(f\"quantize must be one of {sorted(QUANTIZE_ALIASES)} or None\")","typeGuard":"def is_valid_quantize(v) -> bool:\n    from ultralytics.cfg import QUANTIZE_ALIASES\n    return v is None or str(v).lower() in QUANTIZE_ALIASES","tryCatchPattern":"try:\n    model.export(format=\"onnx\", quantize=scheme)\nexcept ValueError as e:\n    if \"Valid 'quantize'\" in str(e):\n        scheme = \"w8\"  # or None for FP32\n        model.export(format=\"onnx\", quantize=scheme)\n    else:\n        raise","preventionTips":["Restrict quantize in config UIs to the documented alias list (8/16/32, w-notation).","Leave quantize unset for FP32 instead of guessing mnemonics.","Confirm the export format supports the scheme before scripting it."],"tags":["config","quantization","export","value-range","validation"],"backgroundTag":null,"analyzedSha":"0449ea011cfd6c9a0d50a0bf1043aca5190cd476","analyzedAt":"2026-08-15T02:34:13.413Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}