docstr: Initialize the sampler for best-of-n generation
  
  Args:
      model (`PreTrainedModelWrapper`):
          The pretrained model to use for generation
      tokenizer (`PreTrainedTokenizer` or `PreTrainedTokenizerFast`):
          Tokenizer associated with the pretrained model
      queries_to_scores (`Callable[[List[str]], List[float]]`):
          Callable that takes a list of generated texts and returns the associated reward scores
      length_sampler (`Any`):
          Sampler used to sample the length of the generated text
      sample_size (`int`):
          Number of samples to generate for each query
      seed (`int`, *optional*):
          Random seed used to control generation
      n_candidates (`int`):
          Number of candidates to return for each query
      generation_config (`GenerationConfig`, *optional*):
          Generation config passed to the underlying model's `generate` method.
          See `GenerationConfig` (https://huggingface.co/docs/transformers/v4.29.1/en/main_classes/text_generation#transformers.GenerationConfig) for more details
code: def __init__(
      self,
      model: PreTrainedModelWrapper,
      tokenizer: Union[PreTrainedTokenizer, PreTrainedTokenizerFast],
      queries_to_scores: Callable[[List[str]], List[float]],
      length_sampler: Any,
      sample_size: int = 4,
      seed: Optional[int] = None,
      n_candidates: int = 1,
      generation_config: Optional[GenerationConfig] = None,
  ) -> None:
      r"""
      Initialize the sampler for best-of-n generation
  
      Args:
          model (`PreTrainedModelWrapper`):
              The pretrained model to use for generation
          tokenizer (`PreTrainedTokenizer` or `PreTrainedTokenizerFast`):
              Tokenizer associated with the pretrained model
          queries_to_scores (`Callable[[List[str]], List[float]]`):
              Callable that takes a list of generated texts and returns the associated reward scores
          length_sampler (`Any`):
              Sampler used to sample the length of the generated text
          sample_size (`int`):
              Number of samples to generate for each query
          seed (`int`, *optional*):
              Random seed used to control generation
          n_candidates (`int`):
              Number of candidates to return for each query
          generation_config (`GenerationConfig`, *optional*):
              Generation config passed to the underlying model's `generate` method.
              See `GenerationConfig` (https://huggingface.co/docs/transformers/v4.29.1/en/main_classes/text_generation#transformers.GenerationConfig) for more details
      """
      if seed is not None:
          set_seed(seed)
  
      if not isinstance(
          tokenizer, (PreTrainedTokenizer, PreTrainedTokenizerFast)
      ):
          raise ValueError(
              f"tokenizer must be a PreTrainedTokenizer or PreTrainedTokenizerFast, got {type(tokenizer)}"
          )
      if not isinstance(model, (SUPPORTED_ARCHITECTURES)):
          raise ValueError(
              f"model must be a PreTrainedModelWrapper, got {type(model)} - supported architectures are: {SUPPORTED_ARCHITECTURES}"
          )
  
      self.model = model
      self.tokenizer = tokenizer
  
      self.queries_to_scores = queries_to_scores
      self.length_sampler = length_sampler
      self.gen_config = generation_config
      self.sample_size = sample_size
      self.n_candidates = n_candidates
  
file_path: trl/trl/extras/best_of_n_sampler.py
imports: from typing import Any, Callable, List, Optional, Union
  import torch
  from transformers import GenerationConfig, PreTrainedTokenizer, PreTrainedTokenizerFast
  from ..core import set_seed
  from ..models import SUPPORTED_ARCHITECTURES, PreTrainedModelWrapper
label_desc: Use image node_id 1 to create a new BestOfNSampler object from inherited base classes: object with example: obj = BestOfNSampler(model, tokenizer, queries_to_scores, length_sampler, sample_size, seed, n_candidates, generation_config)