Examples of using sparse attention, as in "Generating Long Sequences with Sparse Transformers"
openai/sparse_attention 排名第 9,854,有 1,613 个星标。
同类别比较
openai/sparse_attention 排名第 9,854,此处有 8 个同类条目;pypose/pypose 排名第 9,852。
同类别比较| 名称 | 排名 | 指标 |
|---|
| timoschick/pet | 9,838 | - 语言:
- Python
- 星标数:
- 1,623
- 分叉数:
- 280
- 简介:
- This repository contains the code for "Exploiting Cloze Questions for Few-Shot Text Classification and Natural Language Inference"
|
|---|
| dotnet/infer | 9,846 | - 语言:
- C#
- 星标数:
- 1,616
- 分叉数:
- 241
- 简介:
- Infer.NET is a framework for running Bayesian inference in graphical models
|
|---|
| cdipaolo/goml | 9,851 | - 语言:
- Go
- 星标数:
- 1,615
- 分叉数:
- 132
- 简介:
- On-line Machine Learning in Go (and so much more)
|
|---|
| pypose/pypose | 9,852 | - 语言:
- Python
- 星标数:
- 1,615
- 分叉数:
- 138
- 简介:
- A library for differentiable robotics on manifolds.
|
|---|
| JustGlowing/minisom | 9,865 | - 语言:
- Python
- 星标数:
- 1,609
- 分叉数:
- 446
- 简介:
- :red_circle: MiniSom is a minimalistic implementation of the Self Organizing Maps
|
|---|
| experiencor/keras-yolo3 | 9,870 | - 语言:
- Python
- 星标数:
- 1,608
- 分叉数:
- 834
- 简介:
- Training and Detecting Objects with YOLO3
|
|---|
| Delta-ML/delta | 9,872 | - 语言:
- Python
- 星标数:
- 1,607
- 分叉数:
- 281
- 简介:
- DELTA is a deep learning based natural language and speech processing platform. LF AI & DATA Projects: https://lfaidata.foundation/projects/delta/
|
|---|
| facebookresearch/ClassyVision | 9,873 | - 语言:
- Python
- 星标数:
- 1,607
- 分叉数:
- 272
- 简介:
- An end-to-end PyTorch framework for image and video classification
|
|---|
关键参数与规格
关键参数与规格| 参数 | 值 |
|---|
| 语言 | Python |
|---|
| 类别 | Model Development |
|---|
| 子类别 | Architecture |
|---|
| 星标数 | 1,613 |
|---|
| 分叉数 | 192 |
|---|
| 贡献者 | 1 |
|---|
| 创建日期 | 2019-04-12 |
|---|
| 更新日期 | 2026-10-13 |
|---|
| 1 天星标数 | 0 |
|---|
| 7 天星标数 | 1 |
|---|
| 排名 | 9,854 |
|---|
| 上次排名 | 9,892 |
|---|
| 排名变化 | 38 |
|---|
| 7 天星标排名 | 9,713 |
|---|
| 上次 7 天星标排名 | 9,768 |
|---|
| 7 天星标排名变化 | 55 |
|---|
| 总星标排名 | 7,611 |
|---|
| 上次总星标排名 | 7,607 |
|---|
| 总星标排名变化 | -4 |
|---|
| 国家 | USA |
|---|
README 摘录
**Status:** Archive (code is provided as-is, no updates expected) **Update August 2020:** For an example repository that achieves state-of-the-art modeling performance on CIFAR-10 using Sparse Transformers, please see Sparse Attention This repository contains the sparse attention primitives used in Sparse Transformers (see blog and paper). Specifically, it includes the following: 1) A faster implementation of normal attention (the upper triangle is not computed, and many operations are fused). 2) An implementation of "strided" and "fixed
" attention, as in the Sparse Transformers paper. 3) A simple recompute decorator, which can be adapted for usage with attention. We hope this code can further accelerate research into sparse attention. An example Transformer implementation which is close to the version we use internally can be found at Overview of kernels The repository contains fused implementations of the attention operation, which takes in , , matrices (all of dimensionality ) representing the queries, keys, and values for a sequence. For every query element
, a weighted sum of the values is returned, where the weightings are determined by the scaled matrix product of and . The kernels allow specification of block sparsity in the matrix. This means you define a pattern of 0/1s on a matrix of blocks, and the values where it is 0 will not be computed, and not be included in the softmax calculation. Additionally, one can define "callbacks" on the computed blocks, which will further mask out values in any
given block from the softmax (though the matrix product will still be computed for those elements). Block sizes of are supported, and slight advantages in speed may be seen from using larger blocks. Prerequisites For fp32 and blocksize , any NVIDIA GPU past Kepler can be used (i. For fp16 and blocksize , a GPU with Tensor Cores (e. The primary dependency is the OpenAI blocksparse package. With CUDA 10 and tensorflow-gpu, you can install blocksparse with . For other setups, you
must install blocksparse from source, and directions can be found in the root of the repository. Examples Run the following on a non-V100 GPU: On a V100 GPU: General usage An example can be found at the bottom of . Referencing this work If you find this helpful in your work, you can consider citing the following:
常见问题
记录了多少星标和分叉?
openai/sparse_attention 有 1,613 个星标和 192 个分叉。
仓库排名是多少?
openai/sparse_attention 排名第 9,854。
记录的语言和类别是什么?
openai/sparse_attention 有 1,613 个星标,语言为 Python,类别为 Model Development。
哪个仓库排名最接近?
openai/sparse_attention 与 pypose/pypose 比较,后者排名第 9,852,有 1,615 个星标。
Status: Archive (code is provided as-is, no updates expected)
Update August 2020: For an example repository that achieves state-of-the-art modeling performance on CIFAR-10 using Sparse Transformers, please see https://github.com/openai/distribution_augmentation
Sparse Attention
This repository contains the sparse attention primitives used in Sparse Transformers (see blog and paper). Specifically, it includes the following:
- A faster implementation of normal attention (the upper triangle is not computed, and many operations are fused).
- An implementation of "strided" and "fixed" attention, as in the Sparse Transformers paper.
- A simple recompute decorator, which can be adapted for usage with attention.
We hope this code can further accelerate research into sparse attention.
An example Transformer implementation which is close to the version we use internally can be found at https://github.com/openai/blocksparse/blob/master/examples/transformer/enwik8.py.
Overview of kernels
The repository contains fused implementations of the attention operation, which takes in Q, K, V matrices (all of dimensionality batch, time, dim) representing the queries, keys, and values for a sequence. For every query element, a weighted sum of the values is returned, where the weightings are determined by the scaled matrix product of Q and K^T.
The kernels allow specification of block sparsity in the QK^T matrix. This means you define a pattern of 0/1s on a [time/blocksize, time/blocksize] matrix of blocks, and the values where it is 0 will not be computed, and not be included in the softmax calculation. Additionally, one can define "callbacks" on the computed blocks, which will further mask out values in any given block from the softmax (though the matrix product will still be computed for those elements).
Block sizes of {8, 16, 32, 64} are supported, and slight advantages in speed may be seen from using larger blocks.
Prerequisites
For fp32 and blocksize 32, any NVIDIA GPU past Kepler can be used (i.e. compute capability beyond 3.5).
For fp16 and blocksize 8, 16, 32, 64, a GPU with Tensor Cores (e.g. the V100 GPU, compute capability >= 7.0) is required.
The primary dependency is the OpenAI blocksparse package.
With CUDA 10 and tensorflow-gpu, you can install blocksparse with pip install blocksparse.
For other setups, you must install blocksparse from source, and directions can be found in the root of the repository.
Examples
Run the following on a non-V100 GPU:
python attention.py
On a V100 GPU:
python attention.py fp16
General usage
An example can be found at the bottom of attention.py.
full_attn_tf = attention_impl(q, k, v, heads=4, attn_mode="all", recompute=True)
full_attn_bs = blocksparse_attention_impl(q, k, v, heads=4, attn_mode="all", recompute=True)
# first step of strided attention
local_attn_bs = blocksparse_attention_impl(q, k, v, heads=4, attn_mode="local", local_attn_ctx=32, recompute=True)
local_attn_tf = attention_impl(q, k, v, heads=4, attn_mode="local", local_attn_ctx=32, recompute=True)
# second step of strided attention
strided_attn_bs = blocksparse_attention_impl(q, k, v, heads=4, attn_mode="strided", local_attn_ctx=32, recompute=True)
strided_attn_tf = attention_impl(q, k, v, heads=4, attn_mode="strided", local_attn_ctx=32, recompute=True)
# # the 'fixed' attention pattern
fixed = blocksparse_attention_impl(q, k, v, heads=4, attn_mode="fixed", local_attn_ctx=128, num_verts=4, vertsize=1, recompute=True)
Referencing this work
If you find this helpful in your work, you can consider citing the following:
@article{child2019sparsetransformer,
title={Generating Long Sequences with Sparse Transformers},
author={Child, Rewon and Gray, Scott and Radford, Alec and Sutskever, Ilya},
journal={URL https://openai.com/blog/sparse-transformers},
year={2019}
}