38 std::chrono::steady_clock::time_point
t_entry;
74 std::map<std::string, double>
op_ms;
105 int max_batch_size = 1);
132 std::string
generate(
const std::string& prompt,
int steps = 128,
133 float temperature = 0.1f,
136 const std::string& system_prompt =
"",
158 float temperature = 0.1f,
161 const std::string& system_prompt =
"",
214 if (!
bpe_)
return {};
215 std::vector<int> ids =
bpe_->encode(
text);
249 std::string
bpe_decode(
const std::vector<int>& ids)
const {
return bpe_ ?
bpe_->decode(ids) : std::string(); }
272 const std::vector<std::string>&
gguf_tokens()
const;
291 std::unique_ptr<ember_ir::Interpreter>
ir_;
297 std::mt19937
rng_{std::random_device{}()};
307 std::unique_ptr<ember::ChatTokenizer>
bpe_;
A lightweight tokenizer implementation for text processing.
Represents an active TinyLlama session holding the loaded model and tokenizer.
bool use_batch_generation_
int last_generated_tokens() const
bool batch_generation_parallel(const std::vector< int > ¤t_tokens, const std::vector< int > &token_positions, const std::vector< int > &original_sequence_indices, std::vector< std::vector< float > > &batch_logits)
std::vector< float > score_rows(const std::vector< int > &ids, int first_row, bool reuse_prefix, int *reused=nullptr)
std::string chat_template_why_
int score_context() const
bool score_reuse_ok() const
std::unique_ptr< ember::ChatTokenizer > bpe_
bool batch_prefill_parallel(const std::vector< std::vector< int > > &all_tokens, const std::vector< int > &prompt_lengths, std::vector< std::vector< float > > &batch_final_logits)
std::string bpe_decode(const std::vector< int > &ids) const
std::stringstream generated_stream_
float get_repetition_penalty() const
std::vector< int > last_prompt_ids_
std::string last_stop_reason_
std::unique_ptr< TinyLlamaModel > model_
const std::vector< int > & last_generated_ids() const
std::vector< std::vector< int > > scripted_replies_
const std::string & chat_template_why() const
TinyLlamaSession(const TinyLlamaSession &)=delete
std::function< void(int)> token_callback_
std::vector< int > bpe_prompt_ids(const std::string &text) const
std::unique_ptr< ember_ir::Interpreter > ir_
std::unique_ptr< Tokenizer > tokenizer_
std::vector< int > score_ids_
const Tokenizer * get_tokenizer() const
std::vector< int > kv_token_history_
const TtftBreakdown & last_ttft() const
const ember::ChatFormat * chat_format() const
std::string generate(const std::string &prompt, int steps=128, float temperature=0.1f, int top_k=40, float top_p=0.9f, const std::string &system_prompt="", bool apply_q_a_format=false)
Generates text based on a given prompt.
const std::string & last_stop_reason() const
void set_repeat_penalty(float p, int last_n)
void set_repetition_penalty(float p)
const std::vector< int > & last_prompt_ids() const
std::vector< std::string > generate_batch(const std::vector< std::string > &prompts, int steps=128, float temperature=0.1f, int top_k=40, float top_p=0.9f, const std::string &system_prompt="", bool apply_q_a_format=false)
Generates text for multiple prompts in a single batch (parallel processing).
const ModelConfig & get_config() const
std::vector< int > last_generated_ids_
bool is_chat_stop(int id) const
std::string generated_text_for_api_return_
float repetition_penalty_
void set_token_callback(std::function< void(int)> cb)
~TinyLlamaSession()
Destructor to ensure proper cleanup (e.g., KVCache CUDA memory).
std::vector< int > bpe_encode(const std::string &text) const
void set_scripted_replies(std::vector< std::vector< int > > r)
void set_seed(unsigned seed)
std::unique_ptr< microtorch::chat::Template > word_template_
bool is_chat_eos(int id) const
const std::string & ir_document() const
int bpe_token_count(const std::string &text) const
const microtorch::chat::Template * chat_template() const
const std::vector< std::string > & gguf_tokens() const
TinyLlamaSession & operator=(const TinyLlamaSession &)=delete
int last_generated_tokens_
int sample_step(std::vector< float > &logits, const std::vector< int > &context, float temperature, int top_k, float top_p)
const float * p[kIrDepthSourcesMax]
std::vector< int > insert_state_blocks(const std::vector< int > &ids, int vocab, int k, int eot, int user, int assistant)
Complete Key-Value cache for all transformer layers.
Model configuration structure holding architecture and hyperparameters.
Where the time went between generate() being called and its first output token being emitted (docs/TT...
std::chrono::steady_clock::time_point t_first_token
int prefix_prev_cached_tokens
int prefix_reusable_tokens
std::map< std::string, double > op_ms
std::chrono::steady_clock::time_point t_entry
double prefill_gpu_span_ms