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

Method generate

src/common/AutoModel/modeling_qwen3.cpp:102–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102std::string Qwen3::generate(chat_meta_info_t& meta_info, int length_limit, std::ostream& os, std::function<bool()> is_cancelled) {
103 std::vector<int> sampled_tokens;
104 std::string result;
105 if (length_limit > 0){
106 sampled_tokens.reserve(length_limit);
107 }
108 else{
109 sampled_tokens.reserve(4096);
110 }
111 assert(this->last_token != -1);
112 stop_reason_t reason = EOT_DETECTED;
113
114 this->profiler_list[DECODING_TIME].reset();
115 this->profiler_list[TKOEN_DECODE_TIME].reset();
116 std::string token_str;
117 int sampled_token;
118 int last_sampled_token;
119 if(!enable_think) {
120 this->token_history.push_back(think_start_id);
121 this->lm_engine->forward(think_start_id);
122 token_str = this->tokenizer->run_time_decoder(think_start_id);
123
124 // \n\n
125 this->token_history.push_back(271);
126 this->profiler_list[DECODING_TIME].start();
127 this->lm_engine->forward(271);
128 this->profiler_list[DECODING_TIME].stop(1);
129 token_str = this->tokenizer->run_time_decoder(271);
130
131 this->token_history.push_back(think_end_id);
132 this->profiler_list[DECODING_TIME].start();
133 this->lm_engine->forward(think_end_id);
134 this->profiler_list[DECODING_TIME].stop(1);
135 token_str = this->tokenizer->run_time_decoder(think_end_id);
136
137 this->token_history.push_back(271);
138 this->profiler_list[DECODING_TIME].start();
139 buffer<bf16> y = this->lm_engine->forward(271);
140 this->profiler_list[DECODING_TIME].stop(1);
141 token_str = this->tokenizer->run_time_decoder(271);
142 sampled_token = this->sampler->sample(y);
143
144 this->total_tokens++;
145 meta_info.generated_tokens++;
146 last_sampled_token = sampled_token;
147 token_str = this->tokenizer->run_time_decoder(last_sampled_token);
148 result += token_str;
149 os << token_str << std::flush;
150 }
151 else {
152 last_sampled_token = this->last_token;
153 this->token_history.push_back(this->last_token);
154 if (this->is_normal_token(last_sampled_token) && last_sampled_token != -1){
155 std::string token_str = this->tokenizer->run_time_decoder(last_sampled_token);
156 result += token_str;
157 os << token_str << std::flush;
158
159 }

Callers 1

generate_with_promptMethod · 0.45

Calls 14

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

Tested by

no test coverage detected