Skip to content

Commit e08bea8

Browse files
littskStrivin0311
andauthored
Minor update before v1.0.4 (#152)
* update ci * update ci * update ci * minor polished interface * updated gitignore * updated pre-commit-config --------- Co-authored-by: Strivin0311 <hyp@smail.nju.edu.cn>
1 parent c282d58 commit e08bea8

File tree

5 files changed

+102
-11
lines changed

5 files changed

+102
-11
lines changed

.github/workflows/sphinx.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ permissions:
77
contents: write
88
jobs:
99
deploy:
10-
runs-on: ubuntu-latest
10+
runs-on:
11+
group: default
1112
container:
1213
image: nvcr.io/nvidia/pytorch:25.05-py3
1314
steps:

.gitignore

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ magi_attention/flex_flash_attn*
66

77
# Byte-compiled / optimized / DLL files
88
__pycache__/
9-
*.py[cod]
9+
*.py[codz]
1010
*$py.class
1111

1212
# C extensions
@@ -52,7 +52,7 @@ htmlcov/
5252
nosetests.xml
5353
coverage.xml
5454
*.cover
55-
*.py,cover
55+
*.py.cover
5656
.hypothesis/
5757
.pytest_cache/
5858
cover/
@@ -103,20 +103,35 @@ ipython_config.py
103103
# install all needed dependencies.
104104
#Pipfile.lock
105105

106+
# UV
107+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
108+
# This is especially recommended for binary packages to ensure reproducibility, and is more
109+
# commonly ignored for libraries.
110+
#uv.lock
111+
106112
# poetry
107113
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
108114
# This is especially recommended for binary packages to ensure reproducibility, and is more
109115
# commonly ignored for libraries.
110116
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
111117
#poetry.lock
118+
#poetry.toml
112119

113120
# pdm
114121
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
122+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
123+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115124
#pdm.lock
116-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
117-
# in version control.
118-
# https://pdm.fming.dev/#use-with-ide
119-
.pdm.toml
125+
pdm.toml
126+
.pdm-python
127+
.pdm-build/
128+
129+
# pixi
130+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
131+
#pixi.lock
132+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
133+
# in the .venv directory. It is recommended not to include this directory in version control.
134+
.pixi
120135

121136
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
122137
__pypackages__/
@@ -130,6 +145,7 @@ celerybeat.pid
130145

131146
# Environments
132147
.env
148+
.envrc
133149
.venv
134150
env/
135151
venv/
@@ -168,5 +184,33 @@ cython_debug/
168184
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
169185
#.idea/
170186

171-
172-
third_party/TransformerEngine/
187+
# Abstra
188+
# Abstra is an AI-powered process automation framework.
189+
# Ignore directories containing user credentials, local state, and settings.
190+
# Learn more at https://abstra.io/docs
191+
.abstra/
192+
193+
# Visual Studio Code
194+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
195+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
196+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
197+
# you could uncomment the following to ignore the entire vscode folder
198+
# .vscode/
199+
200+
# Ruff stuff:
201+
.ruff_cache/
202+
203+
# PyPI configuration file
204+
.pypirc
205+
206+
# Cursor
207+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
208+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
209+
# refer to https://docs.cursor.com/context/ignore-files
210+
.cursorignore
211+
.cursorindexingignore
212+
213+
# Marimo
214+
marimo/_static/
215+
marimo/_lsp/
216+
__marimo__/

.pre-commit-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ repos:
2121
files: \.(txt|md|yaml|c|cc|cxx|cpp|cu|cuh|h|hpp|hxx|proto|py|pyi|sh)$
2222
- id: csrc_code_formatter
2323
name: check for csrc code format
24-
entry: clang-format-21
24+
entry: bash scripts/run_csrc_code_formatter.sh
2525
language: system
2626
files: ^magi_attention/csrc/.*\.(h|cuh|hpp|cpp|cu)$
2727
args: ['-i']
28+
require_serial: true
2829
- repo: https://github.com/pre-commit/pre-commit-hooks
2930
rev: v4.4.0
3031
hooks:

magi_attention/api/magi_attn_interface.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def magi_attn_varlen_key(
7979
which represents ``[window_size_left, window_size_right]``. The parameter is effective only
8080
when ``causal`` is ``False``; when ``causal`` is ``True``, it is required to be ``(-1, -1)``.
8181
Defaults to be ``(-1, -1)``.
82+
8283
dist_attn_config (DistAttnConfig): dist attn config.
8384
8485
Returns:
@@ -208,6 +209,7 @@ def magi_attn_varlen_dispatch(
208209
which represents ``[window_size_left, window_size_right]``. The parameter is effective only
209210
when ``causal`` is ``False``; when ``causal`` is ``True``, it is required to be ``(-1, -1)``.
210211
Defaults to be ``(-1, -1)``.
212+
211213
dist_attn_config (DistAttnConfig): dist attn config.
212214
213215
Returns:
@@ -306,7 +308,6 @@ def magi_attn_flex_key(
306308
calculate DistAttnRuntimeKey and generate the corr. inner DistAttnRuntimeMgr.
307309
308310
Args:
309-
x (torch.Tensor): input tensor
310311
q_ranges (AttnRanges): the global query ranges
311312
k_ranges (AttnRanges): the global key ranges
312313
attn_mask_type (str | AttnMaskType | list[str | AttnMaskType]):
@@ -518,6 +519,7 @@ def magi_attn_flex_dispatch(
518519
519520
Args:
520521
x (torch.Tensor): input tensor
522+
521523
q_ranges (AttnRanges): the global query ranges
522524
k_ranges (AttnRanges): the global key ranges
523525
attn_mask_type (str | AttnMaskType | list[str | AttnMaskType]):
@@ -817,12 +819,14 @@ def make_varlen_key_for_new_mask_after_dispatch(
817819
Args:
818820
cu_seqlens_q (torch.Tensor): Cumulative sequence lengths for queries.
819821
cu_seqlens_k (torch.Tensor): Cumulative sequence lengths for keys.
822+
820823
key_for_dispatch (DistAttnRuntimeKey): the key used for dispatch
821824
causal (bool, optional): whether the varlen attention mask is causal. Defaults to ``False``.
822825
window_size (tuple[int, int], optional): window_size of sliding window mask
823826
which represents ``[window_size_left, window_size_right]``. The parameter is effective only
824827
when ``causal`` is ``False``; when ``causal`` is ``True``, it is required to be ``(-1, -1)``.
825828
Defaults to be ``(-1, -1)``.
829+
826830
dist_attn_config (DistAttnConfig, optional): the optional new dist attn config,
827831
828832
NOTE: if not provided, we will use the same config as the ``key_for_dispatch``,
@@ -959,7 +963,9 @@ def make_flex_key_for_new_mask_after_dispatch(
959963
attn_mask_type (str | AttnMaskType | list[str | AttnMaskType]):
960964
the global attn mask type (list)
961965
represented by str or enum ``AttnMaskType`` or their mixed combination
966+
962967
key_for_dispatch (DistAttnRuntimeKey): the key used for dispatch
968+
963969
dist_attn_config (DistAttnConfig, optional): the optional new dist attn config,
964970
965971
NOTE: if not provided, we will use the same config as the ``key_for_dispatch``,

scripts/run_csrc_code_formatter.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Copyright (c) 2025 SandAI. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Define the path to the clang-format executable.
18+
# You might need to adjust the version number (e.g., clang-format-15, clang-format-17)
19+
# or just "clang-format" if it's a generic link.
20+
CLANG_FORMAT_BIN="clang-format-21"
21+
22+
INSTALL_CMD="bash scripts/install_clang_format.sh"
23+
24+
# Check if the clang-format executable is available in the system's PATH.
25+
# 'command -v' attempts to locate the command.
26+
# '&> /dev/null' redirects both stdout and stderr to null, suppressing output during the check.
27+
if ! command -v "$CLANG_FORMAT_BIN" &> /dev/null
28+
then
29+
echo "Error: '$CLANG_FORMAT_BIN' command not found."
30+
echo "This pre-commit hook requires '$CLANG_FORMAT_BIN' to be installed."
31+
echo "We recommend running '$INSTALL_CMD' to install it."
32+
exit 1 # Exit with a non-zero status code, signaling failure to pre-commit.
33+
fi
34+
35+
# If clang-format is found, execute it with all arguments passed to this script.
36+
# 'exec' replaces the current shell process with the clang-format process,
37+
# meaning clang-format's exit status will become this script's exit status.
38+
# '"$@"' expands to all positional parameters passed to this script, preserving whitespace.
39+
exec "$CLANG_FORMAT_BIN" "$@"

0 commit comments

Comments
 (0)