Skip to content

Commit a0f643b

Browse files
committed
fix cherrpicked commits
1 parent dc52d3b commit a0f643b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

embeddings/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use llama_cpp_2::ggml_time_us;
2020
use llama_cpp_2::llama_backend::LlamaBackend;
2121
use llama_cpp_2::llama_batch::LlamaBatch;
2222
use llama_cpp_2::model::params::LlamaModelParams;
23-
use llama_cpp_2::model::AddBos;
23+
use llama_cpp_2::model::{AddBos, Special};
2424
use llama_cpp_2::model::LlamaModel;
2525

2626
#[derive(clap::Parser, Debug, Clone)]
@@ -138,7 +138,7 @@ fn main() -> Result<()> {
138138
eprintln!("Prompt {i}");
139139
for token in token_line {
140140
// Attempt to convert token to string and print it; if it fails, print the token instead
141-
match model.token_to_str(*token) {
141+
match model.token_to_str(*token, Special::Tokenize) {
142142
Ok(token_str) => eprintln!(" {} --> {}", token, token_str),
143143
Err(e) => {
144144
eprintln!("Failed to convert token to string, error: {}", e);

llama-cpp-2/src/model.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ impl LlamaModel {
122122
/// # Errors
123123
///
124124
/// See [`TokenToStringError`] for more information.
125-
pub fn token_to_bytes(&self, token: LlamaToken) -> Result<Vec<u8>, TokenToStringError> {
126-
self.token_to_bytes_with_size(token, 32)
125+
pub fn token_to_bytes(&self, token: LlamaToken, special: Special) -> Result<Vec<u8>, TokenToStringError> {
126+
self.token_to_bytes_with_size(token, 32, special)
127127
}
128128

129129
/// Convert a vector of tokens to a single string.
@@ -248,7 +248,7 @@ impl LlamaModel {
248248
buffer_size: usize,
249249
special: Special,
250250
) -> Result<String, TokenToStringError> {
251-
let bytes = self.token_to_bytes_with_size(token, buffer_size)?;
251+
let bytes = self.token_to_bytes_with_size(token, buffer_size, special)?;
252252
Ok(String::from_utf8(bytes)?)
253253
}
254254

@@ -270,6 +270,7 @@ impl LlamaModel {
270270
&self,
271271
token: LlamaToken,
272272
buffer_size: usize,
273+
special: Special,
273274
) -> Result<Vec<u8>, TokenToStringError> {
274275
if token == self.token_nl() {
275276
return Ok(String::from("\n").into_bytes());

simple/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ either reduce n_len or increase n_ctx"
259259
break;
260260
}
261261

262-
let output_bytes = model.token_to_bytes(new_token_id)?;
262+
let output_bytes = model.token_to_bytes(new_token_id, Special::Tokenize)?;
263263
// use `Decoder.decode_to_string()` to avoid the intermediate buffer
264264
let mut output_string = String::with_capacity(32);
265265
let _decode_result = decoder.decode_to_string(&output_bytes, &mut output_string, false);

0 commit comments

Comments
 (0)