Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions common/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class ContextLengthExceededError(Exception):
pass

def validate_context_requirements(
context_len: int,
max_seq_len: int,
max_tokens: int,
cache_max_num_tokens: int = None,
max_rq_tokens: int = None,
allocation_boundary: int = None,
):
if context_len > max_seq_len:
raise ContextLengthExceededError(
f"Prompt length {context_len} is greater than max_seq_len {max_seq_len}"
)
if cache_max_num_tokens is not None and context_len + max_tokens > cache_max_num_tokens:
raise ContextLengthExceededError(
f"Prompt length {context_len} + max_tokens {max_tokens} is greater than cache size {cache_max_num_tokens}"
)