Skip to content
This repository has been archived by the owner on Feb 18, 2025. It is now read-only.

[Tool] Add format tools and execute format #10

Merged
merged 6 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/actionlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Lint GitHub Actions workflows
on:
push:
branches:
- "main"
paths:
- '.github/workflows/*.ya?ml'
- '.github/workflows/actionlint.*'
- '.github/workflows/matchers/actionlint.json'
pull_request:
branches:
- "main"
paths:
- '.github/workflows/*.ya?ml'
- '.github/workflows/actionlint.*'
- '.github/workflows/matchers/actionlint.json'

env:
LC_ALL: en_US.UTF-8

defaults:
run:
shell: bash

permissions:
contents: read

jobs:
actionlint:
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0

- name: "Run actionlint"
run: |
echo "::add-matcher::.github/workflows/matchers/actionlint.json"
tools/actionlint.sh -color
17 changes: 17 additions & 0 deletions .github/workflows/matchers/actionlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "actionlint",
"pattern": [
{
"regexp": "^(?:\\x1b\\[\\d+m)?(.+?)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*:(?:\\x1b\\[\\d+m)*(\\d+)(?:\\x1b\\[\\d+m)*: (?:\\x1b\\[\\d+m)*(.+?)(?:\\x1b\\[\\d+m)* \\[(.+?)\\]$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
]
}
]
}
16 changes: 16 additions & 0 deletions .github/workflows/matchers/mypy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"problemMatcher": [
{
"owner": "mypy",
"pattern": [
{
"regexp": "^(.+):(\\d+):\\s(error|warning):\\s(.+)$",
"file": 1,
"line": 2,
"severity": 3,
"message": 4
}
]
}
]
}
17 changes: 17 additions & 0 deletions .github/workflows/matchers/ruff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"problemMatcher": [
{
"owner": "ruff",
"pattern": [
{
"regexp": "^(.+?):(\\d+):(\\d+): (\\w+): (.+)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ __pycache__/

# egg-info
vllm_ascend.egg-info/

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Linting
actionlint
shellcheck*/
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,3 @@ bash format.sh
# 3. Commit changed files with message 'Run yapf and ruff'
git commit -m "Run yapf and ruff"
```

> [!NOTE]
> The warning "F401 `torch_npu` imported but unused" doesn't matter because the api `torch.npu` will call this library indirectly while there are not `torch_npu` in the codes explicitly.
1 change: 0 additions & 1 deletion examples/offline_inference_audio_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"""

from transformers import AutoTokenizer

from vllm import LLM, SamplingParams
from vllm.assets.audio import AudioAsset
from vllm.utils import FlexibleArgumentParser
Expand Down
14 changes: 7 additions & 7 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ISORT_VERSION=$(isort --vn)
CLANGFORMAT_VERSION=$(clang-format --version | awk '{print $3}')
SPHINX_LINT_VERSION=$(sphinx-lint --version | awk '{print $2}')

# # params: tool name, tool version, required version
# params: tool name, tool version, required version
tool_version_check() {
expected=$(grep "$1" requirements-lint.txt | cut -d'=' -f3)
if [[ "$2" != "$expected" ]]; then
Expand Down Expand Up @@ -112,9 +112,9 @@ fi
echo 'vLLM yapf: Done'

# Run mypy
# echo 'vLLM mypy:'
# tools/mypy.sh
# echo 'vLLM mypy: Done'
echo 'vLLM mypy:'
tools/mypy.sh
echo 'vLLM mypy: Done'


# If git diff returns a file that is in the skip list, the file may be checked anyway:
Expand Down Expand Up @@ -316,6 +316,6 @@ else
echo "✨🎉 Format check passed! Congratulations! 🎉✨"
fi

echo 'vLLM sphinx-lint:'
tools/sphinx-lint.sh
echo 'vLLM sphinx-lint: Done'
# echo 'vLLM sphinx-lint:'
# tools/sphinx-lint.sh
# echo 'vLLM sphinx-lint: Done'
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mypy]
; warn_return_any = True
warn_unused_configs = True

; Suppress all missing import errors from torch_npu for mypy.
[mypy-torch_npu.*]
ignore_missing_imports = True

[mypy-transformers.*]
ignore_missing_imports = True
26 changes: 14 additions & 12 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from typing import Dict, List
from typing import List

from setuptools import setup

ROOT_DIR = os.path.dirname(__file__)
Expand All @@ -8,6 +9,7 @@
def get_path(*filepath) -> str:
return os.path.join(ROOT_DIR, *filepath)


def get_requirements() -> List[str]:
"""Get Python package dependencies from requirements.txt."""

Expand All @@ -23,25 +25,25 @@ def _read_requirements(filename: str) -> List[str]:
else:
resolved_requirements.append(line)
return resolved_requirements

try:
requirements = _read_requirements("requirements.txt")
except ValueError:
print("Failed to read requirements.txt in vllm_ascend.")
return requirements


setup(name='vllm_ascend',
version='0.1',
packages=['vllm_ascend'],
install_requires=get_requirements(),
extras_require={
setup(
name='vllm_ascend',
version='0.1',
packages=['vllm_ascend'],
install_requires=get_requirements(),
extras_require={
"tensorizer": ["tensorizer>=2.9.0"],
"runai": ["runai-model-streamer", "runai-model-streamer-s3", "boto3"],
"audio": ["librosa", "soundfile"], # Required for audio processing
"video": ["decord"] # Required for video processing
},
entry_points={
'vllm.platform_plugins':
["ascend_plugin = vllm_ascend:register"]
})
},
entry_points={
'vllm.platform_plugins': ["ascend_plugin = vllm_ascend:register"]
})
13 changes: 13 additions & 0 deletions tools/actionlint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

if command -v actionlint &> /dev/null; then
actionlint "$@"
exit 0
elif [ -x ./actionlint ]; then
./actionlint "$@"
exit 0
fi

# download a binary to the current directory - v1.7.3
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/aa0a7be8e566b096e64a5df8ff290ec24fa58fbc/scripts/download-actionlint.bash)
./actionlint "$@"
14 changes: 14 additions & 0 deletions tools/check_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Checks whether the repo is clean and whether tags are available (necessary to correctly produce vllm version at build time)

if ! git diff --quiet; then
echo "Repo is dirty" >&2

exit 1
fi

if ! git describe --tags; then
echo "No tags are present. Is this a shallow clone? git fetch --unshallow --tags" >&2

exit 1
fi
21 changes: 21 additions & 0 deletions tools/mypy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

CI=${1:-0}
PYTHON_VERSION=${2:-3.9}

if [ "$CI" -eq 1 ]; then
set -e
fi

run_mypy() {
echo "Running mypy on $1"
if [ "$CI" -eq 1 ] && [ -z "$1" ]; then
mypy --python-version "${PYTHON_VERSION}" "$@"
return
fi
mypy --follow-imports skip --python-version "${PYTHON_VERSION}" "$@"
}

run_mypy # Note that this is less strict than CI
run_mypy vllm_ascend
run_mypy examples
15 changes: 15 additions & 0 deletions tools/png-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# Ensure that *.excalidraw.png files have the excalidraw metadata
# embedded in them. This ensures they can be loaded back into
# the tool and edited in the future.

find . -iname '*.excalidraw.png' | while read -r file; do
if git check-ignore -q "$file"; then
continue
fi
if ! grep -q "excalidraw+json" "$file"; then
echo "$file was not exported from excalidraw with 'Embed Scene' enabled."
exit 1
fi
done
24 changes: 24 additions & 0 deletions tools/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash
set -e

scversion="stable"

if [ -d "shellcheck-${scversion}" ]; then
PATH="$PATH:$(pwd)/shellcheck-${scversion}"
export PATH
fi

if ! [ -x "$(command -v shellcheck)" ]; then
if [ "$(uname -s)" != "Linux" ] || [ "$(uname -m)" != "x86_64" ]; then
echo "Please install shellcheck: https://github.com/koalaman/shellcheck?tab=readme-ov-file#installing"
exit 1
fi

# automatic local install if linux x86_64
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv
PATH="$PATH:$(pwd)/shellcheck-${scversion}"
export PATH
fi

# TODO - fix warnings in .buildkite/run-amd-test.sh
find . -name "*.sh" -not -path "./.buildkite/run-amd-test.sh" -print0 | xargs -0 -I {} sh -c 'git check-ignore -q "{}" || shellcheck "{}"'
3 changes: 3 additions & 0 deletions tools/sphinx-lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

sphinx-lint --disable trailing-whitespace,missing-final-newline docs
9 changes: 5 additions & 4 deletions vllm_ascend/attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import torch

try:
import torch_npu
import torch_npu # noqa: F401
except ImportError:
print("Failed to import torch_npu")
print("Failed to import torch_npu.")

from vllm.attention.backends.abstract import (AttentionBackend, AttentionImpl,
AttentionMetadata, AttentionType)
Expand Down Expand Up @@ -375,15 +375,16 @@ def _add_seq_group(
# TODO(sang): Combine chunked prefill and prefix caching by
# only allowing multiple of block_size chunk size.
# NOTE: This only works for oooooooxxx style attention.
block_table = []
block_table: List[int] = []
prefix_cache_hit = any([
inter_data.prefix_cache_hit
for inter_data in self.input_builder.inter_data_list
])
if prefix_cache_hit:
# NOTE(woosuk): For flash-attn, the block table should
# include the entries for the incoming prefill tokens.
block_table = block_tables[seq_id]
if block_tables is not None:
block_table = block_tables[seq_id]
elif ((chunked_prefill_enabled or not is_prompt)
and block_tables is not None):
if curr_sliding_window_block == 0:
Expand Down
Loading
Loading