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

Method forward

src/fastertransformer/th_op/decoder/DecoderOp.h:111–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109 }
110
111 void forward(size_t batch_size,
112 size_t step,
113 th::Tensor& from_tensor,
114 th::Tensor& memory_tensor,
115 th::Tensor& memory_sequence_length,
116 th::Tensor& sequence_length,
117 th::Tensor& output_tensor,
118 th::Tensor& self_cache_keys_tensor,
119 th::Tensor& self_cache_values_tensor,
120 th::Tensor& memory_cache_keys_tensor,
121 th::Tensor& memory_cache_values_tensor) override
122 {
123 auto stream = at::cuda::getCurrentCUDAStream().stream();
124 cublasHandle_t _cublasHandle = at::cuda::getCurrentCUDABlasHandle();
125 cublasSetStream(_cublasHandle, stream);
126 ft::Allocator<ft::AllocatorType::TH>* allocator = new ft::Allocator<ft::AllocatorType::TH>();
127 ft::cublasMMWrapper* cublas_wrapper = new ft::cublasMMWrapper(
128 _cublasHandle, _cublasltHandle, stream, cublas_algo_map_, cublas_wrapper_mutex_, allocator);
129
130 if (std::is_same<T, half>::value) {
131 cublas_wrapper->setFP16GemmConfig();
132 }
133#ifdef ENABLE_BF16
134 else if (std::is_same<T, __nv_bfloat16>::value) {
135 cublas_wrapper->setBF16GemmConfig();
136 }
137#endif
138 else if (std::is_same<T, float>::value) {
139 cublas_wrapper->setFP32GemmConfig();
140 }
141
142 ft::Decoder<T>* decoder = new ft::Decoder<T>(
143 batch_size, _head_num, _head_size, _inter_size, _layer_num, stream, cublas_wrapper, allocator, true);
144
145 int tmp_step = step + 1;
146 std::vector<ft::Tensor> input_tensors = std::vector<ft::Tensor>{
147 convert_tensor<T>(from_tensor),
148 convert_tensor<T>(memory_tensor),
149 convert_tensor<int>(memory_sequence_length),
150 ft::Tensor{ft::MEMORY_GPU, ft::TYPE_BOOL, {batch_size}, nullptr},
151 ft::Tensor{ft::MEMORY_CPU, ft::TYPE_INT32, {1}, &tmp_step},
152 convert_tensor<int>(sequence_length),
153 ft::Tensor{ft::MEMORY_GPU,
154 ft::TYPE_INT32,
155 {batch_size, 1, (size_t)tmp_step},
156 nullptr}}; // Since we do gather in the Framework, we don't need id of indirection buffer
157
158 std::vector<ft::Tensor> output_tensors = std::vector<ft::Tensor>{convert_tensor<T>(output_tensor),
159 convert_tensor<T>(self_cache_keys_tensor),
160 convert_tensor<T>(self_cache_values_tensor),
161 convert_tensor<T>(memory_cache_keys_tensor),
162 convert_tensor<T>(memory_cache_values_tensor)};
163
164 try {
165 decoder->forward(&output_tensors, &input_tensors, &decoder_layer_weights);
166 }
167 catch (std::runtime_error& error) {
168 std::cout << error.what();

Callers

nothing calls this directly

Calls 2

setFP16GemmConfigMethod · 0.80
whatMethod · 0.45

Tested by

no test coverage detected