{"record":{"id":"94afcee3260d9c83","repo":"sgl-project/sglang","slug":"hicache-native-hash-is-only-supported-on-little-en","errorCode":null,"errorMessage":"HiCache native hash is only supported on little-endian Linux","messagePattern":"HiCache native hash is only supported on little-endian Linux","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/mem_cache/cpp_utils/native_hash.py","lineNumber":22,"sourceCode":"from array import array\nfrom functools import lru_cache\nfrom typing import Any, Optional\n\n\ndef _cpu_supports_avx2() -> bool:\n    if platform.machine().lower() not in (\"x86_64\", \"amd64\"):\n        return False\n    try:\n        with open(\"/proc/cpuinfo\", \"r\", encoding=\"utf-8\", errors=\"ignore\") as f:\n            return \"avx2\" in f.read().lower()\n    except OSError:\n        return False\n\n\n@lru_cache(maxsize=1)\ndef _load_native_hash_module() -> Any:\n    if sys.byteorder != \"little\" or not sys.platform.startswith(\"linux\"):\n        raise RuntimeError(\n            \"HiCache native hash is only supported on little-endian Linux\"\n        )\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        )","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/mem_cache/cpp_utils/native_hash.py#L4-L40","documentation":"The HiCache native hash extension only builds/runs on little-endian Linux. _load_native_hash_module checks sys.byteorder and sys.platform up front and raises this RuntimeError elsewhere (e.g. macOS, big-endian s390x/PowerPC) before attempting the torch cpp_extension load.","triggerScenarios":"Calling get_native_hash() on big-endian systems or non-Linux platforms (macOS ARM/Intel, Windows, FreeBSD); the platform guard fires before any extension compilation.","commonSituations":"Developing or unit-testing SGLang on a Mac or Windows workstation; running in an unusual container reporting a non-linux platform; big-endian enterprise hardware.","solutions":["Run the workload on little-endian Linux (x86_64 or aarch64 Linux)","Use the pure-Python hash fallback instead of get_native_hash if your code path allows it","For local development, use Docker with a linux/amd64 or linux/arm64 image"],"exampleFix":"# before\nfrom sglang.srt.mem_cache.cpp_utils.native_hash import get_native_hash\nh = get_native_hash()\n# after\nimport sys\nif sys.byteorder == \"little\" and sys.platform.startswith(\"linux\"):\n    h = get_native_hash()\nelse:\n    h = None  # use pure-Python hash path","handlingStrategy":"type-guard","validationCode":"import sys\n_NATIVE_HASH_OK = sys.byteorder == \"little\" and sys.platform.startswith(\"linux\")\nif not _NATIVE_HASH_OK:\n    use_python_hash_fallback()","typeGuard":"def native_hash_supported() -> bool:\n    import sys\n    return sys.byteorder == \"little\" and sys.platform.startswith(\"linux\")","tryCatchPattern":"try:\\n    h = get_native_hash()\\nexcept RuntimeError:\\n    h = None  # fallback to pure-Python hashing","preventionTips":["Develop inside linux containers to match production","Feature-detect platform before first native hash use","Keep a pure-Python hash fallback wired in your code"],"tags":["native-extension","platform-support","linux-only","endianess"],"backgroundTag":"unsupported-platform","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}