Giter Club home page Giter Club logo

Comments (10)

ptillet avatar ptillet commented on July 22, 2024 1

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.

ptillet avatar ptillet commented on July 22, 2024

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.

Young768 avatar Young768 commented on July 22, 2024

thx

from triton.

Young768 avatar Young768 commented on July 22, 2024

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

ζˆͺ屏2021-05-22 上午1 12 38

from triton.

ptillet avatar ptillet commented on July 22, 2024

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.

Young768 avatar Young768 commented on July 22, 2024

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.

ptillet avatar ptillet commented on July 22, 2024

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.

Young768 avatar Young768 commented on July 22, 2024

Could you please give some explanation on "how" to reduce the row in triton implementation?

from triton.

Young768 avatar Young768 commented on July 22, 2024

Thanks. Last question. Is this softmax specifically different from the softmax used for full attention, i.e. full spMM.

from triton.

ptillet avatar ptillet commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.