From b789f52b0fc51b8fd35c434650d6bce5318cf0fd Mon Sep 17 00:00:00 2001 From: wejoncy Date: Fri, 20 Sep 2024 22:09:18 -0700 Subject: [PATCH 1/2] publish ci fix rope --- .github/workflows/publish.yml | 111 +++++++++++++++++++ .github/workflows/scripts/build.sh | 19 ++++ .github/workflows/scripts/create_release.js | 20 ++++ .github/workflows/scripts/cuda-install.sh | 23 ++++ .github/workflows/scripts/env.sh | 56 ++++++++++ .github/workflows/scripts/pytorch-install.sh | 15 +++ pyproject.toml | 2 +- requirements.txt | 2 +- vptq/__init__.py | 2 +- vptq/app.py | 5 + vptq/layers/__init__.py | 6 + 11 files changed, 258 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/publish.yml create mode 100644 .github/workflows/scripts/build.sh create mode 100644 .github/workflows/scripts/create_release.js create mode 100644 .github/workflows/scripts/cuda-install.sh create mode 100644 .github/workflows/scripts/env.sh create mode 100644 .github/workflows/scripts/pytorch-install.sh create mode 100644 vptq/layers/__init__.py diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e0b768a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,111 @@ +# this workflow is refered from vllm/.github/workflows/publish.yml +# This workflow will upload a Python Package to Release asset +# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions + +name: Create Release + +on: + push: + tags: + - v* + +# Needed to create release and upload assets +permissions: + contents: write + +jobs: + release: + # Retrieve tag and create release + name: Create Release + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Extract branch info + shell: bash + run: | + echo "release_tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Create Release + id: create_release + uses: "actions/github-script@v6" + env: + RELEASE_TAG: ${{ env.release_tag }} + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + script: | + const script = require('.github/workflows/scripts/create_release.js') + await script(github, context, core) + + wheel: + name: Build Wheel + runs-on: ${{ matrix.os }} + needs: release + + strategy: + fail-fast: false + matrix: + os: ['ubuntu-20.04'] + python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] + pytorch-version: ['2.4.0'] # Must be the most recent version that meets requirements-cuda.txt. + cuda-version: ['12.1'] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup ccache + uses: hendrikmuhs/ccache-action@v1.2 + with: + create-symlink: true + key: ${{ github.job }}-${{ matrix.python-version }}-${{ matrix.cuda-version }} + + - name: Set up Linux Env + if: ${{ runner.os == 'Linux' }} + run: | + bash -x .github/workflows/scripts/env.sh + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install CUDA ${{ matrix.cuda-version }} + run: | + bash -x .github/workflows/scripts/cuda-install.sh ${{ matrix.cuda-version }} ${{ matrix.os }} + + - name: Install PyTorch ${{ matrix.pytorch-version }} with CUDA ${{ matrix.cuda-version }} + run: | + bash -x .github/workflows/scripts/pytorch-install.sh ${{ matrix.python-version }} ${{ matrix.pytorch-version }} ${{ matrix.cuda-version }} + + - name: Build wheel + shell: bash + env: + CMAKE_BUILD_TYPE: Release # do not compile with debug symbol to reduce wheel size + run: | + bash -x .github/workflows/scripts/build.sh ${{ matrix.python-version }} ${{ matrix.cuda-version }} + wheel_name=$(ls dist/*whl | xargs -n 1 basename) + asset_name=${wheel_name//"linux"/"manylinux1"} + echo "wheel_name=${wheel_name}" >> $GITHUB_ENV + echo "asset_name=${asset_name}" >> $GITHUB_ENV + + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ needs.release.outputs.upload_url }} + asset_path: ./dist/${{ env.wheel_name }} + asset_name: ${{ env.asset_name }} + asset_content_type: application/* + + # (Danielkinz): This last step will publish the .whl to pypi. Warning: untested + # - name: Publish package + # uses: pypa/gh-action-pypi-publish@release/v1.8 + # with: + # repository-url: https://test.pypi.org/legacy/ + # password: ${{ secrets.PYPI_API_TOKEN }} + # skip-existing: true diff --git a/.github/workflows/scripts/build.sh b/.github/workflows/scripts/build.sh new file mode 100644 index 0000000..0a759d3 --- /dev/null +++ b/.github/workflows/scripts/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +python_executable=python$1 +cuda_home=/usr/local/cuda-$2 + +# Update paths +PATH=${cuda_home}/bin:$PATH +LD_LIBRARY_PATH=${cuda_home}/lib64:$LD_LIBRARY_PATH + +# Install requirements +$python_executable -m pip install wheel packaging +$python_executable -m pip install -r requirements-cuda.txt + +# Limit the number of parallel jobs to avoid OOM +export MAX_JOBS=1 +# Make sure release wheels are built for the following architectures +export TORCH_CUDA_ARCH_LIST="7.0 7.5 8.0 8.6 8.9 9.0+PTX" +# Build +$python_executable setup.py bdist_wheel --dist-dir=dist diff --git a/.github/workflows/scripts/create_release.js b/.github/workflows/scripts/create_release.js new file mode 100644 index 0000000..4757421 --- /dev/null +++ b/.github/workflows/scripts/create_release.js @@ -0,0 +1,20 @@ +// Uses Github's API to create the release and wait for result. +// We use a JS script since github CLI doesn't provide a way to wait for the release's creation and returns immediately. + +module.exports = async (github, context, core) => { + try { + const response = await github.rest.repos.createRelease({ + draft: false, + generate_release_notes: true, + name: process.env.RELEASE_TAG, + owner: context.repo.owner, + prerelease: true, + repo: context.repo.repo, + tag_name: process.env.RELEASE_TAG, + }); + + core.setOutput('upload_url', response.data.upload_url); + } catch (error) { + core.setFailed(error.message); + } +} \ No newline at end of file diff --git a/.github/workflows/scripts/cuda-install.sh b/.github/workflows/scripts/cuda-install.sh new file mode 100644 index 0000000..312c6e8 --- /dev/null +++ b/.github/workflows/scripts/cuda-install.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Replace '.' with '-' ex: 11.8 -> 11-8 +cuda_version=$(echo $1 | tr "." "-") +# Removes '-' and '.' ex: ubuntu-20.04 -> ubuntu2004 +OS=$(echo $2 | tr -d ".\-") + +# Installs CUDA +wget -nv https://developer.download.nvidia.com/compute/cuda/repos/${OS}/x86_64/cuda-keyring_1.1-1_all.deb +sudo dpkg -i cuda-keyring_1.1-1_all.deb +rm cuda-keyring_1.1-1_all.deb +sudo apt -qq update +sudo apt -y install cuda-${cuda_version} cuda-nvcc-${cuda_version} cuda-libraries-dev-${cuda_version} +sudo apt clean + +# Test nvcc +PATH=/usr/local/cuda-$1/bin:${PATH} +nvcc --version + +# Log gcc, g++, c++ versions +gcc --version +g++ --version +c++ --version diff --git a/.github/workflows/scripts/env.sh b/.github/workflows/scripts/env.sh new file mode 100644 index 0000000..d7baaec --- /dev/null +++ b/.github/workflows/scripts/env.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# This file installs common linux environment tools + +export LANG C.UTF-8 + +# python_version=$1 + +sudo apt-get update && \ +sudo apt-get install -y --no-install-recommends \ + software-properties-common \ + +sudo apt-get install -y --no-install-recommends \ + build-essential \ + apt-utils \ + ca-certificates \ + wget \ + git \ + vim \ + libssl-dev \ + curl \ + unzip \ + unrar \ + cmake \ + net-tools \ + sudo \ + autotools-dev \ + rsync \ + jq \ + openssh-server \ + tmux \ + screen \ + htop \ + pdsh \ + openssh-client \ + lshw \ + dmidecode \ + util-linux \ + automake \ + autoconf \ + libtool \ + net-tools \ + pciutils \ + libpci-dev \ + libaio-dev \ + libcap2 \ + libtinfo5 \ + fakeroot \ + devscripts \ + debhelper \ + nfs-common + +# Remove github bloat files to free up disk space +sudo rm -rf "/usr/local/share/boost" +sudo rm -rf "$AGENT_TOOLSDIRECTORY" +sudo rm -rf "/usr/share/dotnet" diff --git a/.github/workflows/scripts/pytorch-install.sh b/.github/workflows/scripts/pytorch-install.sh new file mode 100644 index 0000000..dfc1851 --- /dev/null +++ b/.github/workflows/scripts/pytorch-install.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +python_executable=python$1 +pytorch_version=$2 +cuda_version=$3 + +# Install torch +$python_executable -m pip install numpy pyyaml scipy ipython mkl mkl-include ninja cython typing pandas typing-extensions dataclasses setuptools && conda clean -ya +$python_executable -m pip install torch==${pytorch_version}+cu${cuda_version//./} --extra-index-url https://download.pytorch.org/whl/cu${cuda_version//./} + +# Print version information +$python_executable --version +$python_executable -c "import torch; print('PyTorch:', torch.__version__)" +$python_executable -c "import torch; print('CUDA:', torch.version.cuda)" +$python_executable -c "from torch.utils import cpp_extension; print (cpp_extension.CUDA_HOME)" diff --git a/pyproject.toml b/pyproject.toml index 9f3a353..0632ace 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -# Should be mirrored in requirements-build.txt +# Should be mirrored in requirements.txt requires = [ "packaging", "setuptools >= 49.4.0", diff --git a/requirements.txt b/requirements.txt index 14f356f..a475439 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ datasets torch -transformers +transformers>=4.44 safetensors psutil accelerate \ No newline at end of file diff --git a/vptq/__init__.py b/vptq/__init__.py index 4fd38e7..9f7ca72 100644 --- a/vptq/__init__.py +++ b/vptq/__init__.py @@ -4,4 +4,4 @@ # -------------------------------------------------------------------------- __version__ = "0.0.1" -from .layers.model_base import AutoModelForCausalLM as AutoModelForCausalLM +from .layers import AutoModelForCausalLM as AutoModelForCausalLM diff --git a/vptq/app.py b/vptq/app.py index 1de0ad1..77c33dc 100644 --- a/vptq/app.py +++ b/vptq/app.py @@ -1,3 +1,8 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------------------- + import os import gradio as gr diff --git a/vptq/layers/__init__.py b/vptq/layers/__init__.py new file mode 100644 index 0000000..f68bf61 --- /dev/null +++ b/vptq/layers/__init__.py @@ -0,0 +1,6 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. +# -------------------------------------------------------------------------- + +from .model_base import AutoModelForCausalLM as AutoModelForCausalLM \ No newline at end of file From 0ce13468346b7a54411514060a0dd6660952e32a Mon Sep 17 00:00:00 2001 From: wejoncy Date: Sat, 21 Sep 2024 00:54:25 -0700 Subject: [PATCH 2/2] add format sh --- format.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/format.sh b/format.sh index 669c1ee..3ce1ecc 100644 --- a/format.sh +++ b/format.sh @@ -1 +1,4 @@ yapf --recursive . --style='{based_on_style: google, column_limit: 120, indent_width: 4}' -i +isort . +find csrc/ \( -name '*.h' -o -name '*.cc' -o -name '*.cu' -o -name '*.cuh' \) -print \ +| xargs clang-format -i \ No newline at end of file