class_docstr: High-level Python wrapper for a gptneox.cpp model.
class_docstr_tok: ["High-level","Python","wrapper","for","a","gptneox.cpp","model","."]
code: def _sample(
      self,
      last_n_tokens_data,  # type: gptneox_cpp.Array[gptneox_cpp.gptneox_token]
      last_n_tokens_size: gptneox_cpp.c_int,
      top_k: gptneox_cpp.c_int,
      top_p: gptneox_cpp.c_float,
      temp: gptneox_cpp.c_float,
      tfs_z: gptneox_cpp.c_float,
      repeat_penalty: gptneox_cpp.c_float,
      frequency_penalty: gptneox_cpp.c_float,
      presence_penalty: gptneox_cpp.c_float,
      mirostat_mode: gptneox_cpp.c_int,
      mirostat_tau: gptneox_cpp.c_float,
      mirostat_eta: gptneox_cpp.c_float,
  ):
      invalidInputError(
          self.ctx is not None,
          "The attribute `ctx` of `Gptneox` object is None.",
      )
      invalidInputError(
          len(self.eval_logits) > 0,
          "The attribute `eval_logits` of `Gptneox` object is None.",
      )
      n_vocab = int(gptneox_cpp.gptneox_n_vocab(self.ctx))
      logits = self.eval_logits[-1]
      # accelerate below code by moving to cpp
      # data = (gptneox_cpp.gptneox_token_data * n_vocab)(
      #     *[
      #         gptneox_cpp.gptneox_token_data(
      #             id=gptneox_cpp.gptneox_token(i),
      #             logit=logits[i],
      #             p=gptneox_cpp.c_float(0.0),
      #         )
      #         for i in range(n_vocab)
      #     ]
      # )
      # size = gptneox_cpp.c_size_t(n_vocab)
      # sorted = False
      # candidates = gptneox_cpp.gptneox_token_data_array(
      #     data=data,
      #     size=size,
      #     sorted=sorted,
      # )
      logits = (ctypes.c_float * n_vocab)(*logits)
      candidates = gptneox_cpp.gptneox_get_candidates(
          ctx=self.ctx, n_vocab=n_vocab, logits=logits
      )
      gptneox_cpp.gptneox_sample_repetition_penalty(
          ctx=self.ctx,
          last_tokens_data=last_n_tokens_data,
          last_tokens_size=last_n_tokens_size,
          candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
          penalty=repeat_penalty,
      )
      gptneox_cpp.gptneox_sample_frequency_and_presence_penalties(
          ctx=self.ctx,
          candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
          last_tokens_data=last_n_tokens_data,
          last_tokens_size=last_n_tokens_size,
          alpha_frequency=frequency_penalty,
          alpha_presence=presence_penalty,
      )
      if temp.value == 0.0:
          return gptneox_cpp.gptneox_sample_token_greedy(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
          )
      elif mirostat_mode.value == 1:
          mirostat_mu = gptneox_cpp.c_float(2.0 * mirostat_tau.value)
          mirostat_m = gptneox_cpp.c_int(100)
          gptneox_cpp.gptneox_sample_temperature(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              temp=temp,
          )
          return gptneox_cpp.gptneox_sample_token_mirostat(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              tau=mirostat_tau,
              eta=mirostat_eta,
              mu=gptneox_cpp.ctypes.byref(mirostat_mu),  # type: ignore
              m=mirostat_m,
          )
      elif mirostat_mode.value == 2:
          mirostat_mu = gptneox_cpp.c_float(2.0 * mirostat_tau.value)
          gptneox_cpp.gptneox_sample_temperature(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.pointer(candidates),
              temp=temp,
          )
          return gptneox_cpp.gptneox_sample_token_mirostat_v2(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              tau=mirostat_tau,
              eta=mirostat_eta,
              mu=gptneox_cpp.ctypes.byref(mirostat_mu),  # type: ignore
          )
      else:
          gptneox_cpp.gptneox_sample_top_k(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              k=top_k,
              min_keep=gptneox_cpp.c_size_t(1),
          )
          gptneox_cpp.gptneox_sample_tail_free(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              z=tfs_z,
              min_keep=gptneox_cpp.c_size_t(1),
          )
          gptneox_cpp.gptneox_sample_typical(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              p=gptneox_cpp.c_float(1.0),
              min_keep=gptneox_cpp.c_size_t(1),
          )
          gptneox_cpp.gptneox_sample_top_p(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              p=top_p,
              min_keep=gptneox_cpp.c_size_t(1),
          )
          gptneox_cpp.gptneox_sample_temperature(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
              temp=temp,
          )
          return gptneox_cpp.gptneox_sample_token(
              ctx=self.ctx,
              candidates=gptneox_cpp.ctypes.byref(candidates),  # type: ignore
          )
  
imports: import os
  import sys
  import uuid
  import time
  import math
  import multiprocessing
  import ctypes
  from typing import List, Optional, Union, Generator, Sequence, Iterator, Deque, Tuple
  from collections import deque, OrderedDict
  from bigdl.llm.utils.common import invalidInputError
  from bigdl.llm.ggml.model.generation import GenerationMixin
  from .None import gptneox_cpp
  from .gptneox_types import *
label_desc: Use image node_id 7 for calling the Gptneox obj's underlying member method code with example usage: obj._sample(last_n_tokens_data, last_n_tokens_size, top_k, top_p, temp, tfs_z, repeat_penalty, frequency_penalty, presence_penalty, mirostat_mode, mirostat_tau, mirostat_eta) and returns: gptneox_cpp, gptneox_cpp, gptneox_cpp, gptneox_cpp