Skip to content

Commit e8180b0

Browse files
authored
fix pylint (#2321)
1 parent c331589 commit e8180b0

36 files changed

+97
-97
lines changed

src/mindnlp/diffusers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
)
99

1010
# Setup backward compatibility: apply patches
11+
# pylint: disable=wrong-import-position
1112
from .patch.diffusers import setup_diffusers_module
1213
setup_diffusers_module()

src/mindnlp/inference/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .llm import LLM
2-
from .sampling_params import SamplingParams
2+
from .sampling_params import SamplingParams

src/mindnlp/inference/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ def __post_init__(self):
2323
assert 1 <= self.tensor_parallel_size <= 8
2424
self.hf_config = AutoConfig.from_pretrained(self.model)
2525
self.max_model_len = min(self.max_model_len, self.hf_config.max_position_embeddings)
26-
assert self.max_num_batched_tokens >= self.max_model_len
26+
assert self.max_num_batched_tokens >= self.max_model_len

src/mindnlp/inference/engine/block_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ def may_append(self, seq: Sequence):
109109
last_block.update(h, token_ids)
110110
self.hash_to_block_id[h] = last_block.block_id
111111
else:
112-
assert last_block.hash == -1
112+
assert last_block.hash == -1

src/mindnlp/inference/engine/llm_engine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ def generate(
9494
outputs = [{"text": self.tokenizer.decode(token_ids), "token_ids": token_ids} for token_ids in outputs]
9595
if use_tqdm:
9696
pbar.close()
97-
return outputs
97+
return outputs

src/mindnlp/inference/engine/model_runner.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import os
22
import pickle
3-
import mindtorch
4-
import mindtorch.distributed as dist
53
from multiprocessing.synchronize import Event
64
from multiprocessing.shared_memory import SharedMemory
5+
import mindtorch
6+
import mindtorch.distributed as dist
77

88
from ..config import Config
99
from ..engine.sequence import Sequence
@@ -156,7 +156,7 @@ def prepare_prefill(self, seqs: list[Sequence]):
156156
if i != seq.num_blocks - 1:
157157
end = start + self.block_size
158158
else:
159-
end = start + seq.last_block_num_tokens
159+
end = start + seq.last_block_num_tokens
160160
slot_mapping.extend(list(range(start, end)))
161161
if cu_seqlens_k[-1] > cu_seqlens_q[-1]: # prefix cache
162162
block_tables = self.prepare_block_tables(seqs)
@@ -255,4 +255,4 @@ def capture_cudagraph(self):
255255
context_lens=context_lens,
256256
block_tables=block_tables,
257257
outputs=outputs,
258-
)
258+
)

src/mindnlp/inference/engine/scheduler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ def postprocess(self, seqs: list[Sequence], token_ids: list[int]) -> list[bool]:
6868
if (not seq.ignore_eos and token_id == self.eos) or seq.num_completion_tokens == seq.max_tokens:
6969
seq.status = SequenceStatus.FINISHED
7070
self.block_manager.deallocate(seq)
71-
self.running.remove(seq)
71+
72+
self.running.remove(seq)

src/mindnlp/inference/engine/sequence.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,4 @@ def __setstate__(self, state):
8080
if self.num_completion_tokens == 0:
8181
self.token_ids = state[-1]
8282
else:
83-
self.last_token = state[-1]
83+
self.last_token = state[-1]

src/mindnlp/inference/layers/activation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
class SiluAndMul(nn.Module):
77

88
def __init__(self):
9-
super().__init__()
9+
super().__init__() # pylint: disable=useless-parent-delegation
1010

1111
@mindtorch.compile
1212
def forward(self, x: mindtorch.Tensor) -> mindtorch.Tensor:
1313
x, y = x.chunk(2, -1)
14-
return F.silu(x) * y
14+
return F.silu(x) * y

src/mindnlp/inference/layers/attention.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import mindtorch
22
from mindtorch import nn
3-
import triton
4-
import triton.language as tl
53

64
from ..utils.context import get_context
75

86

97
def store_kvcache(key: mindtorch.Tensor, value: mindtorch.Tensor, k_cache: mindtorch.Tensor, v_cache: mindtorch.Tensor, slot_mapping: mindtorch.Tensor):
8+
# pylint: disable=undefined-variable
9+
# These are conditionally imported from flash_attn or other backends
1010
N, num_heads, head_dim = key.shape
1111
D = num_heads * head_dim
1212
assert key.stride(-1) == 1 and value.stride(-1) == 1
@@ -40,12 +40,15 @@ def forward(self, q: mindtorch.Tensor, k: mindtorch.Tensor, v: mindtorch.Tensor)
4040
if context.is_prefill:
4141
if context.block_tables is not None: # prefix cache
4242
k, v = k_cache, v_cache
43+
# pylint: disable=undefined-variable
4344
o = flash_attn_varlen_func(q, k, v,
4445
max_seqlen_q=context.max_seqlen_q, cu_seqlens_q=context.cu_seqlens_q,
4546
max_seqlen_k=context.max_seqlen_k, cu_seqlens_k=context.cu_seqlens_k,
4647
softmax_scale=self.scale, causal=True, block_table=context.block_tables)
4748
else: # decode
48-
o = flash_attn_with_kvcache(q.unsqueeze(1), k_cache, v_cache,
49-
cache_seqlens=context.context_lens, block_table=context.block_tables,
49+
# flash_attn_with_kvcache is conditionally imported from flash_attn
50+
# pylint: disable=undefined-variable
51+
o = flash_attn_with_kvcache(q.unsqueeze(1), k_cache, v_cache, # noqa: F821
52+
cache_seqlens=context.context_lens, block_table=context.block_tables,
5053
softmax_scale=self.scale, causal=True)
51-
return o
54+
return o

0 commit comments

Comments
 (0)