Skip to content

Commit 4c95e53

Browse files
fix-confilct
2 parents cd3a790 + 55b154d commit 4c95e53

95 files changed

Lines changed: 3807 additions & 242 deletions

File tree

Some content is hidden

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

.github/workflows/code_scan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010
scan-code-and-report:
1111
runs-on: scan
12-
if: ${{ github.repository == 'Flagopen/FlagGems' }}
12+
if: ${{ github.repository == 'flagos-ai/FlagGems' }}
1313
concurrency:
1414
group: scan-code-and-report-${{ github.event.pull_request.number || github.ref }}
1515
cancel-in-progress: true

.github/workflows/gems-cpp-extension.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- '**/*.cmake'
1515
- '**/*.mk'
1616
- 'Makefile'
17+
- '!src/flag_gems/experimental_ops/**'
1718
pull_request:
1819
branches: [ "master" ]
1920
paths:
@@ -27,6 +28,7 @@ on:
2728
- '**/*.cmake'
2829
- '**/*.mk'
2930
- 'Makefile'
31+
- '!src/flag_gems/experimental_ops/**'
3032

3133
jobs:
3234
build-C-extension:
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: gems-experimental-test
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
paths:
7+
- 'src/flag_gems/experimental_ops/**'
8+
pull_request:
9+
branches: [ "master" ]
10+
paths:
11+
- 'src/flag_gems/experimental_ops/**'
12+
13+
env:
14+
CUDA_VISIBLE_DEVICES: 7
15+
http_proxy: ${{ secrets.HTTP_PROXY }}
16+
https_proxy: ${{ secrets.HTTPS_PROXY }}
17+
18+
jobs:
19+
experimental-test-on-hopper:
20+
runs-on: hopper
21+
concurrency:
22+
group: experimental-test-on-hopper-${{ github.event.pull_request.number || github.ref }}
23+
cancel-in-progress: true
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: FlagGems experimental tests on hopper
31+
shell: bash
32+
run: |
33+
source "/home/zhangzhihui/miniconda3/etc/profile.d/conda.sh"
34+
conda activate flag_gems
35+
source tools/run_command.sh
36+
BASE_SHA=${{ github.event.pull_request.base.sha }}
37+
HEAD_SHA=${{ github.sha }}
38+
39+
echo "Diffing $BASE_SHA...$HEAD_SHA"
40+
41+
changed_ops=$(git diff --name-only $BASE_SHA...$HEAD_SHA | grep '^src/flag_gems/experimental_ops/.*\.py$' || true)
42+
43+
tests=""
44+
for f in $changed_ops; do
45+
base=$(basename "$f" .py)
46+
test_file="src/flag_gems/experimental_ops/exp_tests/${base}_test.py"
47+
if [ -f "$test_file" ]; then
48+
tests="$tests $test_file"
49+
fi
50+
done
51+
52+
if [ -n "$tests" ]; then
53+
echo "Running tests:$tests"
54+
run_command pytest -s $tests
55+
else
56+
echo "No relevant ops changes, skipping tests"
57+
fi

.github/workflows/gems-test-on-hopper.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ on:
1515
- '**/*.mk'
1616
- 'Makefile'
1717
- '**.yaml'
18+
- '!src/flag_gems/experimental_ops/**'
1819
pull_request:
1920
branches: [ "master" ]
2021
paths:
@@ -29,6 +30,7 @@ on:
2930
- '**/*.mk'
3031
- 'Makefile'
3132
- '**.yaml'
33+
- '!src/flag_gems/experimental_ops/**'
3234

3335
env:
3436
CUDA_VISIBLE_DEVICES: 7

.github/workflows/gems-test-on-metax.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- '**/*.cmake'
1515
- '**/*.mk'
1616
- 'Makefile'
17+
- '!src/flag_gems/experimental_ops/**'
1718
pull_request:
1819
branches: [ "master" ]
1920
paths:
@@ -27,6 +28,7 @@ on:
2728
- '**/*.cmake'
2829
- '**/*.mk'
2930
- 'Makefile'
31+
- '!src/flag_gems/experimental_ops/**'
3032

3133
jobs:
3234
op-test-on-metax:

.github/workflows/python-coverage.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- '**/*.cmake'
1515
- '**/*.mk'
1616
- 'Makefile'
17+
- '!src/flag_gems/experimental_ops/**'
1718
pull_request:
1819
branches: [ "master" ]
1920
paths:
@@ -27,6 +28,7 @@ on:
2728
- '**/*.cmake'
2829
- '**/*.mk'
2930
- 'Makefile'
31+
- '!src/flag_gems/experimental_ops/**'
3032

3133
jobs:
3234
blas-op-test:

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@ if(FLAGGEMS_BUILD_CTESTS)
8282
FetchContent_MakeAvailable(googletest)
8383
endif()
8484

85+
execute_process(
86+
COMMAND ${Python_EXECUTABLE}
87+
-c "import triton, sys; sys.stdout.write(triton.__version__)"
88+
RESULT_VARIABLE _ret
89+
OUTPUT_VARIABLE TRITON_VERSION
90+
OUTPUT_STRIP_TRAILING_WHITESPACE
91+
)
92+
if(NOT _ret EQUAL 0)
93+
message(FATAL_ERROR "Triton IS NOT installed properly")
94+
endif()
95+
if(TRITON_VERSION VERSION_GREATER_EQUAL "3.5")
96+
set(TRITON_GE_3P5 1)
97+
endif()
98+
message(STATUS "Detected Triton version: ${TRITON_VERSION}")
99+
85100
# --------------------------- subdirectories ---------------------------
86101
add_subdirectory(lib)
87102
add_subdirectory(src/flag_gems/csrc)

LICENSE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Copyright © 2024 BAAI. All rights reserved.
21

32
Apache License
43
Version 2.0, January 2004

README.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,51 @@ FlagGems can be installed either as a pure Python package or as a package with C
9898

9999
For a quick start with installing and using flag_gems, please refer to the documentation [GetStart](docs/get_start_with_flaggems.md).
100100

101+
## Usage
102+
103+
FlagGems supports two common usage patterns: patching PyTorch ATen ops (recommended) and calling FlagGems ops explicitly.
104+
105+
### (1) Enable FlagGems globally (patch ATen ops)
106+
107+
After `flag_gems.enable()`, supported `torch.*` / `torch.nn.functional.*` calls will be dispatched to FlagGems implementations automatically.
108+
109+
```python
110+
import torch
111+
import flag_gems
112+
113+
flag_gems.enable()
114+
115+
x = torch.randn(4096, 4096, device=flag_gems.device, dtype=torch.float16)
116+
y = torch.mm(x, x)
117+
```
118+
119+
If you only want FlagGems inside a scope (e.g., for benchmarking), use the context manager:
120+
121+
```python
122+
import torch
123+
import flag_gems
124+
125+
with flag_gems.use_gems():
126+
x = torch.randn(4096, 4096, device=flag_gems.device, dtype=torch.float16)
127+
y = torch.mm(x, x)
128+
```
129+
130+
### (2) Explicitly call FlagGems ops
131+
132+
You can also bypass PyTorch dispatch and call operators from `flag_gems.ops` directly (no `enable()` required):
133+
134+
```python
135+
import torch
136+
from flag_gems import ops
137+
import flag_gems
138+
139+
a = torch.randn(1024, 1024, device=flag_gems.device, dtype=torch.float16)
140+
b = torch.randn(1024, 1024, device=flag_gems.device, dtype=torch.float16)
141+
c = ops.mm(a, b)
142+
```
143+
144+
For more details and advanced options (disabling specific ops, runtime logging,e.g.), see [`how_to_use_flaggems`](docs/how_to_use_flaggems.md).
145+
101146
## Supported Operators
102147

103148
Operators will be implemented according to [OperatorList](docs/operator_list.md).
@@ -128,7 +173,7 @@ Operators will be implemented according to [OperatorList](docs/operator_list.md)
128173

129174
The following chart shows the speedup of FlagGems compared with PyTorch ATen library in eager mode. The speedup is calculated by averaging the speedup on each shape, representing the overall performance of the operator.
130175

131-
![Operator Speedup](./docs/assets/speedup-20250423.png)
176+
![Operator Speedup](./docs/assets/speedup-20251225.png)
132177

133178
## Contributions
134179

README_cn.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,50 @@ FlagGems 可以作为纯 Python 包安装,也可以作为带有 C++ 扩展的
9393

9494
参考文档 [开始使用](docs/get_start_with_flaggems.md) 快速安装使用 flag_gems
9595

96+
## 使用方法
97+
98+
FlagGems 支持两种常见的使用模式:对 PyTorch ATen 算子打补丁(推荐)和显式调用 FlagGems 算子。
99+
100+
### (1) 全局启用 FlagGems(对 ATen 算子打补丁)
101+
102+
执行 `flag_gems.enable()` 后,支持的 `torch.*` / `torch.nn.functional.*` 调用将会自动分发(dispatch)到 FlagGems 的实现上。
103+
104+
```python
105+
import torch
106+
import flag_gems
107+
108+
flag_gems.enable()
109+
110+
x = torch.randn(4096, 4096, device=flag_gems.device, dtype=torch.float16)
111+
y = torch.mm(x, x)
112+
```
113+
114+
如果你只想在某个作用域内(例如用于基准测试)使用 FlagGems,请使用上下文管理器:
115+
116+
```python
117+
import torch
118+
import flag_gems
119+
120+
with flag_gems.use_gems():
121+
x = torch.randn(4096, 4096, device=flag_gems.device, dtype=torch.float16)
122+
y = torch.mm(x, x)
123+
```
124+
125+
### (2) 显式调用 FlagGems 算子
126+
你也可以绕过 PyTorch 的分发机制,直接从 flag_gems.ops 中调用算子,此时无需调用 enable():
127+
128+
```python
129+
import torch
130+
from flag_gems import ops
131+
import flag_gems
132+
133+
a = torch.randn(1024, 1024, device=flag_gems.device, dtype=torch.float16)
134+
b = torch.randn(1024, 1024, device=flag_gems.device, dtype=torch.float16)
135+
c = ops.mm(a, b)
136+
```
137+
若要了解更多详情和高级选项(例如禁用特定算子、运行时日志等),请参阅 [`how_to_use_flaggems`](docs/how_to_use_flaggems.md)
138+
139+
96140
## 支持算子
97141

98142
算子将按照文档 [OperatorList](docs/operator_list.md) 的顺序逐步实现。
@@ -123,7 +167,7 @@ FlagGems 可以作为纯 Python 包安装,也可以作为带有 C++ 扩展的
123167

124168
FlagGems 相比 Torch Eager 模式下 ATen 算子库的加速比如下图所示。其中,每个算子的加速比综合了多个形状测例的数据,代表该算子的整体性能。
125169

126-
![算子加速比](./docs/assets/speedup-20250423.png)
170+
![算子加速比](./docs/assets/speedup-20251225.png)
127171

128172
## 贡献代码
129173

0 commit comments

Comments
 (0)