Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion examples/qualcomm/oss_scripts/llama/runner/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,22 @@ Error Runner<T>::generate_from_prompt_or_file(
stats_.inference_start_ms = time_in_ms();

int32_t seq_len = config.seq_len;
seq_len = (seq_len > 0 && seq_len <= context_len_) ? seq_len : context_len_;
if (seq_len > context_len_) {
ET_LOG(
Info,
"Warning: Requested seq_len (%d) exceeds compiled max_seq_len (%d). Clamping to %d.",
seq_len,
context_len_,
context_len_);
seq_len = context_len_;
} else if (seq_len <= 0) {
ET_LOG(
Info,
"Warning: Invalid seq_len (%d). Using compiled max_seq_len (%d).",
seq_len,
context_len_);
seq_len = context_len_;
}
int32_t n_bos = (cur_pos_ == 0) ? 1 : 0;

// encode the (string) prompt into tokens sequence
Expand Down
24 changes: 24 additions & 0 deletions examples/qualcomm/oss_scripts/llama/runner/token_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,30 @@ Result<int64_t> TokenGenerator<T>::generate(
break;
}
}

// Check if generation was truncated due to seq_len limit (no EOS token)
if (eos_ids_->count(cur_token) == 0 && pos >= seq_len - 1) {
printf("\n");
ET_LOG(
Info,
"Warning: Generation stopped at seq_len limit (%d) without reaching EOS token. Response may be incomplete.",
seq_len);
if (seq_len >= metadata_.context_len) {
ET_LOG(
Info,
"- seq_len (%d) already equals compiled max_seq_len (%d). Consider recompiling with larger --max_seq_len.",
seq_len,
metadata_.context_len);
} else {
ET_LOG(
Info,
"- seq_len (%d) is less than compiled max_seq_len (%d). Consider increasing --seq_len (up to %d).",
seq_len,
metadata_.context_len,
metadata_.context_len);
}
}

return pos - start_pos;
}
// Explicit instantiations
Expand Down
Loading