Skip to content

Commit 019a9b5

Browse files
authored
Fix KVCrushAnchorPointMode::ALTERNATE conflicting with Windows headers (#2958)
## Description This PR renames the `KVCrushAnchorPointMode::ALTERNATE` enum value to `KVCrushAnchorPointMode::ALTERNATING` to resolve a naming conflict with Windows headers in newer MSVC versions. The old ALTERNATE name is retained as a deprecated alias for backward compatibility on non-Windows platforms or older MSVC versions. Ticket: CVS-175618 ## Checklist: - [x] Tests have been updated or added to cover the new code - [x] This patch fully addresses the ticket - [x] I have made corresponding changes to the documentation
1 parent b512137 commit 019a9b5

File tree

7 files changed

+26
-22
lines changed

7 files changed

+26
-22
lines changed

site/docs/concepts/optimization-techniques/kvcache-eviction-algorithm.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ CacheEvictionConfig(
101101
- `ZEROS`: All zeros pattern
102102
- `ONES`: All ones pattern
103103
- `MEAN`: Mean of indicators across blocks
104-
- `ALTERNATE`: Alternating 0-1 pattern
104+
- `ALTERNATING`: Alternating 0-1 pattern
105105

106106
### Performance Comparison on LongBench
107107

@@ -115,27 +115,27 @@ Configuration format: SnapKV budget (tokens), KVCrush budget (blocks), Anchor Po
115115
| Configuration | qasper | samsum | trec |
116116
|---------------|--------|--------|------|
117117
| **1024, 0** | 19.77 | 37.72 | 62.50 |
118-
| 768, 8, ALTERNATE | 18.79 | **`37.78`** | **`62.50`** |
118+
| 768, 8, ALTERNATING | 18.79 | **`37.78`** | **`62.50`** |
119119
| 768, 8, MEAN | 19.29 | 37.67 | **`62.50`** |
120120
| 768, 8, RANDOM | 18.95 | **`37.75`** | **`62.50`** |
121-
| 960, 2, ALTERNATE | **`19.83`** | **`37.77`** | **`62.50`** |
121+
| 960, 2, ALTERNATING | **`19.83`** | **`37.77`** | **`62.50`** |
122122
| 960, 2, MEAN | **`19.82`** | **`37.95`** | **`62.50`** |
123123
| 960, 2, RANDOM | **`20.56`** | 37.33 | **`62.50`** |
124-
| 992, 1, ALTERNATE | **`20.05`** | 37.42 | **`62.50`** |
124+
| 992, 1, ALTERNATING | **`20.05`** | 37.42 | **`62.50`** |
125125
| 992, 1, MEAN | **`19.83`** | **`37.80`** | **`62.50`** |
126126
| 992, 1, RANDOM | **`19.92`** | 37.56 | **`62.50`** |
127127
| **KVCrush - Best** | **`20.56`** | **`37.95`** | **`62.50`** |
128128

129129
| Configuration | qasper | samsum | trec |
130130
|---------------|--------|--------|------|
131131
| **512, 0** | 16.97 | 36.60 | 62.50 |
132-
| 384, 4, ALTERNATE | 16.69 | 36.18 | **`62.50`** |
132+
| 384, 4, ALTERNATING | 16.69 | 36.18 | **`62.50`** |
133133
| 384, 4, MEAN | 16.73 | **`36.91`** | **`62.50`** |
134134
| 384, 4, RANDOM | **`17.34`** | 36.24 | **`62.50`** |
135-
| 448, 2, ALTERNATE | **`17.14`** | 36.34 | **`62.50`** |
135+
| 448, 2, ALTERNATING | **`17.14`** | 36.34 | **`62.50`** |
136136
| 448, 2, MEAN | **`17.09`** | 35.99 | **`62.50`** |
137137
| 448, 2, RANDOM | 16.94 | 36.26 | **`62.50`** |
138-
| 480, 1, ALTERNATE | **`17.40`** | **`36.61`** | **`62.50`** |
138+
| 480, 1, ALTERNATING | **`17.40`** | **`36.61`** | **`62.50`** |
139139
| 480, 1, MEAN | 16.77 | 36.39 | **`62.50`** |
140140
| 480, 1, RANDOM | **`17.20`** | 36.54 | **`62.50`** |
141141
| **KVCrush - Best** | **`17.40`** | **`36.91`** | **`62.50`** |

src/cpp/include/openvino/genai/cache_eviction.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ enum class KVCrushAnchorPointMode {
3030
ONES, /**<In this mode the anchor point is a vector of 1s */
3131
MEAN, /**<In this mode the anchor point is a random binary vector of 0s and 1s, where individual values are decided
3232
based on majority value */
33-
ALTERNATE /**In this mode the anchor point is a vector of alternate 0s and 1s */
33+
ALTERNATING, /**In this mode the anchor point is a vector of alternate 0s and 1s */
34+
#if !defined(_WIN32) || !defined(_MSC_VER) || _MSC_VER <= 1942
35+
// KVCrushAnchorPointMode::ALTERNATE is conflicting with definitions in windows.h in newer MSVC versions
36+
ALTERNATE OPENVINO_ENUM_DEPRECATED("Please, use `KVCrushAnchorPointMode::ALTERNATING` instead of `KVCrushAnchorPointMode::ALTERNATE`.") = ALTERNATING /**In this mode the anchor point is a vector of alternate 0s and 1s */
37+
#endif
3438
};
3539

3640
class KVCrushConfig {
@@ -75,7 +79,7 @@ class KVCrushConfig {
7579
{KVCrushAnchorPointMode::ZEROS, "ZEROS"},
7680
{KVCrushAnchorPointMode::ONES, "ONES"},
7781
{KVCrushAnchorPointMode::MEAN, "MEAN"},
78-
{KVCrushAnchorPointMode::ALTERNATE, "ALTERNATE"},
82+
{KVCrushAnchorPointMode::ALTERNATING, "ALTERNATING"},
7983
};
8084

8185
std::ostringstream oss;

src/cpp/src/continuous_batching/kvcrush.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ std::vector<size_t> KVCrushAlgorithm::create_anchor_point_kvcrush(size_t num_tok
6969
}
7070
break;
7171
}
72-
case KVCrushAnchorPointMode::ALTERNATE:
72+
case KVCrushAnchorPointMode::ALTERNATING:
7373
for (size_t i = 0; i < m_block_size; ++i) {
7474
anchor_point[i] = i % 2;
7575
}

src/python/openvino_genai/py_openvino_genai.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ class KVCrushAnchorPointMode:
15871587
:param KVCrushAnchorPointMode.ZEROS: Vector of all zeros will be used as anchor point
15881588
:param KVCrushAnchorPointMode.ONES: Vector of all ones will be used as anchor point
15891589
:param KVCrushAnchorPointMode.MEAN: Mean of indicator feature vector to be used as anchor point
1590-
:param KVCrushAnchorPointMode.ALTERNATE: Alternating 0s and 1s will be used as anchor point
1590+
:param KVCrushAnchorPointMode.ALTERNATING: Alternating 0s and 1s will be used as anchor point
15911591
15921592
Members:
15931593
@@ -1599,14 +1599,14 @@ class KVCrushAnchorPointMode:
15991599
16001600
MEAN
16011601
1602-
ALTERNATE
1602+
ALTERNATING
16031603
"""
1604-
ALTERNATE: typing.ClassVar[KVCrushAnchorPointMode] # value = <KVCrushAnchorPointMode.ALTERNATE: 4>
1604+
ALTERNATING: typing.ClassVar[KVCrushAnchorPointMode] # value = <KVCrushAnchorPointMode.ALTERNATING: 4>
16051605
MEAN: typing.ClassVar[KVCrushAnchorPointMode] # value = <KVCrushAnchorPointMode.MEAN: 3>
16061606
ONES: typing.ClassVar[KVCrushAnchorPointMode] # value = <KVCrushAnchorPointMode.ONES: 2>
16071607
RANDOM: typing.ClassVar[KVCrushAnchorPointMode] # value = <KVCrushAnchorPointMode.RANDOM: 0>
16081608
ZEROS: typing.ClassVar[KVCrushAnchorPointMode] # value = <KVCrushAnchorPointMode.ZEROS: 1>
1609-
__members__: typing.ClassVar[dict[str, KVCrushAnchorPointMode]] # value = {'RANDOM': <KVCrushAnchorPointMode.RANDOM: 0>, 'ZEROS': <KVCrushAnchorPointMode.ZEROS: 1>, 'ONES': <KVCrushAnchorPointMode.ONES: 2>, 'MEAN': <KVCrushAnchorPointMode.MEAN: 3>, 'ALTERNATE': <KVCrushAnchorPointMode.ALTERNATE: 4>}
1609+
__members__: typing.ClassVar[dict[str, KVCrushAnchorPointMode]] # value = {'RANDOM': <KVCrushAnchorPointMode.RANDOM: 0>, 'ZEROS': <KVCrushAnchorPointMode.ZEROS: 1>, 'ONES': <KVCrushAnchorPointMode.ONES: 2>, 'MEAN': <KVCrushAnchorPointMode.MEAN: 3>, 'ALTERNATING': <KVCrushAnchorPointMode.ALTERNATING: 4>}
16101610
def __eq__(self, other: typing.Any) -> bool:
16111611
...
16121612
def __getstate__(self) -> int:

src/python/py_continuous_batching_pipeline.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,12 @@ void init_continuous_batching_pipeline(py::module_& m) {
295295
:param KVCrushAnchorPointMode.ZEROS: Vector of all zeros will be used as anchor point
296296
:param KVCrushAnchorPointMode.ONES: Vector of all ones will be used as anchor point
297297
:param KVCrushAnchorPointMode.MEAN: Mean of indicator feature vector to be used as anchor point
298-
:param KVCrushAnchorPointMode.ALTERNATE: Alternating 0s and 1s will be used as anchor point)")
298+
:param KVCrushAnchorPointMode.ALTERNATING: Alternating 0s and 1s will be used as anchor point)")
299299
.value("RANDOM", KVCrushAnchorPointMode::RANDOM)
300300
.value("ZEROS", KVCrushAnchorPointMode::ZEROS)
301301
.value("ONES", KVCrushAnchorPointMode::ONES)
302302
.value("MEAN", KVCrushAnchorPointMode::MEAN)
303-
.value("ALTERNATE", KVCrushAnchorPointMode::ALTERNATE);
303+
.value("ALTERNATING", KVCrushAnchorPointMode::ALTERNATING);
304304

305305
py::class_<KVCrushConfig>(m, "KVCrushConfig", "Configuration for KVCrush cache eviction algorithm")
306306
.def(py::init<>(), "Default constructor")

tests/cpp/kvcrush.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ TEST_F(KVCrushAlgorithmTest, CreateAnchorPointRandomTest) {
144144
EXPECT_EQ(count_zeros + count_ones, anchor_point.size()) << "All values should be either 0 or 1";
145145
}
146146

147-
// Test create_anchor_point_kvcrush with ALTERNATE mode
147+
// Test create_anchor_point_kvcrush with ALTERNATING mode
148148
TEST_F(KVCrushAlgorithmTest, CreateAnchorPointAlternateTest) {
149149
// Setup using helper function
150-
auto anchor_point = setup_anchor_points(KVCrushAnchorPointMode::ALTERNATE, 16);
150+
auto anchor_point = setup_anchor_points(KVCrushAnchorPointMode::ALTERNATING, 16);
151151

152152
// Verify
153153
EXPECT_EQ(anchor_point.size(), m_block_size);
154154

155-
// In ALTERNATE mode, we expect alternating blocks to be selected
155+
// In ALTERNATING mode, we expect alternating blocks to be selected
156156
// We should have non-zero values at regular intervals
157157
bool found_pattern = false;
158158
for (size_t i = 0; i < anchor_point.size(); i += m_block_size) {

tests/python_tests/test_kv_cache_eviction/test_kv_cache_eviction_2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727

2828

2929
OPTIMAL_KVCRUSH_CONFIGS = {
30-
"samsum": (768, 8, KVCrushAnchorPointMode.ALTERNATE),
31-
"trec": (960, 2, KVCrushAnchorPointMode.ALTERNATE),
32-
"qasper": (960, 2, KVCrushAnchorPointMode.ALTERNATE)
30+
"samsum": (768, 8, KVCrushAnchorPointMode.ALTERNATING),
31+
"trec": (960, 2, KVCrushAnchorPointMode.ALTERNATING),
32+
"qasper": (960, 2, KVCrushAnchorPointMode.ALTERNATING)
3333
}
3434

3535

0 commit comments

Comments
 (0)