注意:FasterTransformer 開發已過渡到 TensorRT-LLM。我們鼓勵所有開發人員利用 TensorRT-LLM 來獲得 LLM Inference 的最新改進。 NVIDIA/FasterTransformer 儲存庫將保持不變,但不會有進一步的開發。
該儲存庫提供了一個腳本和配方來運行高度優化的基於變壓器的編碼器和解碼器元件,並由 NVIDIA 進行測試和維護。
在 NLP 中,編碼器和解碼器是兩個重要的元件,變壓器層成為這兩個元件的流行架構。 FasterTransformer 為編碼器和解碼器實作了高度最佳化的轉換器層以進行推理。在 Volta、Turing 和 Ampere GPU 上,當資料和權重的精確度為 FP16 時,會自動使用 Tensor Core 的運算能力。
FasterTransformer 建構在 CUDA、cuBLAS、cuBLASLt 和 C++ 之上。我們提供以下框架的至少一種 API:TensorFlow、PyTorch 和 Triton 後端。使用者可以將FasterTransformer直接整合到這些框架中。對於支援框架,我們還提供了範例程式碼來演示如何使用,並展示這些框架的效能。
型號 | 框架 | FP16 | INT8(圖靈之後) | 稀疏性(安培之後) | 張量平行 | 管道並聯 | FP8(繼料斗之後) |
---|---|---|---|---|---|---|---|
伯特 | TensorFlow | 是的 | 是的 | - | - | - | - |
伯特 | 火炬 | 是的 | 是的 | 是的 | 是的 | 是的 | - |
伯特 | 海衛一後端 | 是的 | - | - | 是的 | 是的 | - |
伯特 | C++ | 是的 | 是的 | - | - | - | 是的 |
XL網 | C++ | 是的 | - | - | - | - | - |
編碼器 | TensorFlow | 是的 | 是的 | - | - | - | - |
編碼器 | 火炬 | 是的 | 是的 | 是的 | - | - | - |
解碼器 | TensorFlow | 是的 | - | - | - | - | - |
解碼器 | 火炬 | 是的 | - | - | - | - | - |
解碼 | TensorFlow | 是的 | - | - | - | - | - |
解碼 | 火炬 | 是的 | - | - | - | - | - |
GPT | TensorFlow | 是的 | - | - | - | - | - |
通用技術/選擇 | 火炬 | 是的 | - | - | 是的 | 是的 | 是的 |
通用技術/選擇 | 海衛一後端 | 是的 | - | - | 是的 | 是的 | - |
GPT-教育部 | 火炬 | 是的 | - | - | 是的 | 是的 | - |
盛開 | 火炬 | 是的 | - | - | 是的 | 是的 | - |
盛開 | 海衛一後端 | 是的 | - | - | 是的 | 是的 | - |
GPT-J | 海衛一後端 | 是的 | - | - | 是的 | 是的 | - |
長形器 | 火炬 | 是的 | - | - | - | - | - |
T5/UL2 | 火炬 | 是的 | - | - | 是的 | 是的 | - |
T5 | TensorFlow 2 | 是的 | - | - | - | - | - |
T5/UL2 | 海衛一後端 | 是的 | - | - | 是的 | 是的 | - |
T5 | 張量RT | 是的 | - | - | 是的 | 是的 | - |
T5-教育部 | 火炬 | 是的 | - | - | 是的 | 是的 | - |
斯溫變壓器 | 火炬 | 是的 | 是的 | - | - | - | - |
斯溫變壓器 | 張量RT | 是的 | 是的 | - | - | - | - |
維特 | 火炬 | 是的 | 是的 | - | - | - | - |
維特 | 張量RT | 是的 | 是的 | - | - | - | - |
GPT-NeoX | 火炬 | 是的 | - | - | 是的 | 是的 | - |
GPT-NeoX | 海衛一後端 | 是的 | - | - | 是的 | 是的 | - |
巴特/巴特 | 火炬 | 是的 | - | - | 是的 | 是的 | - |
微型網 | C++ | 是的 | - | - | - | - | - |
德貝爾塔 | TensorFlow 2 | 是的 | - | - | 正在進行中 | 正在進行中 | - |
德貝爾塔 | 火炬 | 是的 | - | - | 正在進行中 | 正在進行中 | - |
具體模型的更多詳細資訊放在docs/
的xxx_guide.md
中,其中xxx
表示模型名稱。一些常見問題和相應的答案放在docs/QAList.md
中。請注意,Encoder 和 BERT 的模型類似,我們將說明放在bert_guide.md
中。
以下程式碼列出了FasterTransformer的目錄結構:
/src/fastertransformer: source code of FasterTransformer
|--/cutlass_extensions: Implementation of cutlass gemm/kernels.
|--/kernels: CUDA kernels for different models/layers and operations, like addBiasResiual.
|--/layers: Implementation of layer modules, like attention layer, ffn layer.
|--/models: Implementation of different models, like BERT, GPT.
|--/tensorrt_plugin: encapluate FasterTransformer into TensorRT plugin.
|--/tf_op: custom Tensorflow OP implementation
|--/th_op: custom PyTorch OP implementation
|--/triton_backend: custom triton backend implementation
|--/utils: Contains common cuda utils, like cublasMMWrapper, memory_utils
/examples: C++, tensorflow and pytorch interface examples
|--/cpp: C++ interface examples
|--/pytorch: PyTorch OP examples
|--/tensorflow: TensorFlow OP examples
|--/tensorrt: TensorRT examples
/docs: Documents to explain the details of implementation of different models, and show the benchmark
/benchmark: Contains the scripts to run the benchmarks of different models
/tests: Unit tests
/templates: Documents to explain how to add a new model/example into FasterTransformer repo
請注意,許多資料夾包含許多子資料夾來分割不同的模型。量化工具已轉移到examples
,例如examples/tensorflow/bert/bert-quantization/
和examples/pytorch/bert/bert-quantization-sparsity/
。
FasterTransformer提供了一些方便的環境變數用於調試和測試。
FT_LOG_LEVEL
:此環境控制偵錯訊息的日誌等級。更多詳細資訊位於src/fastertransformer/utils/logger.h
。請注意,當等級低於DEBUG
時,程式會列印大量訊息,並且程式會變得非常慢。FT_NVTX
:如果設定為ON
(如FT_NVTX=ON ./bin/gpt_example
,程式將插入 nvtx 的標記以協助分析程式。FT_DEBUG_LEVEL
:如果設定為DEBUG
,程式將在每個核心之後執行cudaDeviceSynchronize()
。否則,內核預設異步執行。有助於調試時定位錯誤點。但這個標誌對程式的效能影響很大。因此,它應該僅用於調試。 硬體設定:
為了執行以下基準測試,我們需要安裝unix計算工具「bc」:
apt-get install bc
透過運行benchmarks/bert/tf_benchmark.sh
獲得 TensorFlow 的 FP16 結果。
透過執行benchmarks/bert/tf_int8_benchmark.sh
獲得 TensorFlow 的 INT8 結果。
PyTorch 的 FP16 結果是透過運行benchmarks/bert/pyt_benchmark.sh
獲得的。
PyTorch的INT8結果是透過執行benchmarks/bert/pyt_int8_benchmark.sh
獲得的。
更多基準測試放在docs/bert_guide.md
。
下圖比較了FasterTransformer和FasterTransformer在T4上FP16下不同特徵的表現。
對於大批次和序列長度,EFF-FT 和 FT-INT8-v2 都帶來 2 倍的加速。對於大型案例,同時使用Effective FasterTransformer和int8v2可以比FasterTransformer FP16帶來約3.5倍的加速。
下圖比較了FasterTransformer和TensorFlow XLA在T4上FP16下不同特徵的表現。
對於小批量和序列長度,使用 FasterTransformer 可以帶來約 3 倍的加速。
對於大批量和序列長度,使用有效的 FasterTransformer 和 INT8-v2 量化可以帶來約 5 倍的加速。
下圖比較了FasterTransformer和PyTorch TorchScript在T4上FP16下不同特徵的表現。
對於小批次和序列長度,使用 FasterTransformer CustomExt 可以帶來約 4x ~ 6x 的加速。
對於大批量和序列長度,使用有效的 FasterTransformer 和 INT8-v2 量化可以帶來約 5 倍的加速。
透過運行benchmarks/decoding/tf_decoding_beamsearch_benchmark.sh
和benchmarks/decoding/tf_decoding_sampling_benchmark.sh
得到 TensorFlow 的結果
PyTorch的結果是透過執行benchmarks/decoding/pyt_decoding_beamsearch_benchmark.sh
獲得的。
在解碼實驗中,我們更新了以下參數:
更多基準測試放在docs/decoder_guide.md
。
下圖顯示了 FT-Decoder 操作和 FT-Decoding 操作與 FP16 下 T4 下的 TensorFlow 相比的加速情況。這裡,我們使用翻譯測試集的吞吐量來防止每種方法的總令牌可能不同。與 TensorFlow 相比,FT-Decoder 提供 1.5x ~ 3x 的加速比;而 FT-Decoding 提供 4x ~ 18x 的加速。
下圖顯示了 FT-Decoder 操作和 FT-Decoding 操作與使用 T4 的 FP16 下的 PyTorch 相比的加速情況。這裡,我們使用翻譯測試集的吞吐量來防止每種方法的總令牌可能不同。與 PyTorch 相比,FT-Decoder 提供 1.2x ~ 3x 的加速;而 FT-Decoding 則提供 3.8x ~ 13x 的加速。
下圖比較了A100上FP16下Megatron和FasterTransformer的性能。
在解碼實驗中,我們更新了以下參數:
2023年5月
2023 年 1 月
2022 年 12 月
2022 年 11 月
2022 年 10 月
2022 年 9 月
2022 年 8 月
2022 年 7 月
2022 年 6 月
2022年5月
2022 年 4 月
2022 年 3 月
stop_ids
和ban_bad_ids
。start_id
和end_id
。2022 年 2 月
2021 年 12 月
2021 年 11 月
2021 年 8 月
layer_para
重命名為pipeline_para
。size_per_head
96、160、192、224、256。2021 年 6 月
2021 年 4 月
2020年12月
2020年11月
2020 年 9 月
2020年8月
2020年6月
2020年5月
translate_sample.py
中載入模型的方法。2020年4月
decoding_opennmt.h
重新命名為decoding_beamsearch.h
decoding_sampling.h
中bert_transformer_op.h
、 bert_transformer_op.cu.cc
合併至bert_transformer_op.cc
decoder.h
、 decoder.cu.cc
合併到decoder.cc
decoding_beamsearch.h
、 decoding_beamsearch.cu.cc
合併到decoding_beamsearch.cc
bleu_score.py
加入utils
。請注意,BLEU 分數需要 python3。2020年3月
translate_sample.py
來示範如何透過恢復OpenNMT-tf的預訓練模型來翻譯句子。2020年2月
2019年7月
import torch
。如果這樣做了,那是由於 C++ ABI 不相容。你可能需要檢查編譯和執行過程中使用的PyTorch是否相同,或者你需要檢查你的PyTorch是如何編譯的,或者你的GCC版本等。