FasterTransformer icon indicating copy to clipboard operation
FasterTransformer copied to clipboard

Question about GPT topk sampling

Open smallv0221 opened this issue 5 years ago • 7 comments

It seem GPT topk sampling decoding strategy only support k = 1, 2, 4. I dont understand the design here. And is there anyway to use other value for GPT topk sampling decoding like k=50?

smallv0221 avatar Jul 13 '21 12:07 smallv0221

I think FT supports k = 50. Have you tried it?

byshiue avatar Jul 13 '21 13:07 byshiue

I tried k=3 and got an error. I tracked the error here. image

smallv0221 avatar Jul 13 '21 13:07 smallv0221

I used FT 3.1 by the way.

smallv0221 avatar Jul 13 '21 13:07 smallv0221

Please refer the latest code here https://github.com/NVIDIA/FasterTransformer/blob/main/fastertransformer/cuda/topk_kernels.cu#L762, which support at most 64. The constraint is caused by the template. You can also add the k value you need directly.

byshiue avatar Jul 13 '21 14:07 byshiue

Thanks! Directly adding CASE_K(50); solved my problem. But I'm still a little confused about the design here because I see you have another topk kernel called topK_kernelLauncher which accepts general K values. image It uses TopK_2<T> instead of TopK<T, MAX_K> so it has no constraint. So why set constraint for topK_sampling_kernel_kernelLauncher and not for topK_kernelLauncher.

smallv0221 avatar Jul 19 '21 08:07 smallv0221

General case would be slower.

byshiue avatar Jul 19 '21 09:07 byshiue

Close this bug because it is inactivated. Feel free to re-open this issue if you still have any problem.

byshiue avatar Apr 19 '22 00:04 byshiue