Skip to content

Commit bfced8d

Browse files
committed
Merge branch 'master' of github.com:FlagOpen/FlagGems into reshape_and_cache_flash
2 parents dcfa204 + 7b16ab7 commit bfced8d

290 files changed

Lines changed: 12589 additions & 2435 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/gems-cpp-extension.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ name: gems-cpp-extension
33
on:
44
push:
55
branches: [ "master" ]
6+
paths:
7+
- '**.py'
8+
- '**.cpp'
9+
- '**.cu'
10+
- '**.h'
11+
- '**.hpp'
12+
- '**.cc'
13+
- 'CMakeLists.txt'
14+
- '**/*.cmake'
15+
- '**/*.mk'
16+
- 'Makefile'
617
pull_request:
718
branches: [ "master" ]
19+
paths:
20+
- '**.py'
21+
- '**.cpp'
22+
- '**.cu'
23+
- '**.h'
24+
- '**.hpp'
25+
- '**.cc'
26+
- 'CMakeLists.txt'
27+
- '**/*.cmake'
28+
- '**/*.mk'
29+
- 'Makefile'
830

931
jobs:
1032
build-C-extension:

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ name: flag-gems-test-on-hopper
33
on:
44
push:
55
branches: [ "master" ]
6+
paths:
7+
- '**.py'
8+
- '**.cpp'
9+
- '**.cu'
10+
- '**.h'
11+
- '**.hpp'
12+
- '**.cc'
13+
- 'CMakeLists.txt'
14+
- '**/*.cmake'
15+
- '**/*.mk'
16+
- 'Makefile'
617
pull_request:
718
branches: [ "master" ]
19+
paths:
20+
- '**.py'
21+
- '**.cpp'
22+
- '**.cu'
23+
- '**.h'
24+
- '**.hpp'
25+
- '**.cc'
26+
- 'CMakeLists.txt'
27+
- '**/*.cmake'
28+
- '**/*.mk'
29+
- 'Makefile'
830

931
jobs:
1032
op-test-on-hopper:

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ name: flag-gems-test-on-metax
33
on:
44
push:
55
branches: [ "master" ]
6+
paths:
7+
- '**.py'
8+
- '**.cpp'
9+
- '**.cu'
10+
- '**.h'
11+
- '**.hpp'
12+
- '**.cc'
13+
- 'CMakeLists.txt'
14+
- '**/*.cmake'
15+
- '**/*.mk'
16+
- 'Makefile'
617
pull_request:
718
branches: [ "master" ]
19+
paths:
20+
- '**.py'
21+
- '**.cpp'
22+
- '**.cu'
23+
- '**.h'
24+
- '**.hpp'
25+
- '**.cc'
26+
- 'CMakeLists.txt'
27+
- '**/*.cmake'
28+
- '**/*.mk'
29+
- 'Makefile'
830

931
jobs:
1032
op-test-on-metax:

.github/workflows/python-coverage.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ name: python-coverage
33
on:
44
push:
55
branches: [ "master" ]
6+
paths:
7+
- '**.py'
8+
- '**.cpp'
9+
- '**.cu'
10+
- '**.h'
11+
- '**.hpp'
12+
- '**.cc'
13+
- 'CMakeLists.txt'
14+
- '**/*.cmake'
15+
- '**/*.mk'
16+
- 'Makefile'
617
pull_request:
718
branches: [ "master" ]
19+
paths:
20+
- '**.py'
21+
- '**.cpp'
22+
- '**.cu'
23+
- '**.h'
24+
- '**.hpp'
25+
- '**.cc'
26+
- 'CMakeLists.txt'
27+
- '**/*.cmake'
28+
- '**/*.mk'
29+
- 'Makefile'
830

931
jobs:
1032
blas-op-test:

CODE_OF_CONDUCT.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation.
6+
7+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8+
9+
## Our Standards
10+
11+
Examples of behavior that contributes to a positive environment for our community include:
12+
13+
- Demonstrating empathy and kindness toward other people
14+
- Being respectful of differing opinions, viewpoints, and experiences
15+
- Giving and gracefully accepting constructive feedback
16+
- Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17+
- Focusing on what is best not just for us as individuals, but for the overall community
18+
19+
Examples of unacceptable behavior include:
20+
21+
- The use of sexualized language or imagery, and sexual attention or advances of any kind
22+
- Trolling, insulting or derogatory comments, and personal or political attacks
23+
- Public or private harassment
24+
- Publishing others' private information, such as a physical or email address, without their explicit permission
25+
- Other conduct which could reasonably be considered inappropriate in a professional setting
26+
27+
## Enforcement Responsibilities
28+
29+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
32+
33+
## Scope
34+
35+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
36+
37+
## Enforcement
38+
39+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement in the WeChat Group. All complaints will be reviewed and investigated promptly and fairly.
40+
41+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
42+
43+
## Enforcement Guidelines
44+
45+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
46+
47+
### 1. Correction
48+
49+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
50+
51+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
52+
53+
### 2. Warning
54+
55+
**Community Impact**: A violation through a single incident or series of actions.
56+
57+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
58+
59+
### 3. Temporary Ban
60+
61+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
62+
63+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
64+
65+
### 4. Permanent Ban
66+
67+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
68+
69+
**Consequence**: A permanent ban from any sort of public interaction within the community.
70+
71+
## Attribution
72+
73+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
74+
75+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
76+
77+
For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations].
78+
79+
[homepage]: https://www.contributor-covenant.org
80+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
81+
[Mozilla CoC]: https://github.com/mozilla/diversity
82+
[FAQ]: https://www.contributor-covenant.org/faq
83+
[translations]: https://www.contributor-covenant.org/translations

CONTRIBUTING.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@ The documentation for FlagGems is stored in the `docs` directory and is currentl
2727
FlagGems
2828
├── src // python source code
2929
│ └──flag_gems
30-
│ ├──utils // python automatic code generation utilities
30+
│ ├──csrc // C source
31+
│ ├──utils // python utilities
3132
│ ├──ops // python single operators
3233
│ ├──fused // python fused operators
34+
│ ├──modules // python modules
35+
│ ├──patches // patching scripts
3336
│ ├──testing // python testing utility
3437
├── tests // python accuracy test files
3538
├── benchmark // python performance test files
36-
├── examples // python model test files
39+
├── examples // examples
3740
├── cmake // c++ cmake files for C-extension
3841
├── include // c++ headers
3942
├── lib // c++ source code for operator lib

CONTRIBUTING_cn.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ FlagGems 的文档存放在 `docs` 目录下,并且当前使用 [MkDocs](https
2424
FlagGems
2525
├── src // python 源码
2626
│ └──flag_gems
27-
│ ├──utils // python 自动代码生成
28-
│ ├──ops // python 单个算子
27+
│ ├──csrc // C 源文件
28+
│ ├──utils // python utils
29+
│ ├──ops // python 独立算子
2930
│ ├──fused // python 融合算子
30-
│ ├──testing // python 算子测试组件
31+
│ ├──modules // python 模块
32+
│ ├──patches // 布丁脚本
33+
│ ├──testing // python 测试
3134
├── tests // python 算子精度测试
3235
├── benchmark // python 算子性能测试
3336
├── examples // python 模型性能测试

MAINTAINERS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Maintainers
2+
3+
| **GithubID** | **Email Address** |
4+
| ------------ | ------------------------ |
5+
| tongxin | waffle.bai@gmail.com |
6+
| StrongSpoon | strongspoon@outlook.com |
7+
| iclementine | iclementine@outlook.com |
8+
| Bowen12992 | zhangbluestars@gmail.com |
9+
| 0x45f | wangzhen@baai.ac.cn |
10+
| kiddyjinjin | kiddyjinjin@gmail.com |
11+
| Galaxy1458 | rlyanger01@gmail.com |
12+
| zhzhcookie | zhengyang_pku@126.com |

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
## Introduction
66

7-
FlagGems is a high-performance general operator library implemented in [OpenAI Triton](https://github.com/openai/triton). It aims to provide a suite of kernel functions to accelerate LLM training and inference.
7+
FlagGems is a high-performance general operator library implemented in [OpenAI Triton](https://github.com/openai/triton). It builds on a collection of backend neutral kernels that aims to accelerate LLM training and inference across diverse hardware platforms.
88

9-
By registering with the ATen backend of PyTorch, FlagGems facilitates a seamless transition, allowing users to switch to the Triton function library without the need to modify their model code. Users can still utilize the ATen backend as usual while experiencing significant performance enhancement. The Triton language offers benefits in readability, user-friendliness and performance comparable to CUDA. This convenience allows developers to engage in the development of FlagGems with minimal learning investment.
9+
By registering with the ATen backend of PyTorch, FlagGems facilitates a seamless transition, allowing model developers to switch to Triton without changing the low level APIs. Users can still use their familiar Pytorch APIs as usual and benefit from new hardware acceleration technologies. For kernel developers, the Triton language offers readability, user-friendliness and performance comparable to CUDA. This convenience allows developers to engage in the development of FlagGems with minimal learning investment.
1010

1111
We created WeChat group for FlagGems. Scan the QR code to join the group chat! To get the first hand message about our updates and new release, or having any questions or ideas, join us now!
1212

@@ -16,41 +16,61 @@ We created WeChat group for FlagGems. Scan the QR code to join the group chat! T
1616

1717
## Features
1818

19+
FlagGems provides the following technical features.
20+
21+
- A large collection of PyTorch compatible operators
22+
- Hand optimized performance for selective operators
23+
- Eager mode ready, independent of torch.compile
24+
- Automatic pointwise operator codegen supporting arbitrary input types and layout
25+
- Fast per-function runtime kernel dispatching
26+
- Multi-backend interface enabling support of diverse hardware platforms
27+
- Over 10 supported backends
28+
- C++ Triton function dispatcher (working in progress)
29+
30+
## More About Features
31+
1932
### Multi-Backend Hardware Support
33+
2034
FlagGems supports a wide range of hardware platforms and has been extensively tested across different hardware configurations.
2135

2236
### Automatic Codegen
37+
2338
FlagGems provides an automatic code generation mechanism that enables developers to easily generate both pointwise and fused operators.
2439
The auto-generation system supports a variety of needs, including standard element-wise computations, non-tensor parameters, and specifying output types.
25-
For more details, please refer to pointwise_dynamic(docs/pointwise_dynamic.md).
40+
For more details, please refer to [pointwise_dynamic](docs/pointwise_dynamic.md).
2641

2742
### LibEntry
43+
2844
FlagGems introduces `LibEntry`, which independently manages the kernel cache and bypasses the runtime of `Autotuner`, `Heuristics`, and `JitFunction`. To use it, simply decorate the Triton kernel with LibEntry.
2945

3046
`LibEntry` also supports direct wrapping of `Autotuner`, `Heuristics`, and `JitFunction`, preserving full tuning functionality. However, it avoids nested runtime type invocations, eliminating redundant parameter processing. This means no need for binding or type wrapping, resulting in a simplified cache key format and reduced unnecessary key computation.
3147

3248
### C++ Runtime
49+
3350
FlagGems can be installed either as a pure Python package or as a package with C++ extensions. The C++ runtime is designed to address the overhead of the Python runtime and improve end-to-end performance.
3451
For more details, please refer to [c++ extensions](docs/build_flaggems_with_c_extensions.md).
3552

3653
## Changelog
3754

3855
### v1.0
56+
3957
- support BLAS operators: addmm, bmm, mm
4058
- support pointwise operators: abs, add, div, dropout, exp, gelu, mul, pow, reciprocal, relu, rsqrt, silu, sub, triu
4159
- support reduction operators: cumsum, layernorm, mean, softmax
4260

4361
### v2.0
62+
4463
- support BLAS operators: mv, outer
4564
- support pointwise operators: bitwise_and, bitwise_not, bitwise_or, cos, clamp, eq, ge, gt, isinf, isnan, le, lt, ne, neg, or, sin, tanh, sigmoid
4665
- support reduction operators: all, any, amax, argmax, max, min, prod, sum, var_mean, vector_norm, cross_entropy_loss, group_norm, log_softmax, rms_norm
4766
- support fused operators: fused_add_rms_norm, skip_layer_norm, gelu_and_mul, silu_and_mul, apply_rotary_position_embedding
4867

4968
### v2.1
69+
5070
- support Tensor operators: where, arange, repeat, masked_fill, tile, unique, index_select, masked_select, ones, ones_like, zeros, zeros_like, full, full_like, flip, pad
5171
- support neural network operator: embedding
5272
- support basic math operators: allclose, isclose, isfinite, floor_divide, trunc_divide, maximum, minimum
53-
- support distribution operators: normal, uniform_, exponential_, multinomial, nonzero, topk, rand, randn, rand_like, randn_like
73+
- support distribution operators: normal, uniform\_, exponential\_, multinomial, nonzero, topk, rand, randn, rand_like, randn_like
5474
- support science operators: erf, resolve_conj, resolve_neg
5575

5676
## Get Start
@@ -61,17 +81,28 @@ For a quick start with installing and using flag_gems, please refer to the docum
6181

6282
Operators will be implemented according to [OperatorList](docs/operator_list.md).
6383

64-
## Supported Models
84+
## Example Models
6585

6686
- Bert-base-uncased
6787
- Llama-2-7b
6888
- Llava-1.5-7b
6989

90+
7091
## Supported Platforms
7192

72-
| Platform | float16 | float32 | bfloat16 |
73-
| :---: | :---: | :---: | :---: |
74-
| Nvidia GPU ||||
93+
| vendor | state | float16 | float32 | bfloat16 |
94+
| ----------- | ----------- |-----------|-----------|-----------|
95+
| aipu | ✅ (Partial support) ||||
96+
| ascend | ✅ (Partial support) ||||
97+
| cambricon |||||
98+
| hygon |||||
99+
| iluvatar |||||
100+
| kunlunxin |||||
101+
| metax |||||
102+
| mthreads |||||
103+
| nvidia |||||
104+
| arm(cpu) | 🚧 | | | |
105+
| tsingmicro | 🚧 | | | |
75106

76107
## Performance
77108

0 commit comments

Comments
 (0)