Skip to content

Commit 24d0796

Browse files
[Format] pre-commit setup (#3090)
This PR sets up [pre-commit](https://pre-commit.com) for formatting prior to running git commit. This PR also fixes the issues that were brought up by pre-commit in the current codebase. Co-authored-by: Yixin Dong <[email protected]>
1 parent 8845ae8 commit 24d0796

File tree

105 files changed

+3207
-3131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+3207
-3131
lines changed

.github/ISSUE_TEMPLATE/documentation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ assignees: ''
1313
<!-- Please leave your general suggestion to our documentation here. -->
1414

1515
### Bug
16-
- Link to the buggy documentation/tutorial:
16+
- Link to the buggy documentation/tutorial:
1717
- Description of the bug:

.github/ISSUE_TEMPLATE/general.md

-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ assignees: ''
1010
## ❓ General Questions
1111

1212
<!-- Describe your questions -->
13-

.github/ISSUE_TEMPLATE/speed-report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ assignees: ''
1515

1616

1717
- The model configuration (e.g. quantization mode, running data type, etc.):
18-
- Device (e.g. MacBook Pro M2, PC+RTX 3080):
18+
- Device (e.g. MacBook Pro M2, PC+RTX 3080):
1919
- OS (if applicable):
2020
- Encode speed (Token/s):
2121
- Decode speed (Token/s):
2222
- Memory usage (if applicable):
2323

24-
<!-- Note that the measured speed might reflect peak performance if the prompt/chat history is short. -->
24+
<!-- Note that the measured speed might reflect peak performance if the prompt/chat history is short. -->

.pre-commit-config.yaml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# To use:
2+
#
3+
# pre-commit run -a
4+
#
5+
# Or:
6+
#
7+
# pre-commit install # (runs every time you commit in git)
8+
#
9+
# To update this file:
10+
#
11+
# pre-commit autoupdate
12+
#
13+
# See https://github.com/pre-commit/pre-commit
14+
# Note the pre-commit hooks shoule only be used for formatting, but not for linting.
15+
# For linting consider using CI.
16+
repos:
17+
# Standard hooks
18+
- repo: https://github.com/pre-commit/pre-commit-hooks
19+
rev: v5.0.0
20+
hooks:
21+
- id: check-added-large-files
22+
- id: check-case-conflict
23+
- id: check-merge-conflict
24+
- id: check-symlinks
25+
- id: end-of-file-fixer
26+
- id: mixed-line-ending
27+
- id: requirements-txt-fixer
28+
- id: trailing-whitespace
29+
30+
# Changes tabs to spaces
31+
- repo: https://github.com/Lucas-C/pre-commit-hooks
32+
rev: v1.5.5
33+
hooks:
34+
- id: remove-tabs
35+
- id: remove-crlf
36+
37+
# Formatters
38+
- repo: https://github.com/psf/black-pre-commit-mirror
39+
rev: 24.8.0
40+
hooks:
41+
- id: black
42+
43+
- repo: https://github.com/pycqa/isort
44+
rev: 5.13.2
45+
hooks:
46+
- id: isort
47+
48+
- repo: https://github.com/pre-commit/mirrors-clang-format
49+
rev: v19.1.1
50+
hooks:
51+
- id: clang-format
52+
types_or: [c++, c, cuda]
53+
exclude: |
54+
(?x)^(.*cubin.cpp$ | .*fmha_cubin.h | 3rdparty/.*)$
55+
56+
- repo: https://github.com/cheshirekow/cmake-format-precommit
57+
rev: v0.6.13
58+
hooks:
59+
- id: cmake-format
60+
additional_dependencies: [pyyaml>=5.1]

CMakeLists.txt

+60-56
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ else()
1717
endif()
1818

1919
if(NOT CMAKE_BUILD_TYPE)
20-
set(
21-
CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Build type" FORCE
22-
)
20+
set(CMAKE_BUILD_TYPE
21+
RelWithDebInfo
22+
CACHE STRING "Build type" FORCE)
2323
message(STATUS "Setting default build type to " ${CMAKE_BUILD_TYPE})
2424
endif(NOT CMAKE_BUILD_TYPE)
2525

2626
option(MLC_HIDE_PRIVATE_SYMBOLS "Hide private symbols" ON)
2727

28-
if (MLC_LLM_INSTALL_STATIC_LIB)
28+
if(MLC_LLM_INSTALL_STATIC_LIB)
2929
set(BUILD_STATIC_RUNTIME ON)
3030
endif()
3131

3232
set(MLC_VISIBILITY_FLAG "")
33-
if (MLC_HIDE_PRIVATE_SYMBOLS)
33+
if(MLC_HIDE_PRIVATE_SYMBOLS)
3434
set(HIDE_PRIVATE_SYMBOLS ON)
35-
if (NOT MSVC)
35+
if(NOT MSVC)
3636
set(MLC_VISIBILITY_FLAG "-fvisibility=hidden")
3737
endif()
3838
message(STATUS "Hide private symbols")
@@ -54,13 +54,13 @@ set(USE_PROFILER OFF)
5454
set(USE_GTEST OFF)
5555
set(USE_LIBBACKTRACE OFF)
5656
set(BUILD_DUMMY_LIBTVM ON)
57-
if (NOT DEFINED TVM_SOURCE_DIR)
57+
if(NOT DEFINED TVM_SOURCE_DIR)
5858
if(DEFINED ENV{TVM_SOURCE_DIR})
5959
set(TVM_SOURCE_DIR "$ENV{TVM_SOURCE_DIR}")
6060
else()
6161
set(TVM_SOURCE_DIR 3rdparty/tvm)
6262
endif(DEFINED ENV{TVM_SOURCE_DIR})
63-
endif (NOT DEFINED TVM_SOURCE_DIR)
63+
endif(NOT DEFINED TVM_SOURCE_DIR)
6464
message(STATUS "TVM_SOURCE_DIR: ${TVM_SOURCE_DIR}")
6565
add_subdirectory(${TVM_SOURCE_DIR} tvm EXCLUDE_FROM_ALL)
6666

@@ -75,15 +75,13 @@ list(FILTER XGRAMMAR_SRCS EXCLUDE REGEX "${XGRAMMAR_PATH}/cpp/pybind/.*\\.cc")
7575
list(APPEND MLC_LLM_SRCS ${XGRAMMAR_SRCS})
7676
add_library(mlc_llm_objs OBJECT ${MLC_LLM_SRCS})
7777

78-
set(
79-
MLC_LLM_INCLUDES
80-
${TVM_SOURCE_DIR}/include
81-
${TVM_SOURCE_DIR}/3rdparty/dlpack/include
82-
${TVM_SOURCE_DIR}/3rdparty/dmlc-core/include
83-
${TVM_SOURCE_DIR}/3rdparty/picojson
84-
)
78+
set(MLC_LLM_INCLUDES
79+
${TVM_SOURCE_DIR}/include ${TVM_SOURCE_DIR}/3rdparty/dlpack/include
80+
${TVM_SOURCE_DIR}/3rdparty/dmlc-core/include
81+
${TVM_SOURCE_DIR}/3rdparty/picojson)
8582

86-
set(MLC_LLM_COMPILE_DEFS ${MLC_LLM_COMPILE_DEFS} DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
83+
set(MLC_LLM_COMPILE_DEFS ${MLC_LLM_COMPILE_DEFS}
84+
DMLC_USE_LOGGING_LIBRARY=<tvm/runtime/logging.h>)
8785
set(MLC_LLM_COMPILE_DEFS ${MLC_LLM_COMPILE_DEFS} __STDC_FORMAT_MACROS=1)
8886
set(MLC_LLM_COMPILE_DEFS ${MLC_LLM_COMPILE_DEFS} PICOJSON_USE_INT64)
8987
set(MLC_LLM_COMPILE_DEFS ${MLC_LLM_COMPILE_DEFS} XGRAMMAR_ENABLE_LOG_DEBUG=0)
@@ -97,41 +95,46 @@ target_include_directories(mlc_llm_objs PRIVATE ${XGRAMMAR_PATH}/include)
9795

9896
add_library(mlc_llm SHARED $<TARGET_OBJECTS:mlc_llm_objs>)
9997
add_library(mlc_llm_static STATIC $<TARGET_OBJECTS:mlc_llm_objs>)
100-
add_dependencies(mlc_llm_static tokenizers_cpp sentencepiece-static tokenizers_c tvm_runtime)
98+
add_dependencies(mlc_llm_static tokenizers_cpp sentencepiece-static
99+
tokenizers_c tvm_runtime)
101100
set_target_properties(mlc_llm_static PROPERTIES OUTPUT_NAME mlc_llm)
102101

103102
target_link_libraries(mlc_llm PUBLIC tvm_runtime)
104103
target_link_libraries(mlc_llm PRIVATE tokenizers_cpp)
105104

106-
find_library(
107-
FLASH_ATTN_LIBRARY flash_attn
108-
HINTS ${TVM_SOURCE_DIR}/*/3rdparty/libflash_attn/src
109-
)
105+
find_library(FLASH_ATTN_LIBRARY flash_attn
106+
HINTS ${TVM_SOURCE_DIR}/*/3rdparty/libflash_attn/src)
110107

111-
if (FLASH_ATTN_LIBRARY STREQUAL "FLASH_ATTN_LIBRARY-NOTFOUND")
112-
message(WARNING "Cannot find libflash_attn. The model must not have been built with --use-flash-attn-mqa option.")
113-
else ()
108+
if(FLASH_ATTN_LIBRARY STREQUAL "FLASH_ATTN_LIBRARY-NOTFOUND")
109+
message(
110+
WARNING
111+
"Cannot find libflash_attn. The model must not have been built with --use-flash-attn-mqa option."
112+
)
113+
else()
114114
target_link_libraries(mlc_llm PUBLIC -Wl,--no-as-needed ${FLASH_ATTN_LIBRARY})
115115
endif()
116116

117117
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
118-
target_compile_definitions(mlc_llm PRIVATE "TVM_LOG_DEBUG")
119-
target_compile_definitions(mlc_llm_objs PRIVATE "TVM_LOG_DEBUG")
120-
target_compile_definitions(mlc_llm_static PRIVATE "TVM_LOG_DEBUG")
118+
target_compile_definitions(mlc_llm PRIVATE "TVM_LOG_DEBUG")
119+
target_compile_definitions(mlc_llm_objs PRIVATE "TVM_LOG_DEBUG")
120+
target_compile_definitions(mlc_llm_static PRIVATE "TVM_LOG_DEBUG")
121121
endif()
122122

123-
if (BUILD_CPP_TEST)
123+
if(BUILD_CPP_TEST)
124124
message(STATUS "Building cpp unittests")
125125
add_subdirectory(3rdparty/googletest)
126-
file(GLOB_RECURSE MLC_LLM_TEST_SRCS ${PROJECT_SOURCE_DIR}/tests/cpp/*unittest.cc)
126+
file(GLOB_RECURSE MLC_LLM_TEST_SRCS
127+
${PROJECT_SOURCE_DIR}/tests/cpp/*unittest.cc)
127128
add_executable(mlc_llm_cpp_tests ${MLC_LLM_TEST_SRCS})
128129
target_include_directories(mlc_llm_cpp_tests PRIVATE ${MLC_LLM_INCLUDES})
129-
target_include_directories(mlc_llm_cpp_tests PRIVATE ${PROJECT_SOURCE_DIR}/cpp)
130-
target_include_directories(mlc_llm_cpp_tests PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
130+
target_include_directories(mlc_llm_cpp_tests
131+
PRIVATE ${PROJECT_SOURCE_DIR}/cpp)
132+
target_include_directories(
133+
mlc_llm_cpp_tests PRIVATE ${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
131134
target_link_libraries(mlc_llm_cpp_tests PUBLIC mlc_llm gtest gtest_main)
132135
endif(BUILD_CPP_TEST)
133136

134-
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
137+
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
135138
target_link_libraries(mlc_llm PRIVATE log)
136139
target_link_libraries(tokenizers_cpp PRIVATE log)
137140
endif()
@@ -140,42 +143,43 @@ add_library(mlc_llm_module SHARED $<TARGET_OBJECTS:mlc_llm_objs>)
140143
target_link_libraries(mlc_llm_module PUBLIC tvm)
141144
target_link_libraries(mlc_llm_module PRIVATE tokenizers_cpp)
142145

143-
set_property(TARGET mlc_llm_module APPEND PROPERTY LINK_OPTIONS "${MLC_VISIBILITY_FLAG}")
144-
set_property(TARGET mlc_llm APPEND PROPERTY LINK_OPTIONS "${MLC_VISIBILITY_FLAG}")
146+
set_property(
147+
TARGET mlc_llm_module
148+
APPEND
149+
PROPERTY LINK_OPTIONS "${MLC_VISIBILITY_FLAG}")
150+
set_property(
151+
TARGET mlc_llm
152+
APPEND
153+
PROPERTY LINK_OPTIONS "${MLC_VISIBILITY_FLAG}")
145154

146155
find_program(CARGO_EXECUTABLE cargo)
147156

148157
if(NOT CARGO_EXECUTABLE)
149-
message(FATAL_ERROR "Cargo is not found! Please install cargo.")
158+
message(FATAL_ERROR "Cargo is not found! Please install cargo.")
150159
endif()
151160

152-
# when this option is on,
153-
# we install all static lib deps into lib
154-
if (MLC_LLM_INSTALL_STATIC_LIB)
155-
install(TARGETS
156-
mlc_llm_static
157-
tokenizers_cpp
158-
sentencepiece-static
159-
tvm_runtime
160-
LIBRARY DESTINATION lib${LIB_SUFFIX}
161-
)
161+
# when this option is on, we install all static lib deps into lib
162+
if(MLC_LLM_INSTALL_STATIC_LIB)
163+
install(TARGETS mlc_llm_static tokenizers_cpp sentencepiece-static tvm_runtime
164+
LIBRARY DESTINATION lib${LIB_SUFFIX})
162165
# tokenizers need special handling as it builds from rust
163166
if(MSVC)
164167
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tokenizers/libtokenizers_c.lib
165-
DESTINATION lib${LIB_SUFFIX}
166-
)
168+
DESTINATION lib${LIB_SUFFIX})
167169
else()
168170
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/tokenizers/libtokenizers_c.a
169-
DESTINATION lib${LIB_SUFFIX}
170-
)
171+
DESTINATION lib${LIB_SUFFIX})
171172
endif()
172173
else()
173-
install(TARGETS tvm_runtime mlc_llm mlc_llm_module
174-
mlc_llm_static
175-
tokenizers_cpp
176-
sentencepiece-static
177-
RUNTIME_DEPENDENCY_SET tokenizers_c
174+
install(
175+
TARGETS tvm_runtime
176+
mlc_llm
177+
mlc_llm_module
178+
mlc_llm_static
179+
tokenizers_cpp
180+
sentencepiece-static
181+
RUNTIME_DEPENDENCY_SET
182+
tokenizers_c
178183
RUNTIME DESTINATION bin
179-
LIBRARY DESTINATION lib${LIB_SUFFIX}
180-
)
184+
LIBRARY DESTINATION lib${LIB_SUFFIX})
181185
endif()

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,4 @@
198198
distributed under the License is distributed on an "AS IS" BASIS,
199199
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200200
See the License for the specific language governing permissions and
201-
limitations under the License.
201+
limitations under the License.

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -131,5 +131,3 @@ The underlying techniques of MLC LLM include:
131131
}
132132
```
133133
</details>
134-
135-

android/MLCChat/app/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/build
2-
/src/main/libs
2+
/src/main/libs

android/MLCChat/app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ dependencies {
7171
debugImplementation 'androidx.compose.ui:ui-tooling'
7272
debugImplementation 'androidx.compose.ui:ui-test-manifest'
7373

74-
}
74+
}

android/MLCChat/app/proguard-rules.pro

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
# If you keep the line number information, uncomment this to
2020
# hide the original source file name.
21-
#-renamesourcefileattribute SourceFile
21+
#-renamesourcefileattribute SourceFile

android/MLCChat/app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@
3838
</activity>
3939
</application>
4040

41-
</manifest>
41+
</manifest>

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ChatView.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ fun MessageViewPreviewWithMarkdown() {
267267
messageData = MessageData(
268268
role = MessageRole.Assistant, text = """
269269
# Sample Header
270-
* Markdown
271-
* [Link](https://example.com)
270+
* Markdown
271+
* [Link](https://example.com)
272272
<a href="https://www.google.com/">Google</a>
273273
"""
274274
)

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/MainActivity.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ class MainActivity : ComponentActivity() {
2626
}
2727
}
2828
}
29-
}
29+
}

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/NavView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ fun NavView(appViewModel: AppViewModel = viewModel()) {
1515
composable("home") { StartView(navController, appViewModel) }
1616
composable("chat") { ChatView(navController, appViewModel.chatState) }
1717
}
18-
}
18+
}

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/StartView.kt

-1
Original file line numberDiff line numberDiff line change
@@ -248,4 +248,3 @@ fun ModelView(
248248
}
249249
}
250250
}
251-

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ui/theme/Color.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ val BlueGrey30 = Color(0xFF45464F)
4141
val BlueGrey50 = Color(0xFF767680)
4242
val BlueGrey60 = Color(0xFF90909A)
4343
val BlueGrey80 = Color(0xFFC6C5D0)
44-
val BlueGrey90 = Color(0xFFE2E1EC)
44+
val BlueGrey90 = Color(0xFFE2E1EC)

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ui/theme/Theme.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ fun MLCChatTheme(
104104
typography = Typography,
105105
content = content
106106
)
107-
}
107+
}

android/MLCChat/app/src/main/java/ai/mlc/mlcchat/ui/theme/Type.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ val Typography = Typography(
3131
letterSpacing = 0.5.sp
3232
)
3333
*/
34-
)
34+
)

android/MLCChat/app/src/main/res/values/colors.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
<color name="teal_700">#FF018786</color>
88
<color name="black">#FF000000</color>
99
<color name="white">#FFFFFFFF</color>
10-
</resources>
10+
</resources>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<resources>
22
<string name="app_name">MLCChat</string>
3-
</resources>
3+
</resources>

android/MLCChat/app/src/main/res/values/themes.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
<style name="Theme.MLCChat" parent="android:Theme.Material.Light" />
55

6-
</resources>
6+
</resources>

0 commit comments

Comments
 (0)