Skip to content

Commit 8fe3540

Browse files
[CI] add pre-commit integration (#955)
* chore: misc cleanup * feat: add pre-commit config * chore: update lint dependencies * style: fix lint issues * feat: add pre-commit hooks * fix: fix typos * chore: update .gitattributes * [Lint]: [pre-commit.ci] auto fixes [...] * docs: update CONTRIBUTING.md * chore: update default venv name * chore: revert and exclude CUDA files --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f8ae600 commit 8fe3540

File tree

19 files changed

+205
-49
lines changed

19 files changed

+205
-49
lines changed

.clang-format

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
BasedOnStyle: LLVM
3+
UseTab: Never
4+
IndentWidth: 2
5+
ColumnLimit: 80
6+
7+
Language: Cpp
8+
Standard: c++17

.editorconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ insert_final_newline = true
1414
indent_size = 4
1515

1616
[*.{cpp,hpp,cxx,cc,c,h,cu,cuh}]
17-
indent_size = 4
17+
indent_size = 2
18+
19+
[{*.cmake,CMakeLists.txt}]
20+
indent_size = 2
1821

1922
[*.{yaml,yml}]
2023
indent_size = 2

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
* text eol=lf
2+
*.bat eol=crlf
3+
4+
*.svg binary
5+
*.jpg binary
6+
*.jpeg binary
7+
*.png binary
8+
*.gif binary
9+
110
*.h linguist-language=C++

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ nnfusion.tar.gz
2626
# makeenv and test intermediate files
2727
tmp/
2828

29+
.env
30+
.envrc
31+
.venv
32+
env/
2933
venv/
34+
ENV/
35+
env.bak/
36+
venv.bak/
3037
.vscode/
3138
.vs/
3239

.pre-commit-config.yaml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
ci:
4+
autofix_prs: true
5+
autofix_commit_msg: "[Lint]: [pre-commit.ci] auto fixes [...]"
6+
autoupdate_commit_msg: "[CI] [pre-commit.ci] autoupdate"
7+
autoupdate_schedule: monthly
8+
default_stages: [pre-commit, pre-push, manual]
9+
exclude: '^(build|3rdparty)/.*$' # exclude build and 3rdparty directories
10+
repos:
11+
- repo: https://github.com/pre-commit/pre-commit-hooks
12+
rev: v6.0.0
13+
hooks:
14+
- id: check-symlinks
15+
- id: destroyed-symlinks
16+
# FIXME: enable these hooks
17+
# - id: trailing-whitespace
18+
# - id: end-of-file-fixer
19+
- id: check-added-large-files
20+
- id: check-merge-conflict
21+
fail_fast: true
22+
# FIXME: enable these hooks
23+
# - id: check-executables-have-shebangs
24+
# - id: check-shebang-scripts-are-executable
25+
- id: detect-private-key
26+
- id: check-yaml
27+
- id: check-toml
28+
- id: check-ast
29+
fail_fast: true
30+
- id: debug-statements
31+
- repo: https://github.com/pre-commit/mirrors-clang-format
32+
rev: v15.0.7 # sync with requirements-lint.txt
33+
hooks:
34+
- id: clang-format
35+
exclude: |
36+
(?ix)(
37+
^.+\.(cu|cuh)$|
38+
^.+\.json$
39+
)
40+
- repo: https://github.com/astral-sh/ruff-pre-commit
41+
rev: v0.14.0 # sync with requirements-lint.txt
42+
hooks:
43+
- id: ruff-check
44+
args: [--fix, --exit-non-zero-on-fix]
45+
- repo: https://github.com/google/yapf
46+
rev: v0.43.0 # sync with requirements-lint.txt
47+
hooks:
48+
- id: yapf
49+
args: [--recursive, --in-place]
50+
- repo: https://github.com/codespell-project/codespell
51+
rev: v2.4.1 # sync with requirements-lint.txt
52+
hooks:
53+
- id: codespell
54+
additional_dependencies: [".[toml]"]
55+
exclude: |
56+
(?x)(
57+
^.+\.(cpp|hpp|cxx|cc|c|h|cu|cuh)$|
58+
^.+\.svg$|
59+
^.*\brequirements\b.*\.txt$
60+
)

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ else()
5656

5757
# Set default build type to RelWithDebInfo if not provided
5858
if(NOT CMAKE_BUILD_TYPE)
59-
# Set default build type to Release if not provided
59+
# Set default build type to Release if not provided
6060
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
6161
message(STATUS "Setting default build type to ${CMAKE_BUILD_TYPE}")
6262
endif()
@@ -199,7 +199,7 @@ if(USE_CUDA)
199199
set(CUDA_MAJOR_VERSION ${CUDAToolkit_VERSION_MAJOR})
200200
message(STATUS "Setting CUDA_MAJOR_VERSION=${CUDA_MAJOR_VERSION}")
201201
add_compile_definitions(CUDA_MAJOR_VERSION=${CUDA_MAJOR_VERSION})
202-
202+
203203
list(APPEND TILE_LANG_INCLUDES ${CUDAToolkit_INCLUDE_DIRS})
204204
endif(USE_CUDA)
205205

CONTRIBUTING.md

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22

33
That would be awesome if you want to contribute something to TileLang!
44

5-
- [Contributing](CONTRIBUTING.md#contributing)
6-
- [Reporting Bugs](CONTRIBUTING.md#reporting-bugs)
7-
- [Asking Questions](CONTRIBUTING.md#asking-questions)
8-
- [Submitting Pull Requests](CONTRIBUTING.md#submitting-pull-requests)
9-
- [Repository Setup](CONTRIBUTING.md#repository-setup)
10-
- [Running Tests](CONTRIBUTING.md#running-tests)
5+
### Table of Contents <!-- omit in toc --> <!-- markdownlint-disable heading-increment -->
116

12-
## Reporting Bugs
7+
- [Report Bugs](#report-bugs)
8+
- [Ask Questions](#ask-questions)
9+
- [Submit Pull Requests](#submit-pull-requests)
10+
- [Setup Development Environment](#setup-development-environment)
11+
- [Install Develop Version](#install-develop-version)
12+
- [Lint Check](#lint-check)
13+
- [Test Locally](#test-locally)
14+
- [Build Wheels](#build-wheels)
15+
- [Documentation](#documentation)
16+
17+
## Report Bugs
1318

1419
If you run into any weird behavior while using TileLang, feel free to open a new issue in this repository! Please run a **search before opening** a new issue, to make sure that someone else hasn't already reported or solved the bug you've found.
1520

@@ -18,35 +23,86 @@ Any issue you open must include:
1823
- Code snippet that reproduces the bug with a minimal setup.
1924
- A clear explanation of what the issue is.
2025

21-
22-
## Asking Questions
26+
## Ask Questions
2327

2428
Please ask questions in issues.
2529

26-
## Submitting Pull Requests
30+
## Submit Pull Requests
2731

2832
All pull requests are super welcomed and greatly appreciated! Issues in need of a solution are marked with a [`♥ help`](https://github.com/ianstormtaylor/TileLang/issues?q=is%3Aissue+is%3Aopen+label%3A%22%E2%99%A5+help%22) label if you're looking for somewhere to start.
2933

30-
Please run `./format.sh` before submitting a pull request to make sure that your code is formatted correctly.
34+
If you're new to contributing to TileLang, you can follow the following guidelines before submitting a pull request.
35+
36+
> [!NOTE]
37+
> Please include tests and docs with every pull request if applicable!
38+
39+
## Setup Development Environment
40+
41+
Before contributing to TileLang, please follow the instructions below to setup.
42+
43+
1. Fork TileLang ([fork](https://github.com/tile-ai/tilelang/fork)) on GitHub and clone the repository.
44+
45+
```bash
46+
git clone --recurse-submodules git@github.com:<your username>/tilelang.git # use the SSH protocol
47+
cd tilelang
48+
49+
git remote add upstream git@github.com:tile-ai/tilelang.git
50+
```
51+
52+
2. Setup a development environment:
53+
54+
```bash
55+
uv venv --seed .venv # use `python3 -m venv .venv` if you don't have `uv`
56+
57+
source .venv/bin/activate
58+
python3 -m pip install --upgrade pip setuptools wheel "build[uv]"
59+
uv pip install --requirements requirements-dev.txt
60+
```
61+
62+
3. Setup the [`pre-commit`](https://pre-commit.com) hooks:
63+
64+
```bash
65+
pre-commit install --install-hooks
66+
```
3167
32-
Please include tests and docs with every pull request!
68+
Then you are ready to rock. Thanks for contributing to TileLang!
3369
34-
## Repository Setup
70+
## Install Develop Version
3571
36-
To run the build, you need to have the TileLang repository cloned to your computer. After that, you need to `cd` into the directory where you cloned it, and install the dependencies with `python`:
72+
To install TileLang in an "editable" mode, run:
3773
3874
```bash
39-
python setup.py install
75+
python3 -m pip install --no-build-isolation --verbose --editable .
4076
```
4177
78+
in the main directory. This installation is removable by:
4279
43-
## Running Tests
80+
```bash
81+
python3 -m pip uninstall tilelang
82+
```
83+
84+
## Lint Check
85+
86+
To check the linting, run:
87+
88+
```bash
89+
pre-commit run --all-files
90+
```
91+
92+
## Test Locally
4493
45-
To run the tests, start by building the project as described in the [Repository Setup](CONTRIBUTING.md#repository-setup) section.
94+
To run the tests, start by building the project as described in the [Setup Development Environment](#setup-development-environment) section.
4695
4796
Then you can rerun the tests with:
4897
49-
```text
50-
python -m pytest testing
98+
```bash
99+
python3 -m pytest testing
51100
```
52101
102+
## Build Wheels
103+
104+
_TBA_
105+
106+
## Documentation
107+
108+
_TBA_

docs/deeplearning_operators/matmul.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:class: myclass1 myclass2
99
:name: a-tip-reference
1010

11-
This document is still **experimental** and may be incomplete.
11+
This document is still **experimental** and may be incomplete.
1212
Suggestions and improvements are highly encouraged—please submit a PR!
1313
:::
1414

@@ -256,4 +256,4 @@ For more advanced usage—including partial lowering, explicitly controlling thr
256256
* [BitBLAS](https://github.com/tile-ai/bitblas)
257257
* [Triton](https://github.com/openai/triton)
258258
* [Cutlass](https://github.com/NVIDIA/cutlass)
259-
* [PyCUDA](https://documen.tician.de/pycuda/)
259+
* [PyCUDA](https://documen.tician.de/pycuda/) <!-- codespell:ignore -->

examples/deepseek_v32/fp8_lighting_indexer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ def ref_fp8_mqa_logits(q: torch.Tensor, kv: torch.Tensor, weights: torch.Tensor,
258258
cost = mask.sum()
259259
return logits, cost
260260

261+
261262
def test_fp8_lighting_indexer(S=4096, SKV=8192, H=32, HKV=1, D=64, kv_stride=1):
262263
q = torch.randn(S, H, D, device="cuda", dtype=torch.bfloat16).to(torch.bfloat16)
263264
kv = torch.randn(SKV, D, device="cuda", dtype=torch.bfloat16).to(torch.bfloat16)
@@ -302,5 +303,6 @@ def logits_fn():
302303
print(f"logits_tflops: {logits_tflops}, logits_ms: {logits_ms}")
303304
print(f"cost_ref: {cost_ref}")
304305

306+
305307
if __name__ == "__main__":
306308
test_fp8_lighting_indexer()

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ skip = [
2424
".venv"
2525
]
2626

27+
[tool.ruff]
28+
target-version = "py38"
29+
line-length = 100
30+
output-format = "full"
31+
2732
[tool.ruff.lint]
2833
select = [
2934
# pycodestyle
@@ -48,13 +53,17 @@ ignore = [
4853
"E741",
4954
# line too long
5055
"E501",
56+
# if-else-block instead of ternary
57+
"SIM108",
5158
# key in dict.keys()
5259
"SIM118",
5360
# memory leaks
5461
"B019",
62+
# zip without explicit strict
63+
"B905",
5564
# No such file or directory
5665
"E902",
5766
]
5867
[tool.ruff.lint.per-file-ignores]
5968
"3rdparty/**/*" = ["ALL"]
60-
"examples/deepseek_v32/inference/**/*" = ["ALL"]
69+
"examples/deepseek_v32/inference/**/*" = ["ALL"]

0 commit comments

Comments
 (0)