-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: add ruff and resolve issue #2262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d12f426
to
790082b
Compare
I'm fine moving to ruff. But seeing integration tests failure means something very wrong has happened. |
05be40f
to
634e958
Compare
25452f6
to
e216e53
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot.
A few places I'm confused by the changes asked by ruff.
We could merge as-is if necessary, mostly nits.
|
||
def is_fbgemm_gpu_available(): | ||
try: | ||
return importlib.util.find_spec("fbgemm_gpu.experimental.gen_ai") is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale behind this change ?
I find it must less clear in intent. If ruff complains there must be a good reason behind it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a lint from Pyflakes for unused-import
https://docs.astral.sh/ruff/rules/unused-import/
@@ -0,0 +1,56 @@ | |||
import torch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this file coming from ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this resolve a Pyflakes issue of undefined-name
for the torch_snr_error
function used in server/text_generation_server/layers/gptq/quantize.py
. This file adds torch_snr_error
as copied from openppl-public/ppq
@@ -2,12 +2,13 @@ | |||
import math | |||
import torch | |||
from torch import nn | |||
from loguru import logger | |||
|
|||
# Inverse dim formula to find dim based on number of rotations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ooo stray comment. removed, thanks!
@@ -69,12 +69,12 @@ def load(config, prefix: str, weights): | |||
|
|||
# GPTQ,AWQ,EETQ don't quantize heads (nor embeddings) | |||
if config.quantize in ["gptq", "awq", "eetq", "marlin"]: | |||
quantize = None | |||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels wrong. We really want to set quantize=None in each of these I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a lint for unused-variable
as quantize
is set but never used in this function.
reverted the change but i'm not sure if this check is needed..
@danieldk is there a case we need the quantize
variable?
@@ -523,7 +528,7 @@ def get_model( | |||
dtype=dtype, | |||
trust_remote_code=trust_remote_code, | |||
) | |||
elif model_type == MAMBA: | |||
elif model_type == ModelType.MAMBA: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep the global hack personally.
This is just unecessary indirection to me. Pre-existing code is also indirection compared to pure string comparison, but the reason was to make sure we keep documenting supported models correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is related to the undefined-name
lint, since ruff could not determine that the variables exist.
I agree this adds unnecessary complexity, just reverted to prefer the global variables and added # ruff: noqa: F821
to the top of the file to avoid checking this specific lint.
@@ -233,7 +233,7 @@ def filter(self, request_ids: List[int]) -> Optional["CausalLMBatch"]: | |||
] | |||
|
|||
# Ensure that past_key_values tensors can be updated in-place | |||
if type(self.past_key_values[0]) == tuple: | |||
if isinstance(self.past_key_values[0], tuple): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
type(xxX) == tuple was definitely intended here, ti's not a rookie mistake.
It's because xxx can be an instance of tuple, yet not a tuple.
I don't remember specificially the issue at hand, but I'd rather trust our past selves than the linter here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh great catch!!
It seems that a variable can be an instance of a tuple
via inheritance which would return True, even when its not a base tuple
example repro below
class CustomTuple(tuple):
pass
ct = CustomTuple([1, 2, 3])
print(type(ct) == tuple) # False
print(isinstance(ct, tuple)) # True
reverted isinstance
changes and opted to replace the ==
with is
to make the linter happy.
**This should be equivalent, is
checks for object identity where ==
checks for value, and in the case of built-in types this will be the same.
@@ -39,6 +39,12 @@ | |||
from transformers.activations import ACT2FN | |||
from transformers.configuration_utils import PretrainedConfig | |||
|
|||
if SYSTEM == "rocm": | |||
try: | |||
from vllm import _custom_C |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this coming from ?
This doesn'tseem to be linked to ruff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is related to a undefined-name
lint, _custom_C
is used in the DeepseekV2MLP.forward
call but was not imported/defined
@@ -45,6 +45,15 @@ | |||
SpeculativeHead, | |||
) | |||
|
|||
# copied from https://github.com/huggingface/transformers/blob/cd4584e3c809bb9e1392ccd3fe38b40daba5519a/src/transformers/models/t5/modeling_t5.py#L1316 | |||
# Warning message for FutureWarning: head_mask was separated into two input args - head_mask, decoder_head_mask | |||
__HEAD_MASK_WARNING_MSG = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
???? Why do we need this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is also a undefined-name
lint, __HEAD_MASK_WARNING_MSG
is called as a warning in T5ForConditionalGeneration.forward
however I'm not sure we need this warning... leaving for now but happy to remove
This PR adds ruff linting to TGI and adds ruff to the pre-commit hook