Skip to content

Commit aa84d2d

Browse files
committed
Address comments
1 parent dd186a0 commit aa84d2d

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

python/src/coreai_models/export/compression.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,16 @@ def quantize_pytorch_model(
166166

167167
reset_positions = set(state_indices)
168168
for pos in reset_positions:
169-
assert pos >= 2, (
170-
"States cannot occupy the first two input positions. "
171-
"Those must be reserved for input_ids and position_ids"
172-
)
173-
assert pos < len(inputs), (
174-
f"State index out of bounds, got {pos}, while the number of inputs is {len(inputs)}"
175-
)
169+
if pos < 2:
170+
raise ValueError(
171+
"States cannot occupy the first two input positions. "
172+
"Those must be reserved for input_ids and position_ids"
173+
)
174+
if pos >= len(inputs):
175+
raise IndexError(
176+
f"State index out of bounds, got {pos}, while the number of inputs is "
177+
f"{len(inputs)}"
178+
)
176179

177180
# Match the caller's declared bound: position_ids.shape[1] <= cache_seq_len - 1
178181
# (the `seq_pos` Dim in `BaseForCausalLM.build_dynamic_shapes`).

python/src/coreai_models/models/base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@ def __post_init__(self) -> None:
6969
f"max_context_length={self.max_context_length} is too small to trace: "
7070
f"it must be at least query_len + 2 = {self.query_len + 2}."
7171
)
72-
assert self.cache_seq_len <= self.max_context_length, (
73-
"cache_seq_len must not be greater than max_context_length. Received "
74-
f"cache_seq_len = {self.cache_seq_len}, "
75-
f"max_context_length = {self.max_context_length}"
76-
)
72+
if self.cache_seq_len > self.max_context_length:
73+
raise ValueError(
74+
"cache_seq_len must not be greater than max_context_length. Received "
75+
f"cache_seq_len = {self.cache_seq_len}, "
76+
f"max_context_length = {self.max_context_length}"
77+
)
7778

7879
@property
7980
def caches_are_static(self) -> bool:

0 commit comments

Comments
 (0)