Comments (3)
@krishnadubba Have you successfully implement the strided version btw? Could you share the code change?
I was able to reproduce the patterns using this function.
`
def sparse_attention_mask(n_tokens, stride_length=3, c=2):
x = tf.reshape(tf.range(n_tokens), [n_tokens, 1])
y = tf.transpose(x)
z = tf.zeros((n_tokens,n_tokens))
Q = z + x
K = z + y
causal_attention_mask = (Q>=K)
fixed_mask_1 = tf.equal(Q//stride_length, K//stride_length)
fixed_mask_2 = tf.logical_and(tf.math.floormod(K, stride_length) >= stride_length-c, tf.math.floormod(K, stride_length)<=stride_length)
combined_mask_fixed = tf.logical_and(causal_attention_mask, tf.logical_or(fixed_mask_1, fixed_mask_2))
stride_mask_1 = tf.less_equal(Q-K, stride_length)
stride_mask_2 = tf.equal(tf.math.floormod(Q-K, stride_length), 0)
combined_mask_stride = tf.logical_and(causal_attention_mask, tf.logical_or(stride_mask_1, stride_mask_2))
return tf.reshape(combined_mask_fixed, [1, 1, n_tokens, n_tokens]), tf.reshape(combined_mask_stride, [1, 1, n_tokens, n_tokens])`
from sparse_attention.
After reading this code -- "attention.py", I find this base code only contains separate implementations of strided attention, called "first / second step of strided attention" within it. Therefore, you perhaps need to implement a integral version of strided attention by yourself with each head corresponding to one of aforementioned two steps for a two head sparse self-attention.
from sparse_attention.
@krishnadubba Have you successfully implement the strided version btw? Could you share the code change?
from sparse_attention.
Related Issues (10)
- Has anyone been able to reproduce the results for image generation?
- version of TensorFlow and python
- What is the LICENSE?
- Expected throughput?
- Questions about novelty HOT 2
- Great work! but seems insufficient "related work"
- PyTorch Implementation HOT 2
- can it be used for cpu?
- a problem in running code HOT 1
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 sparse_attention.