{"record":{"id":"a5b9d03ba46463f9","repo":"vllm-project/vllm","slug":"expected-ty-but-got-type-value-for-value","errorCode":null,"errorMessage":"Expected {ty} but got {type(value)} for {value}","messagePattern":"Expected (.+?) but got (.+?) for (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"vllm/compilation/backends.py","lineNumber":195,"sourceCode":"        base cache dir of /path/to/hash_str/rank_i_j/ ,\n        to store some common compilation artifacts.\n        \"\"\"\n\n        self.disable_cache = disable_cache\n        self.cache_dir = cache_dir\n        self.cache_file_path = os.path.join(cache_dir, \"vllm_compile_cache.py\")\n\n        if not disable_cache and os.path.exists(self.cache_file_path):\n            # load the cache from the file\n            with open(self.cache_file_path) as f:\n                # we use ast.literal_eval to parse the data\n                # because it is a safe way to parse Python literals.\n                # do not use eval(), it is unsafe.\n                cache = ast.literal_eval(f.read())\n\n            def check_type(value: Any, ty: type) -> None:\n                if not isinstance(value, ty):\n                    raise TypeError(f\"Expected {ty} but got {type(value)} for {value}\")\n\n            def parse_key(key: Any) -> tuple[Range, int, str]:\n                range_tuple, graph_index, compiler_name = key\n                check_type(graph_index, int)\n                check_type(compiler_name, str)\n                if isinstance(range_tuple, tuple):\n                    start, end = range_tuple\n                    check_type(start, int)\n                    check_type(end, int)\n                    range_tuple = Range(start=start, end=end)\n                check_type(range_tuple, Range)\n                return range_tuple, graph_index, compiler_name\n\n            self.cache = {parse_key(key): value for key, value in cache.items()}\n\n        self.compiler.initialize_cache(\n            cache_dir=cache_dir, disable_cache=disable_cache, prefix=prefix\n        )","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/vllm/compilation/backends.py#L177-L213","documentation":"The Inductor compilation-cache backend persists compiled-graph keys to vllm_compile_cache.py and reloads them with ast.literal_eval, then re-validates the structure with check_type(). If the cached literal contains a value whose Python type no longer matches the expected schema (int graph index, str compiler name, Range/tuple range), TypeError is raised with expected vs. actual type.","triggerScenarios":"Loading a stale vllm_compile_cache.py written by an older/newer vLLM version whose key schema differed, or a hand-edited/truncated cache file; e.g. compiler_name stored as int, or range_tuple as a list instead of tuple/Range.","commonSituations":"Upgrading vLLM (or torch) while reusing ~/.cache/vllm/compilation cache across versions; a crashed process leaving a partially-written cache file; version-skew between nodes sharing a cache volume.","solutions":["Delete the compilation cache directory (default under ~/.cache/vllm, the cache_dir holding vllm_compile_cache.py) so it is rebuilt from scratch","Pin matching vLLM/torch versions on machines that share a cache directory, or give each version its own cache_dir","Set disable_cache / VLLM_DISABLE_COMPILE_CACHE=1 if cache staleness keeps recurring"],"exampleFix":"# before: reuse stale cache from older vllm -> TypeError on load\n# after\n$ rm -rf ~/.cache/vllm/compilation  # or the configured cache_dir\n$ # restart vllm, cache regenerates","handlingStrategy":"fallback","validationCode":"cache = os.path.join(cache_dir, \"vllm_compile_cache.py\")\nif os.path.exists(cache) and cache_written_by_different_version(cache):\n    shutil.rmtree(cache_dir)  # regenerate","typeGuard":null,"tryCatchPattern":"try:\n    backend.load_cached(...)\nexcept (TypeError, SyntaxError, ValueError):\n    shutil.rmtree(cache_dir, ignore_errors=True)\n    backend.load_cached(...)  # rebuild from scratch","preventionTips":["Wipe the vLLM compile cache after every vLLM/torch upgrade","Give per-version cache_dir when multiple versions share a host"],"tags":["compilation","cache","version-skew","torch-compile"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}