Add pydocstyle to the ruff rules (#52136)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Signed-off-by: Harry Mellor <hej.mellor@gmail.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
804e5377aa
commit
8c1557a79c
@@ -74,6 +74,7 @@ def compile_regex_with_timeout(fn: Callable[[str], _T], pattern: str) -> _T:
|
||||
|
||||
Raises:
|
||||
ValueError: If compilation exceeds the configured timeout.
|
||||
|
||||
"""
|
||||
timeout = envs.VLLM_REGEX_COMPILATION_TIMEOUT_S
|
||||
if timeout <= 0:
|
||||
@@ -103,13 +104,14 @@ def apply_grammar_bitmask(
|
||||
input_batch: InputBatch,
|
||||
logits: torch.Tensor,
|
||||
) -> None:
|
||||
"""
|
||||
Apply grammar bitmask to output logits of the model with xgrammar function.
|
||||
"""Apply grammar bitmask to output logits of the model with xgrammar function.
|
||||
|
||||
Args:
|
||||
scheduler_output (SchedulerOutput): The result of engine scheduling.
|
||||
grammar_output (GrammarOutput): The grammar bitmask to apply.
|
||||
input_batch (InputBatch): The input of model runner.
|
||||
logits (torch.Tensor): The output logits of model forward.
|
||||
|
||||
"""
|
||||
# Serialization of np.ndarray is much more efficient than a tensor,
|
||||
# so we receive it in that format.
|
||||
@@ -190,8 +192,7 @@ def apply_grammar_bitmask(
|
||||
|
||||
|
||||
class OutlinesVocabulary:
|
||||
"""
|
||||
Wrapper class for `outlines_core.Vocabulary`,
|
||||
"""Wrapper class for `outlines_core.Vocabulary`,
|
||||
which allows us to store a hash with the vocabulary
|
||||
"""
|
||||
|
||||
@@ -206,7 +207,7 @@ class OutlinesVocabulary:
|
||||
|
||||
|
||||
def get_outlines_cache_path() -> str:
|
||||
"""Get the context object that contains previously-computed return values"""
|
||||
"""Get the context object that contains previously-computed return values."""
|
||||
outlines_cache_dir = os.getenv("OUTLINES_CACHE_DIR")
|
||||
xdg_cache_home = os.getenv("XDG_CACHE_HOME")
|
||||
home_dir = os.path.expanduser("~")
|
||||
@@ -294,8 +295,7 @@ class OutlinesDiskCache:
|
||||
|
||||
|
||||
def get_outlines_cache():
|
||||
"""Get the Cache instance to be used for index caching"""
|
||||
|
||||
"""Get the Cache instance to be used for index caching."""
|
||||
cache_dir = get_outlines_cache_path()
|
||||
if envs.VLLM_V1_USE_OUTLINES_CACHE:
|
||||
logger.warning(
|
||||
@@ -324,6 +324,7 @@ def _reduced_vocabulary(tokenizer: TokenizerLike) -> dict[bytes, list[int]]:
|
||||
|
||||
Returns:
|
||||
A Dict of token string -> equivalent token ids
|
||||
|
||||
"""
|
||||
eos_token_id = tokenizer.eos_token_id
|
||||
|
||||
@@ -403,8 +404,7 @@ def get_outlines_vocabulary(tokenizer: TokenizerLike) -> oc.Vocabulary:
|
||||
|
||||
|
||||
def grammar_is_likely_lark(grammar_str: str) -> bool:
|
||||
"""
|
||||
Check if grammar appears to use Lark syntax.
|
||||
"""Check if grammar appears to use Lark syntax.
|
||||
|
||||
Args:
|
||||
grammar_str: Input grammar string
|
||||
@@ -417,6 +417,7 @@ def grammar_is_likely_lark(grammar_str: str) -> bool:
|
||||
True
|
||||
>>> grammar_is_likely_lark("rule ::= 'abc'")
|
||||
False
|
||||
|
||||
"""
|
||||
if not grammar_str or not isinstance(grammar_str, str):
|
||||
return False
|
||||
@@ -435,8 +436,7 @@ def grammar_is_likely_lark(grammar_str: str) -> bool:
|
||||
|
||||
|
||||
def convert_lark_to_ebnf(grammar_str: str) -> str:
|
||||
"""
|
||||
Convert a Lark grammar string to EBNF format.
|
||||
"""Convert a Lark grammar string to EBNF format.
|
||||
|
||||
EBNF reference:
|
||||
https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md
|
||||
@@ -453,6 +453,7 @@ def convert_lark_to_ebnf(grammar_str: str) -> str:
|
||||
>>> print(convert_lark_to_ebnf("rule: 'hello'"))
|
||||
root ::= rule
|
||||
rule ::= "hello"
|
||||
|
||||
"""
|
||||
if not isinstance(grammar_str, str):
|
||||
raise ValueError(f"Grammar must be a string, got {type(grammar_str)}")
|
||||
|
||||
Reference in New Issue
Block a user