MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / bertINT8Example

Function bertINT8Example

examples/cpp/bert_int8/bert_int8_example.cc:73–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71
72template<typename T>
73int bertINT8Example(size_t batch_size,
74 size_t num_layers,
75 size_t seq_len,
76 size_t head_num,
77 size_t size_per_head,
78 int int8_mode,
79 bool is_remove_padding,
80 bool allow_gemm_test)
81{
82 printf("[INFO] Device: %s \n", getDeviceName().c_str());
83
84 const size_t hidden_units = head_num * size_per_head;
85 const size_t inter_size = 4 * hidden_units;
86
87 cudaStream_t stream;
88 cublasLtHandle_t cublaslt_handle;
89 cudaStreamCreate(&stream);
90 cublasLtCreate(&cublaslt_handle);
91#ifdef SPARSITY_ENABLED
92 cusparseLtHandle_t cusparselt_handle;
93 CHECK_CUSPARSE(cusparseLtInit(&cusparselt_handle));
94#endif
95 cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("igemm_config.in");
96
97 int sm = getSMVersion();
98
99 Allocator<AllocatorType::CUDA> allocator(getDevice());
100
101 std::mutex* cublas_wrapper_mutex = new std::mutex();
102
103 bool use_ORDER_COL32_2R_4R4 = false;
104#if (CUDART_VERSION >= 11000)
105 if (sm >= 80) {
106 use_ORDER_COL32_2R_4R4 = true;
107 }
108#endif
109
110#ifdef SPARSITY_ENABLED
111 cublasINT8MMWrapper cublas_wrapper = cublasINT8MMWrapper(
112 cublaslt_handle, cusparselt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, use_ORDER_COL32_2R_4R4);
113#else
114 cublasINT8MMWrapper cublas_wrapper =
115 cublasINT8MMWrapper(cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, use_ORDER_COL32_2R_4R4);
116#endif
117
118 std::vector<BertLayerINT8Weight<T>> bert_layer_weights(num_layers,
119 BertLayerINT8Weight<T>(hidden_units, inter_size));
120
121 AttentionType attention_type = getAttentionTypeINT8<T>(size_per_head, sm, is_remove_padding, seq_len, int8_mode);
122
123 BertINT8<T> bert_int8 = BertINT8<T>(batch_size,
124 seq_len,
125 head_num,
126 size_per_head,
127 inter_size,
128 num_layers,
129 sm,
130 1.0f,

Callers

nothing calls this directly

Calls 9

getDeviceNameFunction · 0.85
getSMVersionFunction · 0.85
getDeviceFunction · 0.85
cublasINT8MMWrapperClass · 0.85
resetScopeFunction · 0.85
addScopeFunction · 0.85
forwardMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected