-
Notifications
You must be signed in to change notification settings - Fork 1.1k
update kt-kernel #1530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update kt-kernel #1530
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| #!/bin/sh | ||
| # commit-msg hook to enforce Conventional Commits (https://www.conventionalcommits.org/) | ||
| # This script checks the commit message subject (first line) for a conventional commit format. | ||
| # If the message does not conform, the hook exits non-zero to block the commit. | ||
|
|
||
| # Read the commit message (first line) | ||
| if [ -z "$1" ]; then | ||
| echo "commit-msg hook: no message file provided" >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| MSG_FILE="$1" | ||
| read -r FIRST_LINE < "$MSG_FILE" || FIRST_LINE="" | ||
|
|
||
| # Trim leading/trailing whitespace | ||
| FIRST_LINE="$(echo "$FIRST_LINE" | sed -e 's/^[ \t]*//' -e 's/[ \t]*$//')" | ||
|
|
||
| # Allow empty message (let git handle it), or allow merges/reverts | ||
| case "$FIRST_LINE" in | ||
| Merge:*|merge:*|Revert:*|revert:*) | ||
| exit 0 | ||
| ;; | ||
| esac | ||
|
|
||
| # Conventional Commit regex (POSIX ERE) | ||
| # [type](scope)!?: subject | ||
| # types: feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip | ||
| # scope: any chars except ) | ||
|
|
||
| regex='^\[(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert|wip)\](\([^\)]+\))?(!)?: .+' | ||
|
|
||
| printf "%s" "$FIRST_LINE" | grep -E "$regex" >/dev/null 2>&1 | ||
| if [ $? -eq 0 ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| cat <<'EOF' >&2 | ||
| ERROR: Commit message does not follow Conventional Commits. | ||
|
|
||
| Expected format: | ||
| [type](scope)?: subject | ||
|
|
||
| Examples: | ||
| [feat]: add new feature | ||
| [fix(parser)]: handle edge case | ||
| [docs]!: update API docs (breaking change) | ||
|
|
||
| Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, wip | ||
|
|
||
| You can bypass this hook locally by running: | ||
| git commit --no-verify | ||
| EOF | ||
|
|
||
| exit 1 | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||||||||||||||||||||||
| #!/usr/bin/bash | ||||||||||||||||||||||||||||||
| # Pre-commit hook: run clang-format via CMake 'format' target and Black for Python before allowing commit. | ||||||||||||||||||||||||||||||
| # If formatting makes changes, stage them and abort so user can review. | ||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| REPO_ROOT="$(git rev-parse --show-toplevel)" | ||||||||||||||||||||||||||||||
| BUILD_DIR="$REPO_ROOT/build" | ||||||||||||||||||||||||||||||
| FORMAT_TARGET="format" | ||||||||||||||||||||||||||||||
| CLANG_FORMAT_BIN="${CLANG_FORMAT_BIN:-clang-format}" | ||||||||||||||||||||||||||||||
| BLACK_BIN="${BLACK_BIN:-black}" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Simple check clang-format present (optional) | ||||||||||||||||||||||||||||||
| # clang-format optional: if missing, skip C/C++ formatting | ||||||||||||||||||||||||||||||
| if ! command -v "$CLANG_FORMAT_BIN" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||
| echo "[pre-commit] clang-format not found (looked for $CLANG_FORMAT_BIN). Skipping C/C++ format." >&2 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # black optional: if missing, skip Python formatting | ||||||||||||||||||||||||||||||
| if ! command -v "$BLACK_BIN" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||
| echo "[pre-commit] black not found (looked for $BLACK_BIN). Skipping Python format." >&2 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Configure build directory if missing (quiet) | ||||||||||||||||||||||||||||||
| if [ ! -d "$BUILD_DIR" ] || [ ! -f "$BUILD_DIR/Makefile" ] && [ ! -f "$BUILD_DIR/build.ninja" ]; then | ||||||||||||||||||||||||||||||
| echo "[pre-commit] configuring project (cmake) ..." >&2 | ||||||||||||||||||||||||||||||
| cmake -S "$REPO_ROOT" -B "$BUILD_DIR" >/dev/null | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Run format target (prefer ninja if present) | ||||||||||||||||||||||||||||||
| # Run clang-format target when available and tool present | ||||||||||||||||||||||||||||||
| if command -v "$CLANG_FORMAT_BIN" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||
| if [ -f "$BUILD_DIR/build.ninja" ]; then | ||||||||||||||||||||||||||||||
| (cd "$BUILD_DIR" && ninja -k0 "$FORMAT_TARGET" >/dev/null) | ||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||
| (cd "$BUILD_DIR" && make "$FORMAT_TARGET") | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Run black on staged python files (or entire repo if you prefer) | ||||||||||||||||||||||||||||||
| if command -v "$BLACK_BIN" >/dev/null 2>&1; then | ||||||||||||||||||||||||||||||
| # Get staged python files; if none, skip | ||||||||||||||||||||||||||||||
| PY_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.py$' || true) | ||||||||||||||||||||||||||||||
| if [ -n "$PY_FILES" ]; then | ||||||||||||||||||||||||||||||
| echo "[pre-commit] running black on staged python files..." >&2 | ||||||||||||||||||||||||||||||
| $BLACK_BIN $PY_FILES | ||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||
| # Optionally format all python files; comment out if not desired | ||||||||||||||||||||||||||||||
| # $BLACK_BIN "$REPO_ROOT" | ||||||||||||||||||||||||||||||
| : | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
Comment on lines
+42
to
+50
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current method of passing python files to
Suggested change
|
||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Stage any formatting changes for tracked files | ||||||||||||||||||||||||||||||
| if ! git diff --quiet --exit-code; then | ||||||||||||||||||||||||||||||
| echo "[pre-commit] Formatting applied; updating index." >&2 | ||||||||||||||||||||||||||||||
| # Add only modified tracked files (exclude untracked new files not staged yet unless user staged them) | ||||||||||||||||||||||||||||||
| git add -u | ||||||||||||||||||||||||||||||
| echo "[pre-commit] Re-run git commit to proceed after reviewing changes." >&2 | ||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| echo "[pre-commit] format OK." >&2 | ||||||||||||||||||||||||||||||
| exit 0 | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| [submodule "pybind11"] | ||
| path = third_party/pybind11 | ||
| url = https://github.com/pybind/pybind11.git | ||
| [submodule "llama.cpp"] | ||
| path = third_party/llama.cpp | ||
| url = https://github.com/ggerganov/llama.cpp.git |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Optional: Install these if not already available in your environment | ||
| # These dependencies will be automatically installed when running `pip install .` | ||
| # You can skip this file if you already have these packages installed | ||
|
|
||
| # Core dependencies (minimum versions) | ||
| torch>=2.0.0 | ||
| safetensors>=0.4.0 | ||
| compressed-tensors>=0.7.0 | ||
| numpy>=1.24.0 | ||
|
|
||
| # Development dependencies | ||
| black>=25.9.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The code in this folder is copied from [Mozilla-Ocho/llamafile](https://github.com/Mozilla-Ocho/llamafile). Special thanks to the Mozilla-Ocho team. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Adapted from | ||
| // https://github.com/Mozilla-Ocho/llamafile/blob/0.8.8/llamafile/bench.h | ||
| // Copyrigth 2024 Mozilla Foundation. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // Copyright(c) 2024 by KVCache.AI, All Rights Reserved. | ||
|
|
||
| // -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*- | ||
| // vi: set et ft=cpp ts=4 sts=4 sw=4 fenc=utf-8 :vi | ||
| #pragma once | ||
|
|
||
| #include <stdio.h> | ||
|
|
||
| #include "micros.h" | ||
|
|
||
| #define BENCH(x) \ | ||
| do { \ | ||
| x; \ | ||
| __asm__ volatile("" ::: "memory"); \ | ||
| long long start = micros(); \ | ||
| for (int i = 0; i < ITERATIONS; ++i) { \ | ||
| __asm__ volatile("" ::: "memory"); \ | ||
| x; \ | ||
| __asm__ volatile("" ::: "memory"); \ | ||
| } \ | ||
| printf("%9lld us %s\n", (micros() - start + ITERATIONS - 1) / ITERATIONS, #x); \ | ||
| } while (0) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Adapted from | ||
| // https://github.com/Mozilla-Ocho/llamafile/blob/0.8.8/llamafile/flags.cpp | ||
| // Copyrigth 2024 Mozilla Foundation. | ||
| // Copyright(c) 2024 by KVCache.AI, All Rights Reserved. | ||
|
|
||
| #include "flags.h" | ||
|
|
||
| bool FLAG_precise = false; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Adapted from | ||
| // https://github.com/Mozilla-Ocho/llamafile/blob/0.8.8/llamafile/flags.cpp | ||
| // Copyrigth 2024 Mozilla Foundation. | ||
| // Copyright(c) 2024 by KVCache.AI, All Rights Reserved. | ||
|
|
||
| #pragma once | ||
|
|
||
| extern bool FLAG_precise; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message format description and examples are inconsistent with the validation regex.
!.[fix(parser)]: ..., will be rejected by the regex, which expects the scope to be outside the square brackets, like[fix](parser): ....To ensure the hook works as intended and the guidance is clear, both the description and the example should be aligned with the regex.