赞
踩
xFormers是一个基于PyTorch的库,其中包含灵活的Transformers 组件。
它们是可互操作和优化的构建块,可以选择组合以创建一些最先进的模型。
conda install xformers -c xformers
# cuda 11.8 version
pip3 install -U xformers --index-url https://download.pytorch.org/whl/cu118
# cuda 12.1 version
pip3 install -U xformers --index-url https://download.pytorch.org/whl/cu121
# Use either conda or pip, same requirements as for the stable version above
conda install xformers -c xformers/label/dev
pip install --pre -U xformers
# (Optional) Makes the build much faster
pip install ninja
# Set TORCH_CUDA_ARCH_LIST if running and building on different GPU types
pip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers
# (this can take dozens of minutes)
Memory-efficient MHA
设置:f16上的A100,测量前进+后退传球的总时间
请注意,这是精确的关注,而不是近似值,只需调用xformers.ops.memory_efficient_attention
更多 benchmarks
xFormers提供了许多组件,BENCHMARKS.md中提供了更多基准测试。
此命令将提供有关xFormers安装的信息,以及构建/可用的内核:
python -m xformers.info
让我们从变形金刚架构的经典概述开始(插图来自Lin et al,“A Survey of Transformers”)
在这个例子中,你会发现关键的存储库边界:转换器通常由注意力机制、编码一些位置信息的嵌入、前馈块和残差路径(通常称为前层或后层范数)的集合组成。这些边界并不适用于所有模型,但我们在实践中发现,如果有一些调整,它可以捕捉到大部分最先进的技术。
因此,模型不是在单体文件中实现的,这些文件通常很难处理和修改。上图中出现的大多数概念对应于抽象级别,当给定子块存在变体时,应该始终可以选择其中任何一个。您可以专注于给定的封装级别并根据需要进行修改。
├── ops # Functional operators
└ ...
├── components # Parts zoo, any of which can be used directly
│ ├── attention
│ │ └ ... # all the supported attentions
│ ├── feedforward #
│ │ └ ... # all the supported feedforwards
│ ├── positional_embedding #
│ │ └ ... # all the supported positional embeddings
│ ├── activations.py #
│ └── multi_head_dispatch.py # (optional) multihead wrap
|
├── benchmarks
│ └ ... # A lot of benchmarks that you can use to test some parts
└── triton
└ ... # (optional) all the triton parts, requires triton + CUDA gpu
module unload cuda; module load cuda/xx.x
,也可能是nvcc
TORCH_CUDA_ARCH_LIST
env变量设置为您想要支持的体系结构。建议的设置(构建缓慢但全面)是export TORCH_CUDA_ARCH_LIST="6.0;6.1;6.2;7.0;7.2;7.5;8.0;8.6"
MAX_JOBS
的并行性(例如MAX_JOBS=2
)UnsatisfiableError
,请确保您在conda环境中安装了PyTorch,并且您的设置(PyTorch版本、cuda版本、python版本、操作系统)匹配xFormers的现有二进制文件2024-07-17(三)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。