You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This only requires a single parameter - consider all tokens whose probability is greater than than the probability of the first one scaled down by some number.
If Nvidia doesn't want to do it (why? much superior inference results...), maybe we can add it ourselves? It looks like sampling layers are part of the code that is open source.
@aikitoria I found that it was far easier and performant to implement in decodingCommon.cu since the same math used for logprobs can be used for calculating the relative threshold used in min-p sampling
See my PR in #1536
I'll need to review that things are done in the correct order: I'm still grappling with the codebase but I assumed it should be doing min-p before sampling
Is that not much slower than it would be if properly implemented it in the CUDA sampling layers?
Just saw the PR above also. That's an interesting way. Highly doubt nvidia would accept it given it seems more like a hack, but it gives us something to experiment with...
@aikitoria Yeah, since it's computed per request and not in a batch (see also #1681). But if you are already using other logit processors, it might not have a big of an effect.
FWIW the new executor API does not allow parametrizing logit processors per-request anymore -- they are fixed at startup -- so one can't implement MinP that way. You have to go lower-level to GptManager in C++, so bumping this thread @ncomly-nvidia@AdamzNV
I'm tired of waiting so I'm just doing it myself the way I thought it should be done... but it is EXTREMELY FRUSTRATING that this library has closed source parts for no reason. For example, I can't modify executor to actually pass the min_p parameter through from the frontend, or allow top_p and min_p to exist at the same time by grouping them in separate batches for sampling. Why???
FWIW I don't think the PR linked above is the correct way to do this. When min_p is in use, top_k and top_p layers should not run, and temperature needs to be applied after min_p filter. We can also fuse min_p filter, late temperature and sampling in a single kernel for best performance if logprobs is not required (I don't use it).
Activity
aikitoria commentedon Feb 29, 2024
Forgot to mention: this sampling method should be applied before temperature
0xymoro commentedon Mar 11, 2024
@ncomly-nvidia seconded on adding min p - makes a noticeable impact on production, doesn't seem too bad to implement compared to some others.
aikitoria commentedon Apr 12, 2024
@byshiue any chance of this being added soon? 👀
Most other engines have it now, it's in vLLM and HF transformers is also adding it.
nivekgnaij commentedon Apr 14, 2024
^^ has a huge impact on production
aikitoria commentedon Apr 21, 2024
If Nvidia doesn't want to do it (why? much superior inference results...), maybe we can add it ourselves? It looks like sampling layers are part of the code that is open source.
https://github.com/NVIDIA/TensorRT-LLM/blob/main/cpp/tensorrt_llm/kernels/samplingTopPKernels.h
https://github.com/NVIDIA/TensorRT-LLM/blob/main/cpp/tensorrt_llm/kernels/samplingTopPKernels.cu
https://github.com/NVIDIA/TensorRT-LLM/blob/main/cpp/tensorrt_llm/layers/topPSamplingLayer.h
https://github.com/NVIDIA/TensorRT-LLM/blob/main/cpp/tensorrt_llm/layers/topPSamplingLayer.cu
https://github.com/NVIDIA/TensorRT-LLM/blob/main/cpp/tensorrt_llm/layers/samplingLayer.cpp#L52
pathorn commentedon May 2, 2024
@aikitoria I found that it was far easier and performant to implement in decodingCommon.cu since the same math used for logprobs can be used for calculating the relative threshold used in min-p sampling
See my PR in #1536
I'll need to review that things are done in the correct order: I'm still grappling with the codebase but I assumed it should be doing min-p before sampling
byshiue commentedon May 29, 2024
Also mentioned in this issue #1683.
cyr0930 commentedon May 29, 2024
I hope this feature being added any time soon!
DreamGenX commentedon May 29, 2024
You can implement this as a logit processor as far as I can tell:
aikitoria commentedon May 29, 2024
Is that not much slower than it would be if properly implemented it in the CUDA sampling layers?
Just saw the PR above also. That's an interesting way. Highly doubt nvidia would accept it given it seems more like a hack, but it gives us something to experiment with...
DreamGenX commentedon May 29, 2024
@aikitoria Yeah, since it's computed per request and not in a batch (see also #1681). But if you are already using other logit processors, it might not have a big of an effect.
DreamGenX commentedon Jun 14, 2024
FWIW the new executor API does not allow parametrizing logit processors per-request anymore -- they are fixed at startup -- so one can't implement MinP that way. You have to go lower-level to GptManager in C++, so bumping this thread @ncomly-nvidia @AdamzNV
hello-11 commentedon Nov 15, 2024
cc @AdamzNV @ncomly-nvidia @laikhtewari for vis.
aikitoria commentedon Nov 20, 2024
This would still be great to have by default, so we don't have to maintain a custom build just to change what the sampling layer does :)
aikitoria commentedon Dec 30, 2024
I'm tired of waiting so I'm just doing it myself the way I thought it should be done... but it is EXTREMELY FRUSTRATING that this library has closed source parts for no reason. For example, I can't modify executor to actually pass the min_p parameter through from the frontend, or allow top_p and min_p to exist at the same time by grouping them in separate batches for sampling. Why???
FWIW I don't think the PR linked above is the correct way to do this. When min_p is in use, top_k and top_p layers should not run, and temperature needs to be applied after min_p filter. We can also fuse min_p filter, late temperature and sampling in a single kernel for best performance if logprobs is not required (I don't use it).
aikitoria commentedon Dec 31, 2024
I've created a WIP branch with my experiment here: main...aikitoria:TensorRT-LLM:min-p
poweiw commentedon May 16, 2025
Closing since feature merged in #2755. Feel free to reopen