{"record":{"id":"cd3931ff9c30cc45","repo":"sgl-project/sglang","slug":"failed-to-load-hicache-native-hash-extension","errorCode":null,"errorMessage":"Failed to load HiCache native hash extension","messagePattern":"Failed to load HiCache native hash extension","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/cpp_utils/native_hash.py","lineNumber":42,"sourceCode":"        )\n\n    try:\n        from torch.utils.cpp_extension import load\n\n        abs_path = os.path.dirname(os.path.abspath(__file__))\n        extra_cflags = [\"-O3\", \"-std=c++17\", \"-DNDEBUG\"]\n        if _cpu_supports_avx2():\n            extra_cflags.append(\"-mavx2\")\n        return load(\n            name=\"hicache_hash_cpp\",\n            sources=[f\"{abs_path}/hash_binding.cpp\"],\n            extra_cflags=extra_cflags,\n            extra_ldflags=[\"-lcrypto\"],\n            with_cuda=False,\n            verbose=False,\n        )\n    except Exception as exc:\n        raise RuntimeError(\"Failed to load HiCache native hash extension\") from exc\n\n\ndef _native_hash_input(token_ids: Any) -> tuple[array, int, int, bool]:\n    raw_token_ids = getattr(token_ids, \"raw_token_ids\", None)\n    raw = (\n        raw_token_ids()\n        if raw_token_ids is not None\n        else getattr(token_ids, \"token_ids\", token_ids)\n    )\n\n    logical_len = len(token_ids)\n    is_bigram = getattr(token_ids, \"is_bigram\", False)\n\n    if isinstance(raw, array) and raw.typecode in (\"I\", \"q\", \"Q\", \"L\"):\n        if is_bigram and logical_len > 0 and len(raw) < logical_len + 1:\n            raise ValueError(\"bigram token buffer is shorter than logical length\")\n        return raw, logical_len, 2 if is_bigram else 1, is_bigram\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/cpp_utils/native_hash.py#L24-L60","documentation":"The torch.utils.cpp_extension.load call for the HiCache native hash extension (compiled C++ linked against -lcrypto) failed. The original exception is chained, so the real cause (missing compiler, missing OpenSSL dev headers, ninja, CUDA toolchain conflicts) is in __cause__.","triggerScenarios":"get_native_hash() triggering JIT compilation where clang/gcc, libcrypto (OpenSSL dev package), or ninja is missing, or a compiler/toolchain version error occurs; any exception inside load() is re-raised as this RuntimeError.","commonSituations":"Slim Docker images without build-essential or libssl-dev; first-run JIT compile in an environment without ninja; incompatible PyTorch/CUDA versions breaking cpp_extension; no network/cache for extension builds.","solutions":["Inspect the chained __cause__ exception for the actual compiler/linker error","Install build prerequisites: apt-get install -y build-essential libssl-dev ninja-build (or OS equivalent)","Retry after cleaning torch extension caches (~/.cache/torch_extensions)","Use the pure-Python hash path as a fallback if the native hash is optional for you"],"exampleFix":"# before\nh = get_native_hash()\n# after\ntry:\n    h = get_native_hash()\nexcept RuntimeError as e:\n    logger.warning(\"native hash unavailable (%s): %s\", e, e.__cause__)\n    h = None  # fall back to Python hash","handlingStrategy":"fallback","validationCode":"import shutil\nshutil.which(\"gcc\") or shutil.which(\"clang\"); shutil.which(\"ninja\")\n# and check libcrypto headers exist before first run","typeGuard":null,"tryCatchPattern":"try:\\n    h = get_native_hash()\\nexcept RuntimeError as e:\\n    log.warning(\"native hash load failed: %s (cause: %s)\", e, e.__cause__)\\n    h = None","preventionTips":["Install build-essential, libssl-dev, and ninja in images that JIT-compile extensions","Pre-build the extension in the Docker image to avoid runtime JIT failures","Always log e.__cause__ to surface the underlying toolchain error"],"tags":["native-extension","build-failure","openssl","toolchain","cpp-extension"],"backgroundTag":"native-extension-build-failure","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}