MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / _shared_generate

Method _shared_generate

src/common/AutoModel/automodel.cpp:250–327  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

248}
249
250std::string AutoModel::_shared_generate(chat_meta_info_t& meta_info, int length_limit, std::ostream& os, std::function<bool()> is_cancelled) {
251 std::vector<int> sampled_tokens;
252 std::string result;
253 if (length_limit > 0){
254 sampled_tokens.reserve(length_limit);
255 }
256 else{
257 sampled_tokens.reserve(4096);
258 }
259 assert(this->last_token != -1);
260
261 stop_reason_t reason = EOT_DETECTED;
262 int last_sampled_token = this->last_token;
263 this->token_history.push_back(this->last_token);
264 if (this->is_normal_token(last_sampled_token) && last_sampled_token != -1){
265 std::string token_str = this->tokenizer->run_time_decoder(last_sampled_token);
266 result += token_str;
267 os << token_str << std::flush;
268
269 }
270 if (this->is_eos(last_sampled_token)){
271 return result;
272 }
273 this->profiler_list[DECODING_TIME].reset();
274 this->profiler_list[TKOEN_DECODE_TIME].reset();
275 if (this->total_tokens >= this->MAX_L){
276 header_print("WARNING", "Max length reached, stopping generation...");
277 reason = MAX_LENGTH_REACHED;
278 return result;
279 }
280 while (this->total_tokens < this->MAX_L){
281 if (is_cancelled()) {
282 reason = CANCEL_DETECTED;
283 // reset stream content
284 buffer_.clear();
285 current_mode_ = StreamEventType::CONTENT;
286 tool_name_.clear();
287 is_in_tool_block_ = false;
288 break;
289 }
290 this->profiler_list[DECODING_TIME].start();
291 buffer<bf16> y = this->lm_engine->forward(last_sampled_token);
292 this->profiler_list[DECODING_TIME].stop(1);
293
294 this->profiler_list[SAMPLING_TIME].start();
295 int sampled_token = this->sampler->sample(y);
296 this->profiler_list[SAMPLING_TIME].stop(1);
297 this->total_tokens++;
298 last_sampled_token = sampled_token;
299
300 this->profiler_list[TKOEN_DECODE_TIME].start();
301 if (this->is_normal_token(sampled_token)){ // filter out special tokens
302 std::string token_str = this->tokenizer->run_time_decoder(sampled_token);
303 os << token_str << std::flush;
304 result += token_str;
305 }
306 this->profiler_list[TKOEN_DECODE_TIME].stop(1);
307 this->token_history.push_back(sampled_token);

Callers 15

generateMethod · 0.80
generate_with_promptMethod · 0.80
generateMethod · 0.80
generate_with_promptMethod · 0.80
generate_with_promptMethod · 0.80
generate_with_promptMethod · 0.80
generateMethod · 0.80
generate_with_promptMethod · 0.80
generateMethod · 0.80
generate_with_promptMethod · 0.80
generateMethod · 0.80
generateMethod · 0.80

Calls 13

is_normal_tokenMethod · 0.95
is_eosMethod · 0.95
cast_to_usFunction · 0.85
push_backMethod · 0.80
run_time_decoderMethod · 0.80
clearMethod · 0.80
forwardMethod · 0.80
sampleMethod · 0.80
get_total_timeMethod · 0.80
reserveMethod · 0.45
resetMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected