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

Function decodingExample

examples/cpp/decoding/decoding_example.cc:112–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110
111template<typename T>
112int decodingExample(const size_t batch_size,
113 const size_t beam_width,
114 const size_t head_num,
115 const size_t size_per_head,
116 const size_t inter_size,
117 const size_t vocab_size,
118 const size_t num_layers,
119 const size_t max_seq_len,
120 const size_t memory_max_seq_len,
121 const size_t memory_hidden_units,
122 const int top_k,
123 const float top_p)
124{
125 const size_t hidden_units = head_num * size_per_head;
126 const int start_id = 0;
127 const int end_id = 1;
128
129 cudaStream_t stream;
130 cublasHandle_t cublas_handle;
131 cublasLtHandle_t cublaslt_handle;
132 cudaStreamCreate(&stream);
133 cublasCreate(&cublas_handle);
134 cublasLtCreate(&cublaslt_handle);
135 cublasSetStream(cublas_handle, stream);
136 cublasAlgoMap* cublas_algo_map = new cublasAlgoMap("gemm_config.in");
137
138 Allocator<AllocatorType::CUDA> allocator(getDevice());
139
140 std::mutex* cublas_wrapper_mutex = new std::mutex();
141 cublasMMWrapper cublas_wrapper =
142 cublasMMWrapper(cublas_handle, cublaslt_handle, stream, cublas_algo_map, cublas_wrapper_mutex, &allocator);
143 if (std::is_same<T, half>::value) {
144 cublas_wrapper.setFP16GemmConfig();
145 }
146#ifdef ENABLE_BF16
147 else if (std::is_same<T, __nv_bfloat16>::value) {
148 cublas_wrapper.setBF16GemmConfig();
149 }
150#endif
151 else if (std::is_same<T, float>::value) {
152 cublas_wrapper.setFP32GemmConfig();
153 }
154 struct cudaDeviceProp prop;
155 check_cuda_error(cudaGetDeviceProperties(&prop, 0));
156
157 fastertransformer::DecodingWeight<T> decoding_weights(
158 hidden_units, inter_size, vocab_size, num_layers, max_seq_len, memory_hidden_units);
159 Decoding<T> decoding = Decoding<T>(batch_size,
160 max_seq_len,
161 memory_max_seq_len,
162 beam_width,
163 head_num,
164 size_per_head,
165 inter_size,
166 num_layers,
167 vocab_size,
168 start_id,
169 end_id,

Callers

nothing calls this directly

Calls 5

getDeviceFunction · 0.85
cublasMMWrapperClass · 0.85
print_mem_usageFunction · 0.85
setFP16GemmConfigMethod · 0.80
forwardMethod · 0.45

Tested by

no test coverage detected