-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
[torch.compile] caching of config fields should be opt-out by default #26468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vnadathur
wants to merge
21
commits into
vllm-project:main
Choose a base branch
from
vnadathur:envhashing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+550
−180
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
97a6194
Opt-out hashing for torch.compile cache keys (ModelConfig + envs)
vnadathur 61d580d
fixed sha-256 for backends.py
WorldExplored 69f6880
short refactor and addressing comments
WorldExplored d6dccaf
added lazy logging to logging utils
vnadathur 1359256
Addresed Codex Problems
WorldExplored 3a3af9b
Merge branch 'main' into envhashing
WorldExplored 1485803
solve merge conflict
vnadathur e4db7f4
fixed ignore list in model.py
WorldExplored 0648852
Merge branch 'main' into envhashing
WorldExplored 226a4ae
Merge branch 'main' into envhashing
WorldExplored f357dbf
Merge branch 'main' into envhashing
WorldExplored 35acae2
Merge branch 'main' into envhashing
WorldExplored a8cd228
Update lazy.py
vnadathur 2a77dac
Merge branch 'main' into envhashing
WorldExplored e8e10bf
Merge branch 'main' into envhashing
WorldExplored 7e1cb9f
revised test file
WorldExplored 8537a07
Merge branch 'main' into envhashing
WorldExplored 4d10df3
update test
vnadathur a40c3af
Merge branch 'main' into envhashing
vnadathur fd7be7b
Merge branch 'main' into envhashing
WorldExplored 2b6b27b
addressed reviewer concerns
WorldExplored File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # SPDX-FileCopyrightText: Copyright contributors to the vLLM project | ||
|
|
||
| from dataclasses import dataclass | ||
| from enum import Enum | ||
| from typing import Optional | ||
|
|
||
| import pytest | ||
|
|
||
| from vllm.config.utils import get_hash_factors, hash_factors, normalize_value | ||
|
|
||
| # Helpers | ||
|
|
||
| def endswith_fqname(obj, suffix: str) -> bool: | ||
| # normalize_value(type) returns fully-qualified name | ||
| # Compare suffix to avoid brittle import paths. | ||
| out = normalize_value(obj) | ||
| return isinstance(out, str) and out.endswith(suffix) | ||
|
|
||
|
|
||
| def expected_path(p_str: str = ".") -> str: | ||
| import pathlib | ||
|
|
||
| p = pathlib.Path(p_str) | ||
| return p.expanduser().resolve().as_posix() | ||
|
|
||
|
|
||
| # Minimal dataclass to test get_hash_factors. | ||
| # Avoid importing heavy vLLM configs. | ||
| @dataclass | ||
| class SimpleConfig: | ||
| a: object | ||
| b: Optional[object] = None | ||
|
|
||
|
|
||
| class DummyLogprobsMode(Enum): | ||
| RAW_LOGITS = "raw_logits" | ||
|
|
||
|
|
||
| def test_hash_factors_deterministic(): | ||
| """Test that hash_factors produces consistent SHA-256 hashes""" | ||
| factors = {"a": 1, "b": "test"} | ||
| hash1 = hash_factors(factors) | ||
| hash2 = hash_factors(factors) | ||
|
|
||
| assert hash1 == hash2 | ||
| assert len(hash1) == 64 | ||
| assert all(c in "0123456789abcdef" for c in hash1) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "inp, expected", | ||
| [ | ||
| (None, None), | ||
| (True, True), | ||
| (1, 1), | ||
| (1.0, 1.0), | ||
| ("x", "x"), | ||
| (b"ab", "6162"), | ||
| (bytearray(b"ab"), "6162"), | ||
| ([1, 2], (1, 2)), | ||
| ({"b": 2, "a": 1}, (("a", 1), ("b", 2))), | ||
| ], | ||
| ) | ||
| def test_normalize_value_matrix(inp, expected): | ||
| """Parametric input→expected normalization table.""" | ||
| assert normalize_value(inp) == expected | ||
|
|
||
|
|
||
| def test_normalize_value_enum(): | ||
| # Enums normalize to (module.QualName, value). | ||
| # DummyLogprobsMode uses a string payload. | ||
| out = normalize_value(DummyLogprobsMode.RAW_LOGITS) | ||
| assert isinstance(out, tuple) | ||
| assert out[0].endswith("DummyLogprobsMode") | ||
| # Expect string payload 'raw_logits'. | ||
| assert out[1] == "raw_logits" | ||
|
|
||
|
|
||
| def test_normalize_value_set_order_insensitive(): | ||
| # Sets are unordered; normalize_value sorts elements for determinism. | ||
| assert normalize_value({3, 1, 2}) == normalize_value({1, 2, 3}) | ||
|
|
||
|
|
||
| def test_normalize_value_path_normalization(): | ||
| from pathlib import Path # local import to avoid global dependency | ||
|
|
||
| # Paths expand/resolve to absolute strings. | ||
| # Stabilizes hashing across working dirs. | ||
| assert normalize_value(Path(".")) == expected_path(".") | ||
|
|
||
|
|
||
| def test_normalize_value_uuid_and_to_json(): | ||
| # Objects may normalize via uuid() or to_json_string(). | ||
| class HasUUID: | ||
| def uuid(self): | ||
| return "test-uuid" | ||
|
|
||
| class ToJson: | ||
| def to_json_string(self): | ||
| return '{"x":1}' | ||
|
|
||
| assert normalize_value(HasUUID()) == "test-uuid" | ||
| assert normalize_value(ToJson()) == '{"x":1}' | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "bad", | ||
| [ | ||
| (lambda x: x), | ||
| (type("CallableInstance", (), {"__call__": lambda self: 0}))(), | ||
| (lambda: (lambda: 0))(), # nested function instance | ||
| ], | ||
| ) | ||
| def test_error_cases(bad): | ||
| """Inputs expected to raise TypeError.""" | ||
| # Reject functions/lambdas/callable instances | ||
| # to avoid under-hashing. | ||
| with pytest.raises(TypeError): | ||
| normalize_value(bad) | ||
|
|
||
|
|
||
| def test_enum_vs_int_disambiguation(): | ||
| # int stays primitive | ||
| nf_int = normalize_value(1) | ||
| assert nf_int == 1 | ||
|
|
||
| # enum becomes ("module.QualName", value) | ||
| nf_enum = normalize_value(DummyLogprobsMode.RAW_LOGITS) | ||
| assert isinstance(nf_enum, tuple) and len(nf_enum) == 2 | ||
| enum_type, enum_val = nf_enum | ||
| assert enum_type.endswith(".DummyLogprobsMode") | ||
| assert enum_val == "raw_logits" | ||
|
|
||
| # Build factor dicts from configs with int vs enum | ||
| f_int = get_hash_factors(SimpleConfig(1), set()) | ||
| f_enum = get_hash_factors(SimpleConfig(DummyLogprobsMode.RAW_LOGITS), set()) | ||
| # The int case remains a primitive value | ||
| assert f_int["a"] == 1 | ||
| # The enum case becomes a tagged tuple ("module.QualName", "raw_logits") | ||
| assert isinstance(f_enum["a"], tuple) and f_enum["a"][1] == "raw_logits" | ||
| # Factor dicts must differ so we don't collide primitives with Enums. | ||
| assert f_int != f_enum | ||
| # Hash digests must differ correspondingly | ||
| assert hash_factors(f_int) != hash_factors(f_enum) | ||
|
|
||
| # Hash functions produce stable hex strings | ||
| h_int = hash_factors(f_int) | ||
| h_enum = hash_factors(f_enum) | ||
| assert isinstance(h_int, str) and len(h_int) == 64 | ||
| assert isinstance(h_enum, str) and len(h_enum) == 64 | ||
|
|
||
|
|
||
| def test_classes_are_types(): | ||
| """Types normalize to FQNs; include real vLLM types.""" | ||
| # Only classes allowed; functions/lambdas are rejected. | ||
| # Canonical form is the fully-qualified name. | ||
| assert isinstance(normalize_value(str), str) | ||
|
|
||
| class LocalDummy: | ||
| pass | ||
|
|
||
| assert endswith_fqname(LocalDummy, ".LocalDummy") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.