From 1dbd7b5552ad83e965ddbe9d0bef9cbbb353d4e5 Mon Sep 17 00:00:00 2001 From: pandacooming Date: Fri, 24 Apr 2026 00:53:08 +0000 Subject: [PATCH 1/2] Add Code Format Check CI - Add .github/workflows/format.yml: GitHub Actions workflow that runs yapf + ruff on every push to main and on every PR. - Add format.sh: local formatting script (used by CI and for contributors to run locally before pushing). Both files follow the same conventions as deepseek-ai/DeepEP. --- .github/workflows/format.yml | 32 ++++++++++ format.sh | 109 +++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 .github/workflows/format.yml create mode 100755 format.sh diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 0000000..77010ec --- /dev/null +++ b/.github/workflows/format.yml @@ -0,0 +1,32 @@ +name: Code Format Check + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + format-check: + runs-on: ubuntu-latest + + steps: + - name: Checkout source + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + cache: 'pip' + + - name: Install formatters + run: | + pip install --upgrade pip + pip install 'yapf==0.40.2' 'ruff>=0.6.0' + + - name: Run format.sh + run: | + bash ./format.sh diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..a3c95fa --- /dev/null +++ b/format.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# Usage: +# bash ./format.sh # Check/format files changed vs origin/main +# bash ./format.sh --all # Format the entire codebase +# +# This script formats all Python files that differ from origin/main. +# You are encouraged to run this locally before pushing changes for review. + +set -eo pipefail + +# Install yapf/ruff if not available +if ! (yapf --version &>/dev/null && ruff --version &>/dev/null); then + pip install --upgrade pip + pip install 'yapf==0.40.2' 'ruff>=0.6.0' +fi + +YAPF_VERSION=$(yapf --version | awk '{print $2}') +RUFF_VERSION=$(ruff --version | awk '{print $2}') + +echo "yapf: ${YAPF_VERSION}" +echo "ruff: ${RUFF_VERSION}" + +# ---------------------------------------------------------------------- +# YAPF — Python formatter +# ---------------------------------------------------------------------- +echo 'yapf: Check Start' + +YAPF_FLAGS=( + '--recursive' + '--parallel' +) + +format_all() { + yapf --in-place "${YAPF_FLAGS[@]}" . +} + +format_changed() { + if git show-ref --verify --quiet refs/remotes/origin/main; then + BASE_BRANCH="origin/main" + else + BASE_BRANCH="main" + fi + + MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)" + + if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then + git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 \ + yapf --in-place "${YAPF_FLAGS[@]}" + fi +} + +if [[ "$1" == '--all' ]]; then + format_all +else + format_changed +fi +echo 'yapf: Done' + +# ---------------------------------------------------------------------- +# Ruff — Python linter +# ---------------------------------------------------------------------- +echo 'ruff: Check Start' + +lint_all() { + ruff check . +} + +lint_changed() { + if git show-ref --verify --quiet refs/remotes/origin/main; then + BASE_BRANCH="origin/main" + else + BASE_BRANCH="main" + fi + + MERGEBASE="$(git merge-base $BASE_BRANCH HEAD)" + + if ! git diff --diff-filter=ACM --quiet --exit-code "$MERGEBASE" -- '*.py' '*.pyi' &>/dev/null; then + git diff --name-only --diff-filter=ACM "$MERGEBASE" -- '*.py' '*.pyi' | xargs -P 5 \ + ruff check + fi +} + +if [[ "$1" == '--all' ]]; then + lint_all +else + lint_changed +fi +echo 'ruff: Done' + +# ---------------------------------------------------------------------- +# Check for uncommitted changes +# ---------------------------------------------------------------------- +if ! git diff --quiet &>/dev/null; then + echo '' + echo 'Reformatted files. Please review and stage the changes.' + echo '' + echo 'Changed files:' + git --no-pager diff --name-only + + echo '' + echo 'You can also review the full diff below:' + echo '' + git --no-pager diff + + exit 1 +fi + +echo '' +echo 'All checks passed.' From c53ca40bf32ffac89a772c6d80bd9260c733c5cc Mon Sep 17 00:00:00 2001 From: pandacooming Date: Fri, 24 Apr 2026 01:29:31 +0000 Subject: [PATCH 2/2] fix(testing/bench.py): add float16 and float8_e5m2 to dtype_to_str mapping Fixes #4 --- tile_kernels/testing/bench.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tile_kernels/testing/bench.py b/tile_kernels/testing/bench.py index 6ad099e..48ba322 100644 --- a/tile_kernels/testing/bench.py +++ b/tile_kernels/testing/bench.py @@ -59,13 +59,15 @@ def print_average_perf(latency_list: list[float], bandwidth_list: list[float], r def dtype_to_str(dtype: torch.dtype) -> str: mapping = { torch.float32: 'fp32', + torch.float16: 'fp16', torch.bfloat16: 'bf16', torch.float8_e4m3fn: 'e4m3', - torch.int8: 'e2m1', # int8 represents FP4 e2m1 format + torch.float8_e5m2: 'e5m2', + torch.int8: 'e2m1', # int8 represents FP4 e2m1 format } if dtype not in mapping: - raise ValueError(f'Unsupported dtype: {dtype}. Only fp32, bf16, e4m3, and int8(e2m1) are supported') + raise ValueError(f'Unsupported dtype: {dtype}. Only fp32, fp16, bf16, e4m3, e5m2, and int8(e2m1) are supported') return mapping[dtype]