22 static const bool on = [] {
23 const char*
v = std::getenv(
"EMBER_SCORE_FULL");
24 return v && std::string(
v) ==
"1";
34 if (
ir_ &&
ir_->max_len() > 0) ctx = std::min(ctx,
ir_->max_len());
39 static const std::vector<std::string>
none;
45 static const bool off = [] {
46 const char*
v = std::getenv(
"EMBER_SCORE_REUSE");
47 return v && std::string(
v) ==
"0";
51 return !
ir_->on_gpu() && !
ir_->has_recurrent() && !
ir_->evicts() && !
ir_->has_depth_route() &&
52 ir_->state_k() == 0 && !
ir_->turn_state();
58 const int n =
static_cast<int>(ids.size());
61 throw std::invalid_argument(
"score_rows: " + std::to_string(
n) +
" positions exceed the context of " +
77 std::vector<float>
out;
79 const std::vector<int>
tail(ids.begin() +
reuse, ids.end());
84 if (
all.size() !=
static_cast<size_t>(
m) *
V)
85 throw std::runtime_error(
"score: the interpreter returned " + std::to_string(
all.size()) +
" logits");
97 std::vector<float>
h(
static_cast<size_t>(
m) *
hs);
98 for (
int i = 0;
i <
m; ++
i) {
99 const std::vector<float>
e =
model_->lookup_embedding(ids[
reuse +
i]);
100 if (
e.size() !=
static_cast<size_t>(
hs))
101 throw std::runtime_error(
"score: no embedding for token id " + std::to_string(ids[
reuse +
i]));
102 std::copy(
e.begin(),
e.end(),
h.begin() +
static_cast<long>(
i) *
hs);
106 if (
h.size() !=
static_cast<size_t>(
m) *
hs)
throw std::runtime_error(
"score: the CPU layers failed");
110 std::vector<float>
keep =
h;
114 if (
lg.size() !=
static_cast<size_t>(
k_rows) *
V)
throw std::runtime_error(
"score: the LM head failed");
115 out.assign(
lg.end() -
static_cast<long>(
rows) *
V,
lg.end());
129 const std::vector<float>
all =
132 if (
all.size() !=
static_cast<size_t>(
m) *
V)
133 throw std::runtime_error(
"score: the device prefill returned " + std::to_string(
all.size()) +
" logits");
136 throw std::runtime_error(
"score: GPU layers requested but CUDA not available");
141 if (
out.size() !=
static_cast<size_t>(
rows) *
V)
142 throw std::runtime_error(
"score: " + std::to_string(
out.size()) +
" logits for " + std::to_string(
rows) +
" rows");
Main transformer model class for TinyLlama.
void set_gemm_fp32_only(bool on)
std::vector< float > score_rows(const std::vector< int > &ids, int first_row, bool reuse_prefix, int *reused=nullptr)
int score_context() const
bool score_reuse_ok() const
std::unique_ptr< TinyLlamaModel > model_
std::unique_ptr< ember_ir::Interpreter > ir_
std::vector< int > score_ids_
std::vector< int > kv_token_history_
const std::vector< std::string > & gguf_tokens() const
Complete representation of a GGUF file's contents.
std::vector< std::string > tokenizer_tokens
int num_cpu_offload_layers
int max_position_embeddings