Comments (10)
Sure! You can find a block-sparse attention example there https://github.com/ptillet/triton/blob/master/python/test/test_blocksparse.py#L150-L159. You can create a block-sparse softmax operation as follows:
sparse_softmax = triton.ops.blocksparse.softmax(layout, block)
and then call it on the output of a SDD matmul
from triton.
This is general block-sparse spMM. There are three modes:
- SDD: sparse = dense x dense, a.k.a. sampled dense-dense matrix multiplication
- DSD: dense = sparse x dense, the lhs is sparse
- DDS: dense = dense x sparse, the rhs is sparse
The output of SDD is in a block-sparse format that can be re-used for triton.ops.blocksparse.softmax
and also by DSD for attention mechanisms.
from triton.
thx
from triton.
Hi what's the definition of block here? Is it to blockify the matrix and then do the MM?
I'm looking to implement the block sparse attention proposed by bigbird using triton ops. I want to know how to obtain the block
in triton. Thanks
from triton.
The sparsity layout is specified as a tensor of 0s and 1s. On your example, this would only work if each colored square corresponds to a 16x16 (or 32x32, 64x64, 128x128) block of data. Also note that triton.ops.blocksparse
doesn't support overlapping blocks
from triton.
Thanks. There won't be any overlapping blocks during attention. And the block size in default is 64X64.
Does triton provide any optimized softmax
or layernorm
kernel for the output from block sparse MM?
from triton.
No layernorm, but you can use triton.ops.blocksparse.softmax to reduce the row of the output of triton.ops.blocksparse.matmul('SDD').
from triton.
Could you please give some explanation on "how" to reduce the row in triton implementation?
from triton.
Thanks. Last question. Is this softmax
specifically different from the softmax
used for full attention, i.e. full spMM.
from triton.
Hmm, it should be the same. You can also pass dense masks since a block-triangular matrix is not triangular (the blocks on the diagonals are dense). There are example usages here https://github.com/ptillet/triton/blob/master/python/test/test_blocksparse.py#L47
from triton.
Related Issues (20)
- Trivial outputs on MacOS using TRITON_INTERPRET=1 HOT 7
- 导入default_dump_dir报错
- What is the use of calling `propagateIfChanged` in `ConstantAnalysis::visit`
- Flash Attention benchmarks fail on AMD Instinct MI210 (`gfx90a`) HOT 2
- [OPS] AttributeError: module 'triton.language.math' has no attribute 'round' HOT 3
- Why is the documentation not versioned like other Read The Docs sites?
- Core dumped without "os.environ["TRITON_INTERPRET"] = "1"
- torch 2.4.0 requires triton==3.0.0; HOT 7
- Triton trying to download llvm even if self built, and build failed
- Seems mistake in setup.py HOT 1
- bfloat16 of fused attention seems have bug HOT 2
- Possible to use WMMA `.b1` instructions? HOT 1
- AttributeError("'AnnAssign' object has no attribute 'targets'") HOT 1
- [Bug] Compiler error in 06-fused-attention.py
- Fused Attention FP8 correctness on L20(Ada GPU) HOT 1
- What impact does changing the kernel shape's divisibility value have?
- Does Triton have a roadmap plan?
- FP8 Casting Tensor Size Alignment Error on AMD MI210 HOT 1
- Output dtype of 09-persistent-matmul.py
- Worse performance on `H100` than `RTX3090`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from triton.