\brief Constructor \param in_features the input features \param config the configuration
| 18 | /// \param in_features the input features |
| 19 | /// \param config the configuration |
| 20 | Sampler::Sampler(int in_features, sampler_config& config) { |
| 21 | this->in_features = in_features; |
| 22 | this->logits.resize(in_features); |
| 23 | this->counters.resize(in_features, 0); |
| 24 | this->token_positions.resize(in_features, -1); |
| 25 | this->top_k_logits.resize(config.top_k); |
| 26 | |
| 27 | this->temperature = config.temperature; |
| 28 | this->top_k = config.top_k; |
| 29 | this->top_p = config.top_p; |
| 30 | this->min_p = config.min_p; |
| 31 | this->total_tokens = 0; |
| 32 | |
| 33 | this->rep_penalty = config.rep_penalty; |
| 34 | this->freq_penalty = config.freq_penalty; |
| 35 | this->pre_penalty = config.pre_penalty; |
| 36 | this->rep_penalty_window = config.rep_penalty_window; |
| 37 | this->freq_penalty_window = config.freq_penalty_window; |
| 38 | this->repeat_last_n = config.repeat_last_n; |
| 39 | this->use_optimized_sampling = config.use_optimized_sampling; |
| 40 | |
| 41 | this->token_history.clear(); |
| 42 | |
| 43 | if (config.has_rng_seed || config.rng_seed != 0) { |
| 44 | rng_.seed(config.rng_seed); |
| 45 | } else { |
| 46 | auto seed = std::chrono::high_resolution_clock::now() |
| 47 | .time_since_epoch() |
| 48 | .count(); |
| 49 | rng_.seed(static_cast<uint64_t>(seed)); |
| 50 | } |
| 51 | uniform_dist_ = std::uniform_real_distribution<float>(0.0f, 1.0f); |
| 52 | } |
| 53 | |
| 54 | void Sampler::set_seed(uint64_t seed) { |
| 55 | rng_.seed(seed); |