#pragma once #include "engine/framework/sampling/torch_random.h" #include "engine/models/higgs_audio_tts/codebooks.h" #include #include #include #include namespace engine::models::higgs_audio_tts { constexpr int64_t kHiggsMaxTopK = 1026; using HiggsCudaSamplingPolicy = engine::sampling::TorchCudaSamplingPolicy; struct HiggsSamplingOptions { float temperature = 1.0F; std::optional top_p; std::optional top_k; bool filter_nan_logits = false; bool has_seed = false; uint64_t seed = 0; HiggsCudaSamplingPolicy cuda_policy; std::mt19937 * fallback_rng = nullptr; }; struct HiggsSamplerState { int64_t num_codebooks = 0; int64_t delay_count = 0; std::optional eoc_countdown; bool generation_done = false; int64_t step_count = 0; std::vector last_codes; }; class HiggsCodebookSampler { public: explicit HiggsCodebookSampler(int64_t num_codebooks, int64_t codebook_vocab_size); HiggsSamplerState make_state() const; const std::vector & step(const float * logits, int64_t logits_count, HiggsSamplerState & state, HiggsSamplingOptions & options); private: int64_t num_codebooks_ = 0; int64_t codebook_vocab_size_ = 0; std::vector scratch_scores_; std::vector scratch_probs_; std::vector scratch_order_; std::vector scratch_kept_; std::vector scratch_codes_; }; } // namespace engine::models::higgs_audio_tts