From 90f5757cb2f5b3d1ac6090f91f52504cd3443c7a Mon Sep 17 00:00:00 2001 From: Mengqing Cao Date: Mon, 13 Jan 2025 16:44:45 +0800 Subject: [PATCH] Init CI (#11) * do lint in CI Signed-off-by: MengqingCao --- .github/mergify.yml | 49 ++++++++++++++++++++++++++ .github/workflows/mypy.yaml | 60 ++++++++++++++++++++++++++++++++ .github/workflows/ruff.yml | 40 +++++++++++++++++++++ .github/workflows/shellcheck.yml | 37 ++++++++++++++++++++ .github/workflows/yapf.yml | 37 ++++++++++++++++++++ tools/mypy.sh | 1 - vllm_ascend/communicator.py | 5 ++- vllm_ascend/worker.py | 1 - 8 files changed, 225 insertions(+), 5 deletions(-) create mode 100644 .github/mergify.yml create mode 100644 .github/workflows/mypy.yaml create mode 100644 .github/workflows/ruff.yml create mode 100644 .github/workflows/shellcheck.yml create mode 100644 .github/workflows/yapf.yml diff --git a/.github/mergify.yml b/.github/mergify.yml new file mode 100644 index 0000000..bc744fe --- /dev/null +++ b/.github/mergify.yml @@ -0,0 +1,49 @@ +pull_request_rules: +- name: label-documentation + description: Automatically apply documentation label + conditions: + - or: + - files~=^[^/]+\.md$ + - files~=^docs/ + actions: + label: + add: + - documentation + +- name: label-ci-build + description: Automatically apply ci/build label + conditions: + - or: + - files~=^\.github/ + - files~=^Dockerfile + - files~=^requirements.*\.txt + - files=setup.py + actions: + label: + add: + - ci/build + + +- name: ping author on conflicts and add 'needs-rebase' label + conditions: + - conflict + - -closed + actions: + label: + add: + - needs-rebase + comment: + message: | + This pull request has merge conflicts that must be resolved before it can be + merged. Please rebase the PR, @{{author}}. + + https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork + +- name: remove 'needs-rebase' label when conflict is resolved + conditions: + - -conflict + - -closed + actions: + label: + remove: + - needs-rebase diff --git a/.github/workflows/mypy.yaml b/.github/workflows/mypy.yaml new file mode 100644 index 0000000..86d315d --- /dev/null +++ b/.github/workflows/mypy.yaml @@ -0,0 +1,60 @@ +name: mypy + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + paths: + - '**/*.py' + - '.github/workflows/mypy.yaml' + - 'tools/mypy.sh' + pull_request: + branches: + - main + # This workflow is only relevant when one of the following files changes. + # However, we have github configured to expect and require this workflow + # to run and pass before github with auto-merge a pull request. Until github + # allows more flexible auto-merge policy, we can just run this on every PR. + # It doesn't take that long to run, anyway. + paths: + - '**/*.py' + - '.github/workflows/mypy.yaml' + - 'tools/mypy.sh' + +jobs: + mypy: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12"] + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install mypy==1.11.1 + pip install types-setuptools + pip install types-PyYAML + pip install types-requests + pip install types-setuptools + sudo apt-get update + sudo apt-get install -y git gcc-12 g++-12 libnuma-dev + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10 --slave /usr/bin/g++ g++ /usr/bin/g++-12 + pip install cmake>=3.26 wheel packaging ninja "setuptools-scm>=8" numpy + - name: Download and Install vllm cpu + # TODO (cmq): clone vllm-project/vllm:main instead of cosdt/vllm:apply_plugin + run: | + git clone https://github.com/cosdt/vllm -b apply_plugin + cd vllm + pip install -r requirements-cpu.txt --extra-index-url https://download.pytorch.org/whl/cpu + VLLM_TARGET_DEVICE=cpu python setup.py install + - name: Mypy + run: | + echo "::add-matcher::.github/workflows/matchers/mypy.json" + tools/mypy.sh 1 ${{ matrix.python-version }} diff --git a/.github/workflows/ruff.yml b/.github/workflows/ruff.yml new file mode 100644 index 0000000..839c767 --- /dev/null +++ b/.github/workflows/ruff.yml @@ -0,0 +1,40 @@ +name: ruff + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + paths: + - "**/*.py" + - requirements-lint.txt + - .github/workflows/matchers/ruff.json + - .github/workflows/ruff.yml + pull_request: + branches: + - main + +jobs: + ruff: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements-lint.txt + - name: Analysing the code with ruff + run: | + echo "::add-matcher::.github/workflows/matchers/ruff.json" + ruff check --output-format github . + - name: Run isort + run: | + isort . --check-only diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 0000000..4b1587e --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,37 @@ +name: Lint shell scripts +on: + push: + branches: + - "main" + paths: + - '**/*.sh' + - '.github/workflows/shellcheck.yml' + pull_request: + branches: + - "main" + paths: + - '**/*.sh' + - '.github/workflows/shellcheck.yml' + +env: + LC_ALL: en_US.UTF-8 + +defaults: + run: + shell: bash + +permissions: + contents: read + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - name: "Checkout" + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + fetch-depth: 0 + + - name: "Check shell scripts" + run: | + tools/shellcheck.sh diff --git a/.github/workflows/yapf.yml b/.github/workflows/yapf.yml new file mode 100644 index 0000000..37df8f9 --- /dev/null +++ b/.github/workflows/yapf.yml @@ -0,0 +1,37 @@ +name: yapf + +on: + # Trigger the workflow on push or pull request, + # but only for the main branch + push: + branches: + - main + paths: + - "**/*.py" + - .github/workflows/yapf.yml + pull_request: + branches: + - main + paths: + - "**/*.py" + - .github/workflows/yapf.yml + +jobs: + yapf: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.12"] + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install yapf==0.32.0 + - name: Running yapf + run: | + yapf --diff --recursive . diff --git a/tools/mypy.sh b/tools/mypy.sh index 5c789fa..7e83aaf 100755 --- a/tools/mypy.sh +++ b/tools/mypy.sh @@ -16,6 +16,5 @@ run_mypy() { 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 diff --git a/vllm_ascend/communicator.py b/vllm_ascend/communicator.py index aa074e0..ebebf83 100644 --- a/vllm_ascend/communicator.py +++ b/vllm_ascend/communicator.py @@ -1,8 +1,7 @@ import torch import torch.distributed as dist - -from vllm.distributed.device_communicators.base_communicator import ( - CommunicatorBase) +from vllm.distributed.device_communicators.base_communicator import \ + CommunicatorBase class NPUCommunicator(CommunicatorBase): diff --git a/vllm_ascend/worker.py b/vllm_ascend/worker.py index e0ddd64..c07910f 100644 --- a/vllm_ascend/worker.py +++ b/vllm_ascend/worker.py @@ -3,7 +3,6 @@ import torch import torch.distributed - from vllm.config import ParallelConfig, VllmConfig from vllm.distributed import (ensure_model_parallel_initialized, init_distributed_environment,