From 19d2f97932875e4d5321688a6b570272a7a8c4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20Gallou=C3=A9dec?= <45557362+qgallouedec@users.noreply.github.com> Date: Wed, 15 Oct 2025 18:06:34 -0600 Subject: [PATCH] Deprecate `BestOfNSampler` (#4291) Co-authored-by: behroozazarkhalili Co-authored-by: Behrooz Azarkhalili <80390531+behroozazarkhalili@users.noreply.github.com> --- docs/source/best_of_n.md | 3 +++ trl/extras/best_of_n_sampler.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/docs/source/best_of_n.md b/docs/source/best_of_n.md index 2935c472d..9280a9e20 100644 --- a/docs/source/best_of_n.md +++ b/docs/source/best_of_n.md @@ -1,5 +1,8 @@ # Best of N sampling: Alternative ways to get better model output without RL based fine-tuning +> [!WARNING] +> Best-of-N sampling is deprecated and will be removed in TRL 0.25.0. + Within the extras module is the `best-of-n` sampler class that serves as an alternative method of generating better model output. As to how it fares against the RL based fine-tuning, please look in the `examples` directory for a comparison example diff --git a/trl/extras/best_of_n_sampler.py b/trl/extras/best_of_n_sampler.py index 165cd69b6..f75050424 100644 --- a/trl/extras/best_of_n_sampler.py +++ b/trl/extras/best_of_n_sampler.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import warnings from typing import Any, Callable, Optional, Union import torch @@ -42,8 +43,16 @@ class BestOfNSampler: generation_config ([`~transformers.GenerationConfig`], *optional*): Generation config passed to the underlying model's `generate` method. See [`~transformers.GenerationConfig`] for more details. + + + + `BestOfNSampler` is deprecated and will be removed in version 0.25. + + """ + warnings.warn("`BestOfNSampler` is deprecated and will be removed in TRL 0.25.", FutureWarning, stacklevel=2) + def __init__( self, model: PreTrainedModelWrapper,