Skip to content

Commit e507584

Browse files
committed
Adds comprehensive contributing guidelines
Establishes clear contribution guidelines covering bug reports, feature requests, development setup, and pull request processes. Includes specific guidance for CUDA development, testing requirements, and performance benchmarking to ensure quality contributions to the Flash Dynamic Mask Attention library.
1 parent bc2a8dc commit e507584

File tree

1 file changed

+205
-0
lines changed

1 file changed

+205
-0
lines changed

CONTRIBUTING.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
# Contributing to Flash Dynamic Mask Attention
2+
3+
Everyone is welcome to contribute, and we value everybody's contribution. Code contributions are not the only way to help the community. Answering questions, helping others, and improving the documentation are also immensely valuable.
4+
5+
It also helps us if you spread the word! Reference the library in blog posts about the awesome projects it made possible, shout out on Twitter every time it has helped you, or simply ⭐️ the repository to say thank you.
6+
7+
However you choose to contribute, please be mindful and respect our [code of conduct](https://github.com/SmallDoges/flash-dmattn/blob/main/CODE_OF_CONDUCT.md).
8+
9+
## Ways to contribute
10+
11+
There are several ways you can contribute to Flash-DMA:
12+
13+
* Fix outstanding issues with the existing code.
14+
* Submit issues related to bugs or desired new features.
15+
* Implement new attention mechanisms or optimizations.
16+
* Contribute to the examples, benchmarks, or documentation.
17+
* Improve CUDA kernel performance.
18+
19+
If you don't know where to start, there is a special [Good First Issue](https://github.com/SmallDoges/flash-dmattn/contribute) listing. It will give you a list of open issues that are beginner-friendly and help you start contributing to open-source.
20+
21+
> All contributions are equally valuable to the community. 🥰
22+
23+
## Fixing outstanding issues
24+
25+
If you notice an issue with the existing code and have a fix in mind, feel free to [start contributing](#create-a-pull-request) and open a Pull Request!
26+
27+
## Submitting a bug-related issue or feature request
28+
29+
Do your best to follow these guidelines when submitting a bug-related issue or a feature request. It will make it easier for us to come back to you quickly and with good feedback.
30+
31+
### Did you find a bug?
32+
33+
The Flash-DMA library is robust and reliable thanks to users who report the problems they encounter.
34+
35+
Before you report an issue, we would really appreciate it if you could **make sure the bug was not already reported** (use the search bar on GitHub under Issues). Your issue should also be related to bugs in the library itself, and not your code.
36+
37+
Once you've confirmed the bug hasn't already been reported, please include the following information in your issue so we can quickly resolve it:
38+
39+
* Your **OS type and version** and **Python**, **PyTorch**, and **CUDA** versions.
40+
* Your **GPU model** and **CUDA Compute Capability**.
41+
* A short, self-contained, code snippet that allows us to reproduce the bug in less than 30s.
42+
* The *full* traceback if an exception is raised.
43+
* Attach any other additional information, like screenshots, you think may help.
44+
45+
To get the environment information automatically, run:
46+
47+
```bash
48+
python -c "import torch; print(f'PyTorch: {torch.__version__}'); print(f'CUDA: {torch.version.cuda}'); print(f'GPU: {torch.cuda.get_device_name() if torch.cuda.is_available() else \"None\"}')"
49+
```
50+
51+
### Do you want a new feature?
52+
53+
If there is a new feature you'd like to see in Flash-DMA, please open an issue and describe:
54+
55+
1. What is the *motivation* behind this feature? Is it related to performance optimization, memory efficiency, or new attention mechanisms?
56+
57+
2. Describe your requested feature in as much detail as possible. The more you can tell us about it, the better we'll be able to help you.
58+
59+
3. Provide a *code snippet* that demonstrates the feature's usage.
60+
61+
4. If the feature is related to a paper, please include a link.
62+
63+
## Do you want to implement a new attention mechanism?
64+
65+
New attention mechanisms and optimizations are constantly being developed. If you want to implement a new mechanism, please provide:
66+
67+
* A short description of the attention mechanism and a link to the paper.
68+
* Link to the implementation if it is open-sourced.
69+
* Performance benchmarks compared to existing methods.
70+
* CUDA compute capability requirements.
71+
72+
## Do you want to add documentation?
73+
74+
We're always looking for improvements to the documentation that make it more clear and accurate. Please let us know how the documentation can be improved such as typos and any content that is missing, unclear or inaccurate.
75+
76+
## Create a Pull Request
77+
78+
Before writing any code, we strongly advise you to search through the existing PRs or issues to make sure nobody is already working on the same thing.
79+
80+
You will need basic `git` proficiency to contribute to Flash-DMA. You'll need **Python 3.8+** and **CUDA 11.8+** to contribute.
81+
82+
### Development Setup
83+
84+
1. Fork the [repository](https://github.com/SmallDoges/flash-dmattn) by clicking on the **Fork** button.
85+
86+
2. Clone your fork to your local disk, and add the base repository as a remote:
87+
88+
```bash
89+
git clone https://github.com/<your Github handle>/flash-dmattn.git
90+
cd flash-dmattn
91+
git remote add upstream https://github.com/SmallDoges/flash-dmattn.git
92+
```
93+
94+
3. Create a new branch to hold your development changes:
95+
96+
```bash
97+
git checkout -b a-descriptive-name-for-my-changes
98+
```
99+
100+
🚨 **Do not** work on the `main` branch!
101+
102+
4. Set up a development environment:
103+
104+
```bash
105+
# Ensure CUDA environment is properly set up
106+
export CUDA_HOME=/usr/local/cuda # Adjust path as needed
107+
108+
# Install in development mode
109+
pip install -e .
110+
111+
# Install development dependencies
112+
pip install pytest numpy
113+
```
114+
115+
5. Develop the features in your branch.
116+
117+
As you work on your code, you should make sure the test suite passes:
118+
119+
```bash
120+
python -m pytest tests/ -v
121+
```
122+
123+
Flash-DMA also includes performance benchmarks. Run them to ensure your changes don't regress performance:
124+
125+
```bash
126+
python benchmarks/forward_performance.py
127+
python benchmarks/forward_equivalence.py
128+
```
129+
130+
For CUDA development, ensure your changes compile across supported architectures:
131+
132+
```bash
133+
python setup.py build_ext --inplace
134+
```
135+
136+
6. Once you're happy with your changes, add changed files using `git add` and record your changes with `git commit`:
137+
138+
```bash
139+
git add .
140+
git commit -m "A descriptive commit message"
141+
```
142+
143+
Please write [good commit messages](https://chris.beams.io/posts/git-commit/).
144+
145+
7. Go to your fork on GitHub and click on **Pull Request** to open a pull request.
146+
147+
### Pull request checklist
148+
149+
☐ The pull request title should summarize your contribution.<br>
150+
☐ If your pull request addresses an issue, please mention the issue number in the pull request description to make sure they are linked.<br>
151+
☐ To indicate a work in progress please prefix the title with `[WIP]`.<br>
152+
☐ Make sure existing tests pass.<br>
153+
☐ If adding a new feature, also add tests for it.<br>
154+
☐ If implementing new CUDA kernels, ensure they work across all supported compute capabilities (SM 8.0+).<br>
155+
☐ All public methods must have informative docstrings.<br>
156+
☐ Performance benchmarks should not regress significantly.<br>
157+
158+
### Tests
159+
160+
An extensive test suite is included to test the library behavior and performance. Tests can be found in the [tests](https://github.com/SmallDoges/flash-dmattn/tree/main/tests) folder and benchmarks in the [benchmarks](https://github.com/SmallDoges/flash-dmattn/tree/main/benchmarks) folder.
161+
162+
We use `pytest` for testing. From the root of the repository, run:
163+
164+
```bash
165+
python -m pytest tests/ -v
166+
```
167+
168+
For performance testing:
169+
170+
```bash
171+
python -m pytest benchmarks/ -v
172+
```
173+
174+
### CUDA Development Guidelines
175+
176+
When contributing CUDA code:
177+
178+
1. **Test across architectures**: Ensure your code works on SM 8.0, 9.0, and 10.0.
179+
2. **Memory efficiency**: Profile memory usage and ensure no memory leaks.
180+
3. **Performance**: Benchmark against existing implementations.
181+
4. **Documentation**: Document kernel parameters and expected performance characteristics.
182+
183+
### Code Style
184+
185+
We follow standard Python code style guidelines:
186+
187+
* Use descriptive variable names
188+
* Add type hints where applicable
189+
* Follow PEP 8 guidelines
190+
* Add docstrings to all public functions
191+
192+
For CUDA code:
193+
* Use clear variable names
194+
* Comment complex kernel logic
195+
* Follow NVIDIA CUDA best practices
196+
197+
## Security
198+
199+
If you discover a security vulnerability, please send an e-mail to the maintainers. All security vulnerabilities will be promptly addressed.
200+
201+
## Questions?
202+
203+
If you have questions about contributing, feel free to ask in the [GitHub Discussions](https://github.com/SmallDoges/flash-dmattn/discussions) or open an issue.
204+
205+
Thank you for contributing to Flash Dynamic Mask Attention! 🚀

0 commit comments

Comments
 (0)