{"record":{"id":"82c0a5ce2776b072","repo":"sgl-project/sglang","slug":"handle-types-must-be-auto-an-integer-or-none","errorCode":null,"errorMessage":"handle_types must be 'auto', an integer, or None","messagePattern":"handle_types must be 'auto', an integer, or None","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/utils/cuda_vmm_utils.py","lineNumber":282,"sourceCode":"        )\n        return handle_type\n    raise RuntimeError(\"no supported CUDA VMM allocation handle type\") from last_error\n\n\ndef make_device_allocation_prop(\n    device_id: int,\n    *,\n    handle_types: int | str | None = \"auto\",\n    gpu_direct_rdma: bool = False,\n):\n    \"\"\"Build a device allocation prop with automatic or explicit exportability.\"\"\"\n    drv = _get_cuda_driver()\n    if handle_types == \"auto\":\n        handle_types = get_device_allocation_handle_type(device_id)\n    elif handle_types is None:\n        handle_types = drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_NONE\n    elif not isinstance(handle_types, int):\n        raise ValueError(\"handle_types must be 'auto', an integer, or None\")\n\n    handle_type_value = int(handle_types)\n    valid_handle_types = {\n        int(drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_NONE): (\n            drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_NONE\n        ),\n        int(drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR): (\n            drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR\n        ),\n        int(drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_FABRIC): (\n            drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_FABRIC\n        ),\n    }\n    if handle_type_value not in valid_handle_types:\n        raise ValueError(f\"invalid CUDA handle-type value: {handle_type_value}\")\n\n    prop = drv.CUmemAllocationProp()\n    prop.type = drv.CUmemAllocationType.CU_MEM_ALLOCATION_TYPE_PINNED","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/utils/cuda_vmm_utils.py#L264-L300","documentation":"make_device_allocation_prop accepts handle_types as the string 'auto' (auto-detect), None (no sharing), or a raw integer handle-type bitmask. Any other type — a list, a string other than 'auto', an enum object on some versions — raises this ValueError before touching the driver.","triggerScenarios":"Passing handle_types=['posix'] or 'fabric' (string names) instead of the integer bitmask; passing a CUmemAllocationHandleType enum instance where the installed cuda-bindings requires int; passing a float.","commonSituations":"User config exposing handle type names that aren't converted to int bitmasks; version upgrades of cuda-bindings changing enum/int acceptance.","solutions":["Pass int(handle_types) — convert enums with int() before the call","Use 'auto' to let the library detect the best handle type, or None for no sharing","Map config strings to int(drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX) etc. at your config layer"],"exampleFix":"# before\nprop = make_device_allocation_prop(0, handle_types=\"posix\")\n\n# after\nfrom cuda.bindings import driver as drv\nprop = make_device_allocation_prop(\n    0, handle_types=int(drv.CUmemAllocationHandleType.CU_MEM_HANDLE_TYPE_POSIX)\n)","handlingStrategy":"type-guard","validationCode":"assert handle_types == \"auto\" or handle_types is None or isinstance(handle_types, int)","typeGuard":"def valid_handle_types(h) -> bool:\n    return h == \"auto\" or h is None or isinstance(h, int) and not isinstance(h, bool)","tryCatchPattern":null,"preventionTips":["Convert enums with int() before passing","Prefer 'auto' unless you need a specific handle type"],"tags":["cuda","vmm","validation","handle","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}