A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 17, 06:45 UTC
Migrate linter from `pylint` to `ruff` (#1665)
Simon Mo committed
Nov 20, 2023 at 11:58 UTC
5ffc0d13a2d38050ba44c2efd848910d87ceb57e
45 files changed
+122
-607
.github/workflows/ruff.yml
renamed
+5
-5
@@ -1,4 +1,4 @@
1
-name: pylint
1
+name: ruff
2
3
on:
4
# Trigger the workflow on push or pull request,
@@ -11,7 +11,7 @@ on:
11
- main
12
13
jobs:
14
- pylint:
14
+ ruff:
15
runs-on: ubuntu-latest
16
strategy:
17
matrix:
@@ -25,7 +25,7 @@ jobs:
25
- name: Install dependencies
26
run: |
27
python -m pip install --upgrade pip
28
- pip install pylint==2.8.2
29
- - name: Analysing the code with pylint
28
+ pip install ruff==0.1.5
29
+ - name: Analysing the code with ruff
30
run: |
31
- pylint vllm tests
31
+ ruff vllm tests
.pylintrc
deleted
-434
@@ -1,434 +0,0 @@
1
-# This Pylint rcfile contains a best-effort configuration to uphold the
2
-# best-practices and style described in the Google Python style guide:
3
-# https://google.github.io/styleguide/pyguide.html
4
-#
5
-# Its canonical open-source location is:
6
-# https://google.github.io/styleguide/pylintrc
7
-
8
-[MASTER]
9
-
10
-# Files or directories to be skipped. They should be base names, not paths.
11
-ignore=docs
12
-
13
-# Files or directories matching the regex patterns are skipped. The regex
14
-# matches against base names, not paths.
15
-ignore-patterns=
16
-
17
-# Pickle collected data for later comparisons.
18
-persistent=no
19
-
20
-# List of plugins (as comma separated values of python modules names) to load,
21
-# usually to register additional checkers.
22
-load-plugins=
23
-
24
-# Use multiple processes to speed up Pylint.
25
-jobs=4
26
-
27
-# Allow loading of arbitrary C extensions. Extensions are imported into the
28
-# active Python interpreter and may run arbitrary code.
29
-unsafe-load-any-extension=no
30
-
31
-
32
-[MESSAGES CONTROL]
33
-
34
-# Only show warnings with the listed confidence levels. Leave empty to show
35
-# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED
36
-confidence=
37
-
38
-# Enable the message, report, category or checker with the given id(s). You can
39
-# either give multiple identifier separated by comma (,) or put this option
40
-# multiple time (only on the command line, not in the configuration file where
41
-# it should appear only once). See also the "--disable" option for examples.
42
-#enable=
43
-
44
-# Disable the message, report, category or checker with the given id(s). You
45
-# can either give multiple identifiers separated by comma (,) or put this
46
-# option multiple times (only on the command line, not in the configuration
47
-# file where it should appear only once).You can also use "--disable=all" to
48
-# disable everything first and then reenable specific checks. For example, if
49
-# you want to run only the similarities checker, you can use "--disable=all
50
-# --enable=similarities". If you want to run only the classes checker, but have
51
-# no Warning level messages displayed, use"--disable=all --enable=classes
52
-# --disable=W"
53
-disable=abstract-method,
54
- apply-builtin,
55
- arguments-differ,
56
- attribute-defined-outside-init,
57
- backtick,
58
- bad-option-value,
59
- basestring-builtin,
60
- buffer-builtin,
61
- c-extension-no-member,
62
- consider-using-enumerate,
63
- cmp-builtin,
64
- cmp-method,
65
- coerce-builtin,
66
- coerce-method,
67
- delslice-method,
68
- div-method,
69
- duplicate-code,
70
- eq-without-hash,
71
- execfile-builtin,
72
- file-builtin,
73
- filter-builtin-not-iterating,
74
- fixme,
75
- getslice-method,
76
- global-statement,
77
- hex-method,
78
- idiv-method,
79
- implicit-str-concat-in-sequence,
80
- import-error,
81
- import-self,
82
- import-star-module-level,
83
- inconsistent-return-statements,
84
- input-builtin,
85
- intern-builtin,
86
- invalid-str-codec,
87
- locally-disabled,
88
- logging-fstring-interpolation, # added by vLLM
89
- logging-not-lazy, # added by vLLM
90
- long-builtin,
91
- long-suffix,
92
- map-builtin-not-iterating,
93
- misplaced-comparison-constant,
94
- missing-class-docstring, # TODO (vLLM): enable
95
- missing-function-docstring,
96
- missing-module-docstring, # TODO (vLLM): enable
97
- metaclass-assignment,
98
- next-method-called,
99
- next-method-defined,
100
- no-absolute-import,
101
- no-else-break,
102
- no-else-continue,
103
- no-else-raise,
104
- no-else-return,
105
- no-init, # added
106
- no-member,
107
- no-name-in-module,
108
- no-self-use,
109
- nonzero-method,
110
- oct-method,
111
- old-division,
112
- old-ne-operator,
113
- old-octal-literal,
114
- old-raise-syntax,
115
- parameter-unpacking,
116
- print-statement,
117
- raising-string,
118
- range-builtin-not-iterating,
119
- raw_input-builtin,
120
- rdiv-method,
121
- reduce-builtin,
122
- relative-import,
123
- reload-builtin,
124
- round-builtin,
125
- setslice-method,
126
- signature-differs,
127
- standarderror-builtin,
128
- suppressed-message,
129
- sys-max-int,
130
- too-few-public-methods,
131
- too-many-ancestors,
132
- too-many-arguments,
133
- too-many-boolean-expressions,
134
- too-many-branches,
135
- too-many-instance-attributes,
136
- too-many-locals,
137
- too-many-nested-blocks,
138
- too-many-public-methods,
139
- too-many-return-statements,
140
- too-many-statements,
141
- trailing-newlines,
142
- unichr-builtin,
143
- unicode-builtin,
144
- unnecessary-pass,
145
- unpacking-in-except,
146
- unspecified-encoding,
147
- useless-else-on-loop,
148
- useless-object-inheritance,
149
- useless-suppression,
150
- using-cmp-argument,
151
- wrong-import-order,
152
- xrange-builtin,
153
- zip-builtin-not-iterating,
154
-
155
-
156
-[REPORTS]
157
-
158
-# Set the output format. Available formats are text, parseable, colorized, msvs
159
-# (visual studio) and html. You can also give a reporter class, eg
160
-# mypackage.mymodule.MyReporterClass.
161
-output-format=text
162
-
163
-# Tells whether to display a full report or only the messages
164
-reports=no
165
-
166
-# Python expression which should return a note less than 10 (10 is the highest
167
-# note). You have access to the variables errors warning, statement which
168
-# respectively contain the number of errors / warnings messages and the total
169
-# number of statements analyzed. This is used by the global evaluation report
170
-# (RP0004).
171
-evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
172
-
173
-# Template used to display messages. This is a python new-style format string
174
-# used to format the message information. See doc for all details
175
-#msg-template=
176
-
177
-
178
-[BASIC]
179
-
180
-# Good variable names which should always be accepted, separated by a comma
181
-good-names=main,_
182
-
183
-# Bad variable names which should always be refused, separated by a comma
184
-bad-names=
185
-
186
-# Colon-delimited sets of names that determine each other's naming style when
187
-# the name regexes allow several styles.
188
-name-group=
189
-
190
-# Include a hint for the correct naming format with invalid-name
191
-include-naming-hint=no
192
-
193
-# List of decorators that produce properties, such as abc.abstractproperty. Add
194
-# to this list to register other decorators that produce valid properties.
195
-property-classes=abc.abstractproperty,cached_property.cached_property,cached_property.threaded_cached_property,cached_property.cached_property_with_ttl,cached_property.threaded_cached_property_with_ttl
196
-
197
-# Regular expression matching correct function names
198
-function-rgx=^(?:(?P<exempt>setUp|tearDown|setUpModule|tearDownModule)|(?P<camel_case>_?[A-Z][a-zA-Z0-9]*)|(?P<snake_case>_?[a-z][a-z0-9_]*))$
199
-
200
-# Regular expression matching correct variable names
201
-variable-rgx=^[a-z][a-z0-9_]*$
202
-
203
-# Regular expression matching correct constant names
204
-const-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
205
-
206
-# Regular expression matching correct attribute names
207
-attr-rgx=^_{0,2}[a-z][a-z0-9_]*$
208
-
209
-# Regular expression matching correct argument names
210
-argument-rgx=^[a-z][a-z0-9_]*$
211
-
212
-# Regular expression matching correct class attribute names
213
-class-attribute-rgx=^(_?[A-Z][A-Z0-9_]*|__[a-z0-9_]+__|_?[a-z][a-z0-9_]*)$
214
-
215
-# Regular expression matching correct inline iteration names
216
-inlinevar-rgx=^[a-z][a-z0-9_]*$
217
-
218
-# Regular expression matching correct class names
219
-class-rgx=^_?[A-Z][a-zA-Z0-9]*$
220
-
221
-# Regular expression matching correct module names
222
-module-rgx=^(_?[a-z][a-z0-9_]*|__init__)$
223
-
224
-# Regular expression matching correct method names
225
-method-rgx=(?x)^(?:(?P<exempt>_[a-z0-9_]+__|runTest|setUp|tearDown|setUpTestCase|tearDownTestCase|setupSelf|tearDownClass|setUpClass|(test|assert)_*[A-Z0-9][a-zA-Z0-9_]*|next)|(?P<camel_case>_{0,2}[A-Z][a-zA-Z0-9_]*)|(?P<snake_case>_{0,2}[a-z][a-z0-9_]*))$
226
-
227
-# Regular expression which should only match function or class names that do
228
-# not require a docstring.
229
-no-docstring-rgx=(__.*__|main|test.*|.*test|.*Test)$
230
-
231
-# Minimum line length for functions/classes that require docstrings, shorter
232
-# ones are exempt.
233
-docstring-min-length=10
234
-
235
-
236
-[TYPECHECK]
237
-
238
-# List of decorators that produce context managers, such as
239
-# contextlib.contextmanager. Add to this list to register other decorators that
240
-# produce valid context managers.
241
-contextmanager-decorators=contextlib.contextmanager,contextlib2.contextmanager
242
-
243
-# Tells whether missing members accessed in mixin class should be ignored. A
244
-# mixin class is detected if its name ends with "mixin" (case insensitive).
245
-ignore-mixin-members=yes
246
-
247
-# List of module names for which member attributes should not be checked
248
-# (useful for modules/projects where namespaces are manipulated during runtime
249
-# and thus existing member attributes cannot be deduced by static analysis. It
250
-# supports qualified module names, as well as Unix pattern matching.
251
-ignored-modules=
252
-
253
-# List of class names for which member attributes should not be checked (useful
254
-# for classes with dynamically set attributes). This supports the use of
255
-# qualified names.
256
-ignored-classes=optparse.Values,thread._local,_thread._local
257
-
258
-# List of members which are set dynamically and missed by pylint inference
259
-# system, and so shouldn't trigger E1101 when accessed. Python regular
260
-# expressions are accepted.
261
-generated-members=
262
-
263
-
264
-[FORMAT]
265
-
266
-# Maximum number of characters on a single line.
267
-max-line-length=80
268
-
269
-# TODO(https://github.com/PyCQA/pylint/issues/3352): Direct pylint to exempt
270
-# lines made too long by directives to pytype.
271
-
272
-# Regexp for a line that is allowed to be longer than the limit.
273
-ignore-long-lines=(?x)(
274
- ^\s*(\#\ )?<?https?://\S+>?$|
275
- ^\s*(from\s+\S+\s+)?import\s+.+$)
276
-
277
-# Allow the body of an if to be on the same line as the test if there is no
278
-# else.
279
-single-line-if-stmt=yes
280
-
281
-# Maximum number of lines in a module
282
-max-module-lines=99999
283
-
284
-# String used as indentation unit. The internal Google style guide mandates 2
285
-# spaces. Google's externaly-published style guide says 4, consistent with
286
-# PEP 8. Here, we use 2 spaces, for conformity with many open-sourced Google
287
-# projects (like TensorFlow).
288
-indent-string=' '
289
-
290
-# Number of spaces of indent required inside a hanging or continued line.
291
-indent-after-paren=4
292
-
293
-# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
294
-expected-line-ending-format=
295
-
296
-
297
-[MISCELLANEOUS]
298
-
299
-# List of note tags to take in consideration, separated by a comma.
300
-notes=TODO
301
-
302
-
303
-[STRING]
304
-
305
-# This flag controls whether inconsistent-quotes generates a warning when the
306
-# character used as a quote delimiter is used inconsistently within a module.
307
-check-quote-consistency=yes
308
-
309
-
310
-[VARIABLES]
311
-
312
-# Tells whether we should check for unused import in __init__ files.
313
-init-import=no
314
-
315
-# A regular expression matching the name of dummy variables (i.e. expectedly
316
-# not used).
317
-dummy-variables-rgx=^\*{0,2}(_$|unused_|dummy_)
318
-
319
-# List of additional names supposed to be defined in builtins. Remember that
320
-# you should avoid to define new builtins when possible.
321
-additional-builtins=
322
-
323
-# List of strings which can identify a callback function by name. A callback
324
-# name must start or end with one of those strings.
325
-callbacks=cb_,_cb
326
-
327
-# List of qualified module names which can have objects that can redefine
328
-# builtins.
329
-redefining-builtins-modules=six,six.moves,past.builtins,future.builtins,functools
330
-
331
-
332
-[LOGGING]
333
-
334
-# Logging modules to check that the string format arguments are in logging
335
-# function parameter format
336
-logging-modules=logging,absl.logging,tensorflow.io.logging
337
-
338
-
339
-[SIMILARITIES]
340
-
341
-# Minimum lines number of a similarity.
342
-min-similarity-lines=4
343
-
344
-# Ignore comments when computing similarities.
345
-ignore-comments=yes
346
-
347
-# Ignore docstrings when computing similarities.
348
-ignore-docstrings=yes
349
-
350
-# Ignore imports when computing similarities.
351
-ignore-imports=no
352
-
353
-
354
-[SPELLING]
355
-
356
-# Spelling dictionary name. Available dictionaries: none. To make it working
357
-# install python-enchant package.
358
-spelling-dict=
359
-
360
-# List of comma separated words that should not be checked.
361
-spelling-ignore-words=
362
-
363
-# A path to a file that contains private dictionary; one word per line.
364
-spelling-private-dict-file=
365
-
366
-# Tells whether to store unknown words to indicated private dictionary in
367
-# --spelling-private-dict-file option instead of raising a message.
368
-spelling-store-unknown-words=no
369
-
370
-
371
-[IMPORTS]
372
-
373
-# Deprecated modules which should not be used, separated by a comma
374
-deprecated-modules=regsub,
375
- TERMIOS,
376
- Bastion,
377
- rexec,
378
- sets
379
-
380
-# Create a graph of every (i.e. internal and external) dependencies in the
381
-# given file (report RP0402 must not be disabled)
382
-import-graph=
383
-
384
-# Create a graph of external dependencies in the given file (report RP0402 must
385
-# not be disabled)
386
-ext-import-graph=
387
-
388
-# Create a graph of internal dependencies in the given file (report RP0402 must
389
-# not be disabled)
390
-int-import-graph=
391
-
392
-# Force import order to recognize a module as part of the standard
393
-# compatibility libraries.
394
-known-standard-library=
395
-
396
-# Force import order to recognize a module as part of a third party library.
397
-known-third-party=enchant, absl
398
-
399
-# Analyse import fallback blocks. This can be used to support both Python 2 and
400
-# 3 compatible code, which means that the block might have code that exists
401
-# only in one or another interpreter, leading to false positives when analysed.
402
-analyse-fallback-blocks=no
403
-
404
-
405
-[CLASSES]
406
-
407
-# List of method names used to declare (i.e. assign) instance attributes.
408
-defining-attr-methods=__init__,
409
- __new__,
410
- setUp
411
-
412
-# List of member names, which should be excluded from the protected access
413
-# warning.
414
-exclude-protected=_asdict,
415
- _fields,
416
- _replace,
417
- _source,
418
- _make
419
-
420
-# List of valid names for the first argument in a class method.
421
-valid-classmethod-first-arg=cls,
422
- class_
423
-
424
-# List of valid names for the first argument in a metaclass class method.
425
-valid-metaclass-classmethod-first-arg=mcs
426
-
427
-
428
-[EXCEPTIONS]
429
-
430
-# Exceptions that will emit a warning when being caught. Defaults to
431
-# "Exception"
432
-overgeneral-exceptions=StandardError,
433
- Exception,
434
- BaseException
benchmarks/benchmark_throughput.py
+2
-3
@@ -17,9 +17,8 @@ def sample_requests(
17
tokenizer: PreTrainedTokenizerBase,
18
fixed_output_len: Optional[int],
19
) -> List[Tuple[str, int, int]]:
20
- if fixed_output_len is not None:
21
- if fixed_output_len < 4:
22
- raise ValueError("output_len too small")
20
+ if fixed_output_len is not None and fixed_output_len < 4:
21
+ raise ValueError("output_len too small")
22
23
# Load the dataset.
24
with open(dataset_path) as f:
format.sh
+8
-8
@@ -7,7 +7,7 @@
7
# # Format files that differ from origin/main.
8
# bash format.sh
9
10
-# # Commit changed files with message 'Run yapf and pylint'
10
+# # Commit changed files with message 'Run yapf and ruff'
11
#
12
#
13
# YAPF + Clang formatter (if installed). This script formats all changed files from the last mergebase.
@@ -22,7 +22,7 @@ ROOT="$(git rev-parse --show-toplevel)"
22
builtin cd "$ROOT" || exit 1
23
24
YAPF_VERSION=$(yapf --version | awk '{print $2}')
25
-PYLINT_VERSION=$(pylint --version | head -n 1 | awk '{print $2}')
25
+RUFF_VERSION=$(ruff --version | awk '{print $2}')
26
MYPY_VERSION=$(mypy --version | awk '{print $2}')
27
28
# # params: tool name, tool version, required version
@@ -34,7 +34,7 @@ tool_version_check() {
34
}
35
36
tool_version_check "yapf" $YAPF_VERSION "$(grep yapf requirements-dev.txt | cut -d'=' -f3)"
37
-tool_version_check "pylint" $PYLINT_VERSION "$(grep "pylint==" requirements-dev.txt | cut -d'=' -f3)"
37
+tool_version_check "ruff" $RUFF_VERSION "$(grep "ruff==" requirements-dev.txt | cut -d'=' -f3)"
38
tool_version_check "mypy" "$MYPY_VERSION" "$(grep mypy requirements-dev.txt | cut -d'=' -f3)"
39
40
YAPF_FLAGS=(
@@ -95,14 +95,14 @@ echo 'vLLM yapf: Done'
95
96
# Lint specified files
97
lint() {
98
- pylint "$@"
98
+ ruff "$@"
99
}
100
101
# Lint files that differ from main branch. Ignores dirs that are not slated
102
# for autolint yet.
103
lint_changed() {
104
# The `if` guard ensures that the list of filenames is not empty, which
105
- # could cause pylint to receive 0 positional arguments, making it hang
105
+ # could cause ruff to receive 0 positional arguments, making it hang
106
# waiting for STDIN.
107
#
108
# `diff-filter=ACM` and $MERGEBASE is to ensure we only lint files that
@@ -111,13 +111,13 @@ lint_changed() {
111
112
if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then
113
git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs \
114
- pylint
114
+ ruff
115
fi
116
117
}
118
119
-# Run Pylint
120
-echo 'vLLM Pylint:'
119
+# Run Ruff
120
+echo 'vLLM Ruff:'
121
## This flag lints individual files. --files *must* be the first command line
122
## arg to use this option.
123
if [[ "$1" == '--files' ]]; then
pyproject.toml
+24
@@ -7,3 +7,27 @@ requires = [
7
"wheel",
8
]
9
build-backend = "setuptools.build_meta"
10
+
11
+[tool.ruff.lint]
12
+select = [
13
+ # pycodestyle
14
+ "E",
15
+ # Pyflakes
16
+ "F",
17
+ # pyupgrade
18
+ # "UP",
19
+ # flake8-bugbear
20
+ "B",
21
+ # flake8-simplify
22
+ "SIM",
23
+ # isort
24
+ # "I",
25
+]
26
+ignore = [
27
+ # star imports
28
+ "F405", "F403",
29
+ # lambda expression assignment
30
+ "E731",
31
+ # line too long, handled by black formatting
32
+ "E501",
33
+]
requirements-dev.txt
+1
-1
@@ -1,6 +1,6 @@
1
# formatting
2
yapf==0.32.0
3
-pylint==2.8.2
3
+ruff==0.1.5
4
5
# type checking
6
mypy==0.991
setup.py
+8
-6
@@ -75,7 +75,8 @@ def get_torch_arch_list() -> Set[str]:
75
f"Unsupported CUDA architectures ({invalid_arch_list}) are "
76
"excluded from the `TORCH_CUDA_ARCH_LIST` env variable "
77
f"({env_arch_list}). Supported CUDA architectures are: "
78
- f"{valid_archs}.")
78
+ f"{valid_archs}.",
79
+ stacklevel=2)
80
return arch_list
81
82
@@ -106,10 +107,10 @@ if not compute_capabilities:
107
# Validate the NVCC CUDA version.
108
if nvcc_cuda_version < Version("11.0"):
109
raise RuntimeError("CUDA 11.0 or higher is required to build the package.")
109
-if nvcc_cuda_version < Version("11.1"):
110
- if any(cc.startswith("8.6") for cc in compute_capabilities):
111
- raise RuntimeError(
112
- "CUDA 11.1 or higher is required for compute capability 8.6.")
110
+if (nvcc_cuda_version < Version("11.1")
111
+ and any(cc.startswith("8.6") for cc in compute_capabilities)):
112
+ raise RuntimeError(
113
+ "CUDA 11.1 or higher is required for compute capability 8.6.")
114
if nvcc_cuda_version < Version("11.8"):
115
if any(cc.startswith("8.9") for cc in compute_capabilities):
116
# CUDA 11.8 is required to generate the code targeting compute capability 8.9.
@@ -119,7 +120,8 @@ if nvcc_cuda_version < Version("11.8"):
120
# instead of 8.9.
121
warnings.warn(
122
"CUDA 11.8 or higher is required for compute capability 8.9. "
122
- "Targeting compute capability 8.0 instead.")
123
+ "Targeting compute capability 8.0 instead.",
124
+ stacklevel=2)
125
compute_capabilities = set(cc for cc in compute_capabilities
126
if not cc.startswith("8.9"))
127
compute_capabilities.add("8.0+PTX")
tests/async_engine/api_server_async_engine.py
-1
@@ -14,7 +14,6 @@ app = vllm.entrypoints.api_server.app
14
15
class AsyncLLMEngineWithStats(AsyncLLMEngine):
16
17
- # pylint: disable=redefined-outer-name
17
def __init__(self, *args, **kwargs):
18
super().__init__(*args, **kwargs)
19
self._num_aborts = 0
tests/async_engine/test_api_server.py
+2
-5
@@ -24,7 +24,6 @@ def _query_server(prompt: str) -> dict:
24
def api_server():
25
script_path = Path(__file__).parent.joinpath(
26
"api_server_async_engine.py").absolute()
27
- # pylint: disable=consider-using-with
27
uvicorn_process = subprocess.Popen([
28
sys.executable, "-u",
29
str(script_path), "--model", "facebook/opt-125m"
@@ -33,7 +32,6 @@ def api_server():
32
uvicorn_process.terminate()
33
34
36
-# pylint: disable=redefined-outer-name, unused-argument
35
def test_api_server(api_server):
36
"""
37
Run the API server and test it.
@@ -49,11 +47,10 @@ def test_api_server(api_server):
47
prompts = ["Hello world"] * 1
48
result = None
49
while not result:
52
- # pylint: disable=bare-except
50
try:
54
- for result in pool.map(_query_server, prompts):
51
+ for _ in pool.map(_query_server, prompts):
52
break
56
- except:
53
+ except Exception:
54
time.sleep(1)
55
56
# Actual tests start here
tests/conftest.py
-1
@@ -8,7 +8,6 @@ from vllm import LLM, SamplingParams
8
from vllm.transformers_utils.tokenizer import get_tokenizer
9
10
_TEST_PROMPTS = [
11
- # pylint: disable=line-too-long
11
"vLLM is a high-throughput and memory-efficient inference and serving engine for LLMs.",
12
"Briefly describe the major milestones in the development of artificial intelligence from 1950 to 2020.",
13
"Compare and contrast artificial intelligence with human intelligence in terms of processing information.",
tests/engine/test_detokenize.py
+3
-4
@@ -5,10 +5,9 @@ from transformers import AutoTokenizer
5
from vllm.transformers_utils.tokenizer import detokenize_incrementally
6
7
TRUTH = [
8
- # pylint: disable=line-too-long
9
- "Hello here, this is a simple test",
10
- "vLLM is a high-throughput and memory-efficient inference and serving engine for LLMs. It is designed to be used in production environments, where inference and serving",
11
- "我很感谢你的热情"
8
+ "Hello here, this is a simple test", # noqa: E501
9
+ "vLLM is a high-throughput and memory-efficient inference and serving engine for LLMs. It is designed to be used in production environments, where inference and serving", # noqa: E501
10
+ "我很感谢你的热情" # noqa: E501
11
]
12
TOKENIZERS = [
13
"facebook/opt-125m",
tests/kernels/test_attention.py
+1
-1
@@ -211,7 +211,7 @@ def test_paged_attention(
211
alibi_slopes,
212
)
213
else:
214
- assert False, f"Unknown version: {version}"
214
+ raise AssertionError(f"Unknown version: {version}")
215
216
# Run the reference implementation.
217
ref_output = torch.empty_like(query)
tests/samplers/test_sampler.py
+4
-5
@@ -1,4 +1,3 @@
1
-# pylint: disable=protected-access
1
import random
2
from typing import Tuple
3
from unittest.mock import patch
@@ -20,10 +19,10 @@ class MockLogitsSampler(Sampler):
19
20
def forward(self, *args, **kwargs):
21
with patch("vllm.model_executor.layers.sampler._prune_hidden_states",
23
- lambda x, y: x):
24
- with patch("vllm.model_executor.layers.sampler._get_logits",
22
+ lambda x, y: x), patch(
23
+ "vllm.model_executor.layers.sampler._get_logits",
24
lambda *args, **kwargs: self.fake_logits):
26
- return super().forward(*args, **kwargs)
25
+ return super().forward(*args, **kwargs)
26
27
28
def _prepare_test(
@@ -214,6 +213,6 @@ def test_sampler_logits_processors(seed: int):
213
sampler_output = sampler(embedding=None,
214
hidden_states=input_tensor,
215
input_metadata=input_metadata)
217
- for i, sequence_output in enumerate(sampler_output):
216
+ for _, sequence_output in enumerate(sampler_output):
217
for idx, nth_output in enumerate(sequence_output.samples):
218
assert nth_output.output_token == idx
tests/worker/test_worker.py
-1
@@ -1,4 +1,3 @@
1
-# pylint: disable=protected-access
1
import random
2
import torch
3
vllm/core/scheduler.py
+1
-1
@@ -350,7 +350,7 @@ class Scheduler:
350
elif preemption_mode == PreemptionMode.SWAP:
351
self._preempt_by_swap(seq_group, blocks_to_swap_out)
352
else:
353
- assert False, "Invalid preemption mode."
353
+ raise AssertionError("Invalid preemption mode.")
354
355
def _preempt_by_recompute(
356
self,
vllm/engine/llm_engine.py
+2
-2
@@ -125,7 +125,7 @@ class LLMEngine:
125
def _init_workers(self, distributed_init_method: str):
126
# Lazy import the Worker to avoid importing torch.cuda/xformers
127
# before CUDA_VISIBLE_DEVICES is set in the Worker
128
- from vllm.worker.worker import Worker # pylint: disable=import-outside-toplevel
128
+ from vllm.worker.worker import Worker
129
130
assert self.parallel_config.world_size == 1, (
131
"Ray is required if parallel_config.world_size > 1.")
@@ -148,7 +148,7 @@ class LLMEngine:
148
**ray_remote_kwargs):
149
# Lazy import the Worker to avoid importing torch.cuda/xformers
150
# before CUDA_VISIBLE_DEVICES is set in the Worker
151
- from vllm.worker.worker import Worker # pylint: disable=import-outside-toplevel
151
+ from vllm.worker.worker import Worker
152
153
self.workers: List[Worker] = []
154
for bundle in placement_group.bundle_specs:
vllm/engine/ray_utils.py
+1
-2
@@ -16,7 +16,6 @@ try:
16
17
def __init__(self, init_cached_hf_modules=False) -> None:
18
if init_cached_hf_modules:
19
- # pylint: disable=import-outside-toplevel
19
from transformers.dynamic_module_utils import init_hf_modules
20
init_hf_modules()
21
self.worker = None
@@ -37,7 +36,7 @@ except ImportError as e:
36
"`pip install ray pandas pyarrow`.")
37
ray = None
38
TorchDistributedWorker = None
40
- RayWorker = None # pylint: disable=invalid-name
39
+ RayWorker = None
40
41
if TYPE_CHECKING:
42
from ray.util.placement_group import PlacementGroup
vllm/entrypoints/llm.py
+8
-12
@@ -134,25 +134,21 @@ class LLM:
134
if isinstance(prompts, str):
135
# Convert a single prompt to a list.
136
prompts = [prompts]
137
- if prompts is not None and prompt_token_ids is not None:
138
- if len(prompts) != len(prompt_token_ids):
139
- raise ValueError("The lengths of prompts and prompt_token_ids "
140
- "must be the same.")
137
+ if (prompts is not None and prompt_token_ids is not None
138
+ and len(prompts) != len(prompt_token_ids)):
139
+ raise ValueError("The lengths of prompts and prompt_token_ids "
140
+ "must be the same.")
141
if sampling_params is None:
142
# Use default sampling params.
143
sampling_params = SamplingParams()
144
145
# Add requests to the engine.
146
- if prompts is not None:
147
- num_requests = len(prompts)
148
- else:
149
- num_requests = len(prompt_token_ids)
146
+ num_requests = len(prompts) if prompts is not None else len(
147
+ prompt_token_ids)
148
for i in range(num_requests):
149
prompt = prompts[i] if prompts is not None else None
152
- if prompt_token_ids is None:
153
- token_ids = None
154
- else:
155
- token_ids = prompt_token_ids[i]
150
+ token_ids = None if prompt_token_ids is None else prompt_token_ids[
151
+ i]
152
self._add_request(prompt, sampling_params, token_ids)
153
return self._run_engine(use_tqdm)
154
vllm/entrypoints/openai/api_server.py
+3
-5
@@ -55,7 +55,7 @@ def create_error_response(status_code: HTTPStatus,
55
56
57
@app.exception_handler(RequestValidationError)
58
-async def validation_exception_handler(request, exc): # pylint: disable=unused-argument
58
+async def validation_exception_handler(_, exc):
59
return create_error_response(HTTPStatus.BAD_REQUEST, str(exc))
60
61
@@ -124,10 +124,8 @@ async def check_length(
124
assert (not (prompt is None and prompt_ids is None)
125
and not (prompt is not None and prompt_ids is not None)
126
), "Either prompt or prompt_ids should be provided."
127
- if prompt_ids is not None:
128
- input_ids = prompt_ids
129
- else:
130
- input_ids = tokenizer(prompt).input_ids
127
+ input_ids = prompt_ids if prompt_ids is not None else tokenizer(
128
+ prompt).input_ids
129
token_num = len(input_ids)
130
131
if request.max_tokens is None:
vllm/model_executor/layers/activation.py
+10
-11
@@ -84,15 +84,14 @@ def get_act_fn(
84
f"Activation function {act_fn_name!r} is not supported.")
85
86
act_fn = _ACTIVATION_REGISTRY[act_fn_name]
87
- if quant_config is not None:
88
- if act_fn_name in quant_config.get_scaled_act_names():
89
- if intermediate_size is None:
90
- raise ValueError(
91
- "intermediate_size must be specified for scaled "
92
- "activation functions.")
93
- return ScaledActivation(
94
- act_fn,
95
- intermediate_size,
96
- params_dtype=torch.get_default_dtype(),
97
- )
87
+ if quant_config is not None and act_fn_name in quant_config.get_scaled_act_names(
88
+ ):
89
+ if intermediate_size is None:
90
+ raise ValueError("intermediate_size must be specified for scaled "
91
+ "activation functions.")
92
+ return ScaledActivation(
93
+ act_fn,
94
+ intermediate_size,
95
+ params_dtype=torch.get_default_dtype(),
96
+ )
97
return act_fn
vllm/model_executor/layers/attention.py
-1
@@ -18,7 +18,6 @@ _PARTITION_SIZE = 512
18
19
20
class PagedAttention(nn.Module):
21
- # pylint: disable=line-too-long
21
"""GPT-style multi-head PagedAttention.
22
23
This class takes query, key, and value tensors as input. The input tensors
vllm/model_executor/layers/quantization/awq.py
+1
-1
@@ -50,7 +50,7 @@ class AWQConfig(QuantizationConfig):
50
def get_config_filenames() -> List[str]:
51
return [
52
"quant_config.json", # E.g., casperhansen/vicuna-7b-v1.5-awq
53
- "quantize_config.json", # E.g., abhinavkulkarni/mosaicml-mpt-7b-instruct-w4-g128-awq # pylint: disable=line-too-long
53
+ "quantize_config.json", # E.g., abhinavkulkarni/mosaicml-mpt-7b-instruct-w4-g128-awq
54
]
55
56
@classmethod
vllm/model_executor/model_loader.py
+1
-1
@@ -7,7 +7,7 @@ import torch.nn as nn
7
from transformers import PretrainedConfig
8
9
from vllm.config import ModelConfig
10
-from vllm.model_executor.models import * # pylint: disable=wildcard-import
10
+from vllm.model_executor.models import *
11
from vllm.model_executor.weight_utils import (get_quant_config,
12
initialize_dummy_weights)
13
vllm/model_executor/models/aquila.py
+1
-4
@@ -261,10 +261,7 @@ class AquilaModel(nn.Module):
261
) -> torch.Tensor:
262
hidden_states = self.embed_tokens(input_ids)
263
for i in range(len(self.layers)):
264
- if cache_events is None:
265
- cache_event = None
266
- else:
267
- cache_event = cache_events[i]
264
+ cache_event = None if cache_events is None else cache_events[i]
265
layer = self.layers[i]
266
hidden_states = layer(
267
positions,
vllm/model_executor/models/baichuan.py
+1
-4
@@ -281,10 +281,7 @@ class BaiChuanModel(nn.Module):
281
hidden_states = self.embed_tokens(input_ids)
282
residual = None
283
for i in range(len(self.layers)):
284
- if cache_events is None:
285
- cache_event = None
286
- else:
287
- cache_event = cache_events[i]
284
+ cache_event = None if cache_events is None else cache_events[i]
285
layer = self.layers[i]
286
hidden_states, residual = layer(
287
positions,
vllm/model_executor/models/bloom.py
+1
-4
@@ -256,10 +256,7 @@ class BloomModel(nn.Module):
256
hidden_states = self.word_embeddings(input_ids)
257
hidden_states = self.word_embeddings_layernorm(hidden_states)
258
for i in range(len(self.h)):
259
- if cache_events is None:
260
- cache_event = None
261
- else:
262
- cache_event = cache_events[i]
259
+ cache_event = None if cache_events is None else cache_events[i]
260
layer = self.h[i]
261
hidden_states = layer(
262
position_ids,
vllm/model_executor/models/chatglm.py
+1
-4
@@ -269,10 +269,7 @@ class GLMTransformer(nn.Module):
269
cache_events: Optional[List[torch.cuda.Event]],
270
) -> torch.Tensor:
271
for i in range(self.num_layers):
272
- if cache_events is None:
273
- cache_event = None
274
- else:
275
- cache_event = cache_events[i]
272
+ cache_event = None if cache_events is None else cache_events[i]
273
layer = self.layers[i]
274
hidden_states = layer(
275
hidden_states=hidden_states,
vllm/model_executor/models/falcon.py
+1
-4
@@ -353,10 +353,7 @@ class FalconModel(nn.Module):
353
) -> torch.Tensor:
354
hidden_states = self.word_embeddings(input_ids)
355
for i in range(len(self.h)):
356
- if cache_events is None:
357
- cache_event = None
358
- else:
359
- cache_event = cache_events[i]
356
+ cache_event = None if cache_events is None else cache_events[i]
357
layer = self.h[i]
358
hidden_states = layer(
359
positions,
vllm/model_executor/models/gpt2.py
+1
-4
@@ -206,10 +206,7 @@ class GPT2Model(nn.Module):
206
hidden_states = inputs_embeds + position_embeds
207
208
for i in range(len(self.h)):
209
- if cache_events is None:
210
- cache_event = None
211
- else:
212
- cache_event = cache_events[i]
209
+ cache_event = None if cache_events is None else cache_events[i]
210
layer = self.h[i]
211
hidden_states = layer(hidden_states, kv_caches[i], input_metadata,
212
cache_event)
vllm/model_executor/models/gpt_bigcode.py
+1
-4
@@ -225,10 +225,7 @@ class GPTBigCodeModel(nn.Module):
225
hidden_states = inputs_embeds + position_embeds
226
227
for i in range(len(self.h)):
228
- if cache_events is None:
229
- cache_event = None
230
- else:
231
- cache_event = cache_events[i]
228
+ cache_event = None if cache_events is None else cache_events[i]
229
layer = self.h[i]
230
hidden_states = layer(hidden_states, kv_caches[i], input_metadata,
231
cache_event)
vllm/model_executor/models/gpt_j.py
+2
-8
@@ -147,10 +147,7 @@ class GPTJBlock(nn.Module):
147
linear_method: Optional[LinearMethodBase] = None,
148
):
149
super().__init__()
150
- if config.n_inner is None:
151
- inner_dim = 4 * config.n_embd
152
- else:
153
- inner_dim = config.n_inner
150
+ inner_dim = 4 * config.n_embd if config.n_inner is None else config.n_inner
151
self.ln_1 = nn.LayerNorm(config.n_embd, eps=config.layer_norm_epsilon)
152
self.attn = GPTJAttention(config, linear_method)
153
self.mlp = GPTJMLP(inner_dim, config, linear_method)
@@ -205,10 +202,7 @@ class GPTJModel(nn.Module):
202
) -> torch.Tensor:
203
hidden_states = self.wte(input_ids)
204
for i in range(len(self.h)):
208
- if cache_events is None:
209
- cache_event = None
210
- else:
211
- cache_event = cache_events[i]
205
+ cache_event = None if cache_events is None else cache_events[i]
206
layer = self.h[i]
207
hidden_states = layer(
208
position_ids,
vllm/model_executor/models/gpt_neox.py
+1
-4
@@ -216,10 +216,7 @@ class GPTNeoXModel(nn.Module):
216
) -> torch.Tensor:
217
hidden_states = self.embed_in(input_ids)
218
for i in range(len(self.layers)):
219
- if cache_events is None:
220
- cache_event = None
221
- else:
222
- cache_event = cache_events[i]
219
+ cache_event = None if cache_events is None else cache_events[i]
220
layer = self.layers[i]
221
hidden_states = layer(
222
position_ids,
vllm/model_executor/models/internlm.py
+1
-4
@@ -213,10 +213,7 @@ class InternLMModel(nn.Module):
213
hidden_states = self.embed_tokens(input_ids)
214
residual = None
215
for i in range(len(self.layers)):
216
- if cache_events is None:
217
- cache_event = None
218
- else:
219
- cache_event = cache_events[i]
216
+ cache_event = None if cache_events is None else cache_events[i]
217
layer = self.layers[i]
218
hidden_states, residual = layer(
219
positions,
vllm/model_executor/models/llama.py
+1
-4
@@ -253,10 +253,7 @@ class LlamaModel(nn.Module):
253
hidden_states = self.embed_tokens(input_ids)
254
residual = None
255
for i in range(len(self.layers)):
256
- if cache_events is None:
257
- cache_event = None
258
- else:
259
- cache_event = cache_events[i]
256
+ cache_event = None if cache_events is None else cache_events[i]
257
layer = self.layers[i]
258
hidden_states, residual = layer(
259
positions,
vllm/model_executor/models/mistral.py
+1
-4
@@ -248,10 +248,7 @@ class MistralModel(nn.Module):
248
hidden_states = self.embed_tokens(input_ids)
249
residual = None
250
for i in range(len(self.layers)):
251
- if cache_events is None:
252
- cache_event = None
253
- else:
254
- cache_event = cache_events[i]
251
+ cache_event = None if cache_events is None else cache_events[i]
252
layer = self.layers[i]
253
hidden_states, residual = layer(
254
positions,
vllm/model_executor/models/mpt.py
+5
-8
@@ -203,10 +203,10 @@ class MPTModel(nn.Module):
203
self.norm_f = nn.LayerNorm(config.d_model)
204
if config.no_bias:
205
for module in self.modules():
206
- if hasattr(module, "bias"):
207
- if isinstance(module.bias, nn.Parameter):
208
- # Remove the bias term in Linear and LayerNorm.
209
- module.register_parameter("bias", None)
206
+ if hasattr(module, "bias") and isinstance(
207
+ module.bias, nn.Parameter):
208
+ # Remove the bias term in Linear and LayerNorm.
209
+ module.register_parameter("bias", None)
210
211
def forward(
212
self,
@@ -218,10 +218,7 @@ class MPTModel(nn.Module):
218
) -> torch.Tensor:
219
hidden_states = self.wte(input_ids)
220
for i in range(len(self.blocks)):
221
- if cache_events is None:
222
- cache_event = None
223
- else:
224
- cache_event = cache_events[i]
221
+ cache_event = None if cache_events is None else cache_events[i]
222
block = self.blocks[i]
223
hidden_states = block(
224
position_ids,
vllm/model_executor/models/opt.py
+1
-4
@@ -257,10 +257,7 @@ class OPTDecoder(nn.Module):
257
hidden_states = inputs_embeds + pos_embeds
258
259
for i in range(len(self.layers)):
260
- if cache_events is None:
261
- cache_event = None
262
- else:
263
- cache_event = cache_events[i]
260
+ cache_event = None if cache_events is None else cache_events[i]
261
layer = self.layers[i]
262
hidden_states = layer(hidden_states, kv_caches[i], input_metadata,
263
cache_event)
vllm/model_executor/models/phi_1_5.py
+1
-4
@@ -258,10 +258,7 @@ class PhiModel(nn.Module):
258
) -> SamplerOutput:
259
hidden_states = self.embd(input_ids)
260
for i in range(self.config.num_hidden_layers):
261
- if cache_events is None:
262
- cache_event = None
263
- else:
264
- cache_event = cache_events[i]
261
+ cache_event = None if cache_events is None else cache_events[i]
262
layer = self.h[i]
263
hidden_states = layer(
264
positions,
vllm/model_executor/models/qwen.py
+1
-4
@@ -213,10 +213,7 @@ class QWenModel(nn.Module):
213
hidden_states = self.wte(input_ids)
214
residual = None
215
for i in range(len(self.h)):
216
- if cache_events is None:
217
- cache_event = None
218
- else:
219
- cache_event = cache_events[i]
216
+ cache_event = None if cache_events is None else cache_events[i]
217
layer = self.h[i]
218
hidden_states, residual = layer(
219
positions,
vllm/model_executor/models/yi.py
+1
-4
@@ -249,10 +249,7 @@ class YiModel(nn.Module):
249
hidden_states = self.embed_tokens(input_ids)
250
residual = None
251
for i in range(len(self.layers)):
252
- if cache_events is None:
253
- cache_event = None
254
- else:
255
- cache_event = cache_events[i]
252
+ cache_event = None if cache_events is None else cache_events[i]
253
layer = self.layers[i]
254
hidden_states, residual = layer(
255
positions,
vllm/model_executor/weight_utils.py
+4
-6
@@ -131,11 +131,9 @@ def prepare_hf_model_weights(
131
) -> Tuple[str, List[str], bool]:
132
# Download model weights from huggingface.
133
is_local = os.path.isdir(model_name_or_path)
134
- if use_safetensors:
135
- allow_patterns = ["*.safetensors"]
136
- else:
137
- # Some quantized models use .pt files for storing the weights.
138
- allow_patterns = ["*.bin", "*.pt"]
134
+ # Some quantized models use .pt files for storing the weights.
135
+ allow_patterns = ["*.safetensors"
136
+ ] if use_safetensors else ["*.bin", "*.pt"]
137
if not is_local:
138
# Use file lock to prevent multiple processes from
139
# downloading the same model weights at the same time.
@@ -242,7 +240,7 @@ def hf_model_weights_iterator(
240
elif use_safetensors:
241
for st_file in hf_weights_files:
242
with safe_open(st_file, framework="pt") as f:
245
- for name in f.keys():
243
+ for name in f:
244
param = f.get_tensor(name)
245
yield name, param
246
else:
vllm/transformers_utils/config.py
+1
-1
@@ -2,7 +2,7 @@ from typing import Optional
2
3
from transformers import AutoConfig, PretrainedConfig
4
5
-from vllm.transformers_utils.configs import * # pylint: disable=wildcard-import
5
+from vllm.transformers_utils.configs import *
6
7
_CONFIG_REGISTRY = {
8
"aquila": AquilaConfig,
vllm/transformers_utils/configs/mpt.py
+8
-8
@@ -62,7 +62,6 @@ class MPTConfig(PretrainedConfig):
62
fc_type: str = 'torch',
63
verbose: Optional[int] = None,
64
**kwargs: Any):
65
- # pylint: disable=line-too-long
65
"""The MPT configuration class.
66
Args:
67
d_model (int): The size of the embedding dimension of the model.
@@ -139,10 +138,10 @@ class MPTConfig(PretrainedConfig):
138
self.init_config = init_config
139
self.fc_type = fc_type
140
if verbose is not None:
142
- warnings.warn(
143
- DeprecationWarning(
144
- 'verbose argument for MPTConfig is now ignored and will be removed. Use python_log_level instead.'
145
- ))
141
+ warnings.warn(DeprecationWarning(
142
+ 'verbose argument for MPTConfig is now ignored and will be removed. Use python_log_level instead.'
143
+ ),
144
+ stacklevel=2)
145
if 'name' in kwargs:
146
del kwargs['name']
147
if 'loss_fn' in kwargs:
@@ -150,8 +149,8 @@ class MPTConfig(PretrainedConfig):
149
if self.attn_config.get('alibi', False):
150
self.learned_pos_emb = False
151
warnings.warn(
153
- f'alibi is turned on, setting `learned_pos_emb` to {self.learned_pos_emb}`'
154
- )
152
+ f'alibi is turned on, setting `learned_pos_emb` to {self.learned_pos_emb}`',
153
+ stacklevel=2)
154
super().__init__(**kwargs)
155
self._validate_config()
156
@@ -211,7 +210,8 @@ class MPTConfig(PretrainedConfig):
210
)
211
if not self.learned_pos_emb and (not self.attn_config['alibi']):
212
warnings.warn(
214
- 'Positional information not being provided to the model.')
213
+ 'Positional information not being provided to the model.',
214
+ stacklevel=2)
215
if self.fc_type == 'te' or self.ffn_config['ffn_type'] == 'te_ln_mlp':
216
try:
217
# pylint: disable=import-outside-toplevel
vllm/utils.py
+1
-1
@@ -30,7 +30,7 @@ class Counter:
30
def get_max_shared_memory_bytes(gpu: int = 0) -> int:
31
"""Returns the maximum shared memory per thread block in bytes."""
32
# https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html
33
- cudaDevAttrMaxSharedMemoryPerBlockOptin = 97 # pylint: disable=invalid-name
33
+ cudaDevAttrMaxSharedMemoryPerBlockOptin = 97
34
max_shared_mem = cuda_utils.get_device_attribute(
35
cudaDevAttrMaxSharedMemoryPerBlockOptin, gpu)
36
return int(max_shared_mem)
vllm/worker/worker.py
+1
-4
@@ -350,10 +350,7 @@ class Worker:
350
self.cache_engine.copy(blocks_to_copy)
351
issued_cache_op = True
352
353
- if issued_cache_op:
354
- cache_events = self.cache_events
355
- else:
356
- cache_events = None
353
+ cache_events = self.cache_events if issued_cache_op else None
354
355
# If there is no input, we don't need to execute the model.
356
if not seq_group_metadata_list: