Skip to content

Commit

Permalink
Improve test, minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-andex committed Jan 7, 2024
1 parent 2078bd5 commit ec4c9e1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "wasm-pack build -s text-yoga --dev",
"build:release": "wasm-pack build -s text-yoga --release",
"test:server": "npx http-server --cors -p 31300 ./tests/data",
"test:chrome": "wasm-pack test --chrome --chromedriver \"$(which chromedriver)\" --headless",
"test:chrome": "RUST_LOG=wasm_bindgen_test_runner wasm-pack -vvv test --chrome --chromedriver \"$(which chromedriver)\" --headless",
"test:gecko": "wasm-pack test --firefox --geckodriver \"$(which geckodriver)\" --headless"
},
"keywords": [],
Expand Down
14 changes: 5 additions & 9 deletions src/quantized_mistral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tokenizers::Tokenizer;
use wasm_bindgen::prelude::*;
use web_time as time;

use gloo::console::log;
use gloo::console::{debug, log};
use web_sys::console;

#[wasm_bindgen]
Expand Down Expand Up @@ -84,9 +84,6 @@ impl Model {
let mut total_size_in_bytes = 0;
for (_, tensor) in model.tensor_infos.iter() {
let elem_count = tensor.shape.elem_count();
log!("elem_count", elem_count);
log!("type_size", tensor.ggml_dtype.type_size());
log!("blck_size", tensor.ggml_dtype.blck_size());
total_size_in_bytes +=
// Very important to keep the parenthesis here, otherwise might overflow (in test).
elem_count * (tensor.ggml_dtype.type_size() / tensor.ggml_dtype.blck_size());
Expand Down Expand Up @@ -128,11 +125,10 @@ impl Model {
repeat_penalty: f32,
seed: u64,
) -> Result<String, JsError> {
console::log_1(&"Initialising prompt with temperature=".into());
console::log_2(&"temperature=".into(), &temp.into());
console::log_2(&"top_p=".into(), &top_p.into());
console::log_2(&"repeat_penalty=".into(), &repeat_penalty.into());
console::log_2(&"seed=".into(), &seed.into());
debug!(
"Initialising prompt with temperature=",
temp, "top_p=", top_p, "repeat_penalty=", repeat_penalty, "seed=", seed
);
// First reset the cache.
// {
// let mut cache = self.inner.cache.kvs.lock().unwrap();
Expand Down
12 changes: 11 additions & 1 deletion tests/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,19 @@ async fn pass() -> Result<(), JsValue> {
let top_p: f64 = 1.;
let repeat_penalty: f32 = 1.1;
let seed: u64 = 203948203948;
let max_token = 20;
let first_result: String = model.init_with_prompt(prompt, temp, top_p, repeat_penalty, seed)?;

log!("first prompt result", &first_result);
assert_eq!(1 + 1, 2);

let mut result = first_result;
for index in 0..max_token {
let tok = model.next_token()?;
result += &tok;
log!(tok);
}
log!("\nComplete result:");
log!(result);
let result = assert_eq!(1 + 1, 2);
Ok(())
}

0 comments on commit ec4c9e1

Please sign in to comment.