| 155 | |
| 156 | template<typename T1, typename T2> |
| 157 | int bertExample(size_t batch_size, |
| 158 | size_t num_layers, |
| 159 | size_t seq_len, |
| 160 | size_t head_num, |
| 161 | size_t size_per_head, |
| 162 | bool is_remove_padding, |
| 163 | std::string model_path, |
| 164 | const float& mean_rel_diff_threshold) |
| 165 | { |
| 166 | const int fp8_mode = 2; |
| 167 | FT_LOG_INFO("fp8_mode: %d", fp8_mode); |
| 168 | FT_LOG_INFO("Device: %s \n", getDeviceName().c_str()); |
| 169 | |
| 170 | const size_t hidden_units = head_num * size_per_head; |
| 171 | const size_t inter_size = 4 * hidden_units; |
| 172 | const size_t vocab_size = 30522; // Fixed by bert model config |
| 173 | const size_t max_position_embeddings = 512; // Fixed by bert model config |
| 174 | const size_t token_type_vocab_size = 2; // Fixed by bert model config |
| 175 | |
| 176 | cudaStream_t stream; |
| 177 | cublasHandle_t cublas_handle; |
| 178 | cublasLtHandle_t cublaslt_handle; |
| 179 | cudaStreamCreate(&stream); |
| 180 | cublasCreate(&cublas_handle); |
| 181 | cublasLtCreate(&cublaslt_handle); |
| 182 | #ifdef SPARSITY_ENABLED |
| 183 | cusparseLtHandle_t cusparselt_handle; |
| 184 | CHECK_CUSPARSE(cusparseLtInit(&cusparselt_handle)); |
| 185 | #endif |
| 186 | cublasSetStream(cublas_handle, stream); |
| 187 | cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("gemm_config.in", ""); |
| 188 | |
| 189 | Allocator<AllocatorType::CUDA> allocator(getDevice()); |
| 190 | |
| 191 | std::mutex* cublas_wrapper_mutex = new std::mutex(); |
| 192 | #ifdef SPARSITY_ENABLED |
| 193 | // cublasFP8MMWrapper cublas_wrapper = cublasMMWrapper( |
| 194 | // cublas_handle, cublaslt_handle, cusparselt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, |
| 195 | // &allocator); |
| 196 | #else |
| 197 | cublasFP8MMWrapper cublas_wrapper = |
| 198 | cublasFP8MMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator); |
| 199 | #endif |
| 200 | |
| 201 | const size_t input_size = batch_size * seq_len * head_num * size_per_head; |
| 202 | std::string fp32_ckpt_path = model_path + "/ft_fp32/1-gpu/"; |
| 203 | std::string fp8_ckpt_path = model_path + "/ft_fp8/1-gpu/"; |
| 204 | std::string input_path = model_path + "/bert_input_unit_test/bs_"; // use random ids |
| 205 | |
| 206 | // Preare FP16 bert model and weight |
| 207 | BertWeight<half> f_bert_weights(hidden_units, inter_size, num_layers); |
| 208 | f_bert_weights.loadModel(fp32_ckpt_path); |
| 209 | |
| 210 | AttentionType fp8_attention_type = getAttentionType<T1>(size_per_head, getSMVersion(), is_remove_padding, seq_len); |
| 211 | AttentionType f_attention_type = getAttentionType<half>(size_per_head, getSMVersion(), is_remove_padding, seq_len); |
| 212 | cublasMMWrapper f_cublas_wrapper = |
| 213 | cublasMMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator); |
| 214 | f_cublas_wrapper.setFP16GemmConfig(); |
nothing calls this directly
no test coverage detected