| 138 | } |
| 139 | |
| 140 | void forward(size_t batch_size, |
| 141 | size_t seq_len, |
| 142 | th::Tensor& input, |
| 143 | th::Tensor& sequence_lengths, |
| 144 | th::Tensor& output, |
| 145 | bool removing_padding) override |
| 146 | { |
| 147 | auto stream = at::cuda::getCurrentCUDAStream().stream(); |
| 148 | cublasHandle_t _cublasHandle = at::cuda::getCurrentCUDABlasHandle(); |
| 149 | cublasSetStream(_cublasHandle, stream); |
| 150 | ft::Allocator<ft::AllocatorType::TH>* allocator = new ft::Allocator<ft::AllocatorType::TH>(); |
| 151 | ft::cublasMMWrapper* cublas_wrapper = |
| 152 | #ifdef SPARSITY_ENABLED |
| 153 | new ft::cublasMMWrapper(_cublasHandle, |
| 154 | _cublasltHandle, |
| 155 | _cusparseLtHandle, |
| 156 | stream, |
| 157 | cublas_algo_map_, |
| 158 | cublas_wrapper_mutex_, |
| 159 | allocator); |
| 160 | #else |
| 161 | new ft::cublasMMWrapper( |
| 162 | _cublasHandle, _cublasltHandle, stream, cublas_algo_map_, cublas_wrapper_mutex_, allocator); |
| 163 | #endif |
| 164 | |
| 165 | if (std::is_same<T, half>::value) { |
| 166 | cublas_wrapper->setFP16GemmConfig(); |
| 167 | } |
| 168 | #ifdef ENABLE_BF16 |
| 169 | else if (std::is_same<T, __nv_bfloat16>::value) { |
| 170 | cublas_wrapper->setBF16GemmConfig(); |
| 171 | } |
| 172 | #endif |
| 173 | else if (std::is_same<T, float>::value) { |
| 174 | cublas_wrapper->setFP32GemmConfig(); |
| 175 | } |
| 176 | |
| 177 | ft::AttentionType attention_type = ft::getAttentionType<T>(_head_size, sm_, removing_padding, seq_len); |
| 178 | |
| 179 | ft::Bert<T>* encoder = new ft::Bert<T>(batch_size, |
| 180 | seq_len, |
| 181 | _head_num, |
| 182 | _head_size, |
| 183 | _inter_size, |
| 184 | _layer_num, |
| 185 | sm_, |
| 186 | _q_scaling, |
| 187 | stream, |
| 188 | cublas_wrapper, |
| 189 | allocator, |
| 190 | false, |
| 191 | attention_type, |
| 192 | _sparse, |
| 193 | ft::ActivationType::Relu, |
| 194 | ft::LayerNormType::pre_layernorm); |
| 195 | |
| 196 | ft::DataType data_type = ft::getTensorType<T>(); |
| 197 | std::vector<ft::Tensor> input_tensors = std::vector<ft::Tensor>{ |
nothing calls this directly
no test coverage detected