Skip to content

Commit

Permalink
Lint new versions
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosv committed Sep 23, 2024
1 parent 9521995 commit ae3bd34
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pdl/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def accumulator(self, q):
)


def write_log( # pylint: disable=too-many-arguments
def write_log( # pylint: disable=too-many-arguments,too-many-positional-arguments
log, index, question, truth, answer, solution, document, exc
):
log.write("\n\n------------------------\n")
Expand Down
45 changes: 22 additions & 23 deletions pdl/pdl_ast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""PDL programs are represented by the Pydantic data structure defined in this file.
"""


from enum import StrEnum
from typing import Any, Literal, Optional, TypeAlias, TypedDict, Union

Expand Down Expand Up @@ -353,7 +352,7 @@ class MessageBlock(Block):
"""Create a message."""

kind: Literal[BlockKind.MESSAGE] = BlockKind.MESSAGE
role: RoleType
role: RoleType # type: ignore
"""Role of associated to the message."""
content: "BlocksType"
"""Content of the message."""
Expand Down Expand Up @@ -602,32 +601,32 @@ def set_default_granite_model_parameters(
if parameters is None:
parameters = {}
if "decoding_method" not in parameters:
parameters[
"decoding_method"
] = DECODING_METHOD # pylint: disable=attribute-defined-outside-init
parameters["decoding_method"] = (
DECODING_METHOD # pylint: disable=attribute-defined-outside-init
)
if "max_tokens" in parameters and parameters["max_tokens"] is None:
parameters[
"max_tokens"
] = MAX_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
parameters["max_tokens"] = (
MAX_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
)
if "min_new_tokens" not in parameters:
parameters[
"min_new_tokens"
] = MIN_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
parameters["min_new_tokens"] = (
MIN_NEW_TOKENS # pylint: disable=attribute-defined-outside-init
)
if "repetition_penalty" not in parameters:
parameters[
"repetition_penalty"
] = REPETITION_PENATLY # pylint: disable=attribute-defined-outside-init
parameters["repetition_penalty"] = (
REPETITION_PENATLY # pylint: disable=attribute-defined-outside-init
)
if parameters["decoding_method"] == "sample":
if "temperature" not in parameters:
parameters[
"temperature"
] = TEMPERATURE_SAMPLING # pylint: disable=attribute-defined-outside-init
parameters["temperature"] = (
TEMPERATURE_SAMPLING # pylint: disable=attribute-defined-outside-init
)
if "top_k" not in parameters:
parameters[
"top_k"
] = TOP_K_SAMPLING # pylint: disable=attribute-defined-outside-init
parameters["top_k"] = (
TOP_K_SAMPLING # pylint: disable=attribute-defined-outside-init
)
if "top_p" not in parameters:
parameters[
"top_p"
] = TOP_P_SAMPLING # pylint: disable=attribute-defined-outside-init
parameters["top_p"] = (
TOP_P_SAMPLING # pylint: disable=attribute-defined-outside-init
)
return parameters
3 changes: 1 addition & 2 deletions pdl/pdl_compilers/to_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@

class Re(ABC):
@abstractmethod
def to_re(self) -> str:
...
def to_re(self) -> str: ...


class ReEmpty(Re):
Expand Down
6 changes: 3 additions & 3 deletions pdl/pdl_dumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ def block_to_dict(block: pdl_ast.BlockType) -> int | float | str | dict[str, Any
def blocks_to_dict(
blocks: BlocksType,
) -> int | float | str | dict[str, Any] | list[int | float | str | dict[str, Any]]:
result: int | float | str | dict[str, Any] | list[
int | float | str | dict[str, Any]
]
result: (
int | float | str | dict[str, Any] | list[int | float | str | dict[str, Any]]
)
if not isinstance(blocks, str) and isinstance(blocks, Sequence):
result = [block_to_dict(block) for block in blocks]
else:
Expand Down
4 changes: 2 additions & 2 deletions pdl/pdl_llms.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def get_model() -> BamClient:
return BamModel.bam_client

@staticmethod
def generate_text( # pylint: disable=too-many-arguments
def generate_text( # pylint: disable=too-many-arguments,too-many-positional-arguments
model_id: str,
prompt_id: Optional[str],
model_input: Optional[str],
Expand All @@ -69,7 +69,7 @@ def generate_text( # pylint: disable=too-many-arguments
return {"role": None, "content": text}

@staticmethod
def generate_text_stream( # pylint: disable=too-many-arguments
def generate_text_stream( # pylint: disable=too-many-arguments,too-many-positional-arguments
model_id: str,
prompt_id: Optional[str],
model_input: Optional[str],
Expand Down
14 changes: 7 additions & 7 deletions pdl/pdl_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def schedule(
) -> list[GeneratorReturnT]:
global _LAST_ROLE # pylint: disable= global-statement
todo: list[tuple[int, Generator[YieldMessage, Any, GeneratorReturnT], Any]]
todo_next: list[
tuple[int, Generator[YieldMessage, Any, GeneratorReturnT], Any]
] = []
todo_next: list[tuple[int, Generator[YieldMessage, Any, GeneratorReturnT], Any]] = (
[]
)
done: list[Optional[GeneratorReturnT]]
todo = [(i, gen, None) for i, gen in enumerate(generators)]
done = [None for _ in generators]
Expand All @@ -106,10 +106,10 @@ def schedule(
try:
msg = gen.send(v)
match msg:
case ModelYieldResultMessage(
result=result
) | CodeYieldResultMessage(result=result) | YieldResultMessage(
result=result
case (
ModelYieldResultMessage(result=result)
| CodeYieldResultMessage(result=result)
| YieldResultMessage(result=result)
):
if msg.color is None:
text = stringify(result)
Expand Down
8 changes: 5 additions & 3 deletions pdl/pdl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ def messages_to_str(messages: Messages) -> str:
# TODO
return "".join(
[
msg["content"]
if msg["role"] is None
else f"<|{msg['role']}|>{msg['content']}"
(
msg["content"]
if msg["role"] is None
else f"<|{msg['role']}|>{msg['content']}"
)
for msg in messages
]
)

0 comments on commit ae3bd34

Please sign in to comment.