-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9b4fe7
commit 3afb7d9
Showing
8 changed files
with
373 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include <cuda_bf16.h> | ||
#include <cuda_fp16.h> | ||
|
||
#include <cstdint> | ||
|
||
#include "flashinfer/sampling.cuh" | ||
|
||
template <typename T> | ||
cudaError_t FlashInferSampleProb(T* probs, T* uniform_samples, int32_t* output, | ||
int batch_size, int dim) { | ||
return flashinfer::sampling::SamplingFromProb<T, int32_t>( | ||
probs, uniform_samples, output, batch_size, dim); | ||
} | ||
#define INST_FlashInferSampleProb(T) \ | ||
template cudaError_t FlashInferSampleProb<T>(T * probs, T * uniform_samples, \ | ||
int32_t * output, \ | ||
int batch_size, int dim); | ||
INST_FlashInferSampleProb(float); | ||
INST_FlashInferSampleProb(nv_half); | ||
INST_FlashInferSampleProb(nv_bfloat16); | ||
|
||
template <typename T> | ||
cudaError_t FlashInferSampleTopK(T* probs, T* uniform_samples, int32_t* output, | ||
int batch_size, int dim, int32_t k, | ||
int max_rounds) { | ||
bool* success = nullptr; // Skip checking. | ||
auto status = flashinfer::sampling::TopKSamplingFromProb<T, int32_t>( | ||
probs, uniform_samples, output, success, k, batch_size, dim, max_rounds); | ||
return status; | ||
} | ||
#define INST_FlashInferSampleTopK(T) \ | ||
template cudaError_t FlashInferSampleTopK<T>( \ | ||
T * probs, T * uniform_samples, int32_t * output, int batch_size, \ | ||
int dim, int32_t k, int max_rounds); | ||
INST_FlashInferSampleTopK(float); | ||
INST_FlashInferSampleTopK(nv_half); | ||
INST_FlashInferSampleTopK(nv_bfloat16); | ||
|
||
template <typename T> | ||
cudaError_t FlashInferSampleTopP(T* probs, T* uniform_samples, int32_t* output, | ||
int batch_size, int dim, float p, | ||
int max_rounds) { | ||
bool* success = nullptr; // Skip checking. | ||
auto status = flashinfer::sampling::TopPSamplingFromProb<T, int32_t>( | ||
probs, uniform_samples, output, success, static_cast<T>(p), batch_size, | ||
dim, max_rounds); | ||
return status; | ||
} | ||
#define INST_FlashInferSampleTopP(T) \ | ||
template cudaError_t FlashInferSampleTopP<T>( \ | ||
T * probs, T * uniform_samples, int32_t * output, int batch_size, \ | ||
int dim, float p, int max_rounds); | ||
INST_FlashInferSampleTopP(float); | ||
INST_FlashInferSampleTopP(nv_half); | ||
INST_FlashInferSampleTopP(nv_bfloat16); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.