-
Notifications
You must be signed in to change notification settings - Fork 744
[Cherry-Pick] [Optimization] TopP=1.0 using _random_sample (#7892) and Triton SamplerBackend (#7639) #7910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release/2.6
Are you sure you want to change the base?
[Cherry-Pick] [Optimization] TopP=1.0 using _random_sample (#7892) and Triton SamplerBackend (#7639) #7910
Changes from all commits
27b9c26
e52ec74
be0f9cf
6d6f6cb
204c426
755453a
b73b574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,6 +42,7 @@ class SamplingMetadata: | |
| step_idx: paddle.Tensor | ||
|
|
||
| top_p: paddle.Tensor | ||
| top_p_list: Optional[list] = None | ||
| # only GPU used | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 建议 建议修改为: top_p_list: Optional[List[float]] = None(同时在文件顶部 import |
||
| bad_words_token_len: Optional[paddle.Tensor] = None | ||
| top_k: Optional[paddle.Tensor] = None | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,20 @@ def _reset_cuda_generator_for_determinism(): | |
| paddle.framework.core.default_cuda_generator(0).manual_seed(_DETERMINISTIC_RNG_SEED) | ||
|
|
||
|
|
||
| def dispatch_top_k_renorm_probs(probs, top_k): | ||
| try: | ||
| if current_platform.is_iluvatar(): | ||
| from fastdeploy.model_executor.ops.iluvatar import top_k_renorm_probs | ||
| else: | ||
| from fastdeploy.model_executor.ops.gpu import top_k_renorm_probs | ||
| probs = top_k_renorm_probs(probs, top_k) | ||
|
|
||
| except ImportError: | ||
| logger.warning("top_k sampling is not supported on current platform, skipping top_k filtering.") | ||
|
|
||
| return probs | ||
|
|
||
|
|
||
| def top_k_top_p_sampling( | ||
| x: paddle.Tensor, | ||
| top_p: paddle.Tensor, | ||
|
|
@@ -70,7 +84,6 @@ def top_k_top_p_sampling( | |
|
|
||
| """ | ||
| top_p_class = envs.FD_SAMPLING_CLASS.lower() | ||
| topp_seed_device = None | ||
|
|
||
| # In deterministic mode, reset CUDA generator offset before sampling. | ||
| # paddle.tensor.top_p_sampling uses the global GPU generator offset even | ||
|
|
@@ -85,29 +98,17 @@ def top_k_top_p_sampling( | |
| _ = None | ||
| else: | ||
| if top_k_list and any(x > 0 for x in top_k_list): | ||
| try: | ||
| if current_platform.is_iluvatar(): | ||
| from fastdeploy.model_executor.ops.iluvatar import ( | ||
| top_k_renorm_probs, | ||
| ) | ||
| else: | ||
| from fastdeploy.model_executor.ops.gpu import top_k_renorm_probs | ||
| x = top_k_renorm_probs(x, top_k) | ||
| except ImportError: | ||
| logger.warning("top_k sampling is not supported on current platform, skipping top_k filtering.") | ||
| x = dispatch_top_k_renorm_probs(x, top_k) | ||
|
|
||
| if top_p_class == "air": | ||
| _, ids = air_top_p_sampling(x, top_p, threshold, topp_seed, seed=seed, k=k, mode=mode) | ||
|
|
||
| elif top_p_class == "base_non_truncated": | ||
| if topp_seed is not None: | ||
| topp_seed_device = paddle.empty(shape=topp_seed.shape, dtype=topp_seed.dtype) | ||
| topp_seed_device.copy_(topp_seed, False) | ||
| _, ids = paddle.tensor.top_p_sampling( | ||
This comment was marked as outdated.
Sorry, something went wrong. |
||
| x, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ 疑问 原代码明确将 若 请确认 |
||
| top_p, | ||
| threshold=threshold, | ||
| topp_seed=topp_seed_device, | ||
| topp_seed=topp_seed, | ||
| seed=seed, | ||
| k=k, | ||
| mode="non-truncated", | ||
|
|
@@ -122,14 +123,11 @@ def top_k_top_p_sampling( | |
|
|
||
| _, ids = native_top_p_sampling(x, top_p) | ||
| else: | ||
| if topp_seed is not None: | ||
| topp_seed_device = paddle.empty(shape=topp_seed.shape, dtype=topp_seed.dtype) | ||
| topp_seed_device.copy_(topp_seed, False) | ||
| _, ids = paddle.tensor.top_p_sampling( | ||
| x, | ||
| top_p, | ||
| threshold=threshold, | ||
| topp_seed=topp_seed_device, | ||
| topp_seed=topp_seed, | ||
| seed=seed, | ||
| k=k, | ||
| mode="truncated", | ||
|
|
||
This comment was marked as outdated.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.