Skip to content

Commit

Permalink
Doing something, not sure what though
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-andex committed Jan 8, 2024
1 parent 589b80e commit 5ffb94d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"rust-analyzer.runnables.extraEnv": {
"RUSTFLAGS": "--cfg=web_sys_unstable_apis"
},
"rust-analyzer.cargo.extraEnv": {
"RUSTFLAGS": "--cfg=web_sys_unstable_apis"
}
}
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ repository = "https://github.com/text-yoga/transformers-wasm"
[lib]
crate-type = ["cdylib", "rlib"]

[build]
rustflags = ["--cfg=web_sys_unstable_apis"]

[features]
default = ["console_error_panic_hook"]

Expand Down Expand Up @@ -45,7 +48,11 @@ features = [
'RequestMode',
'Response',
'Window',
'Navigator',
'Gpu',
'WgslLanguageFeatures'
]

version = "0.3.64"

[dev-dependencies]
Expand Down
19 changes: 18 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use js_sys::{ArrayBuffer, Uint8Array};

use wasm_bindgen::{prelude::*, JsValue};
use wasm_bindgen_futures::JsFuture;
use web_sys::{Request, RequestInit, RequestMode, Response};
use web_sys::{Navigator, Request, RequestInit, RequestMode, Response, Window};

pub fn set_panic_hook() {
// When the `console_error_panic_hook` feature is enabled, we can call the
Expand Down Expand Up @@ -48,3 +48,20 @@ pub async fn load_binary(url: &str) -> Result<Vec<u8>, JsValue> {
log!(url, x);
Ok(vec)
}

#[cfg(web_sys_unstable_apis)]
pub async fn has_gpu() -> bool {
let window = web_sys::window().expect("no global `window` exists");
let navigator = window.navigator();

let gpu: web_sys::Gpu = navigator.gpu();
let has_gpu_check = JsFuture::from(gpu.request_adapter()).await;

let mut has_gpu = false;
match has_gpu_check {
Ok(_) => has_gpu = true,
Err(err) => {}
}
log!("wgsl_language_features");
has_gpu
}
6 changes: 4 additions & 2 deletions tests/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ use transformers_wasm::utils;
use wasm_bindgen::{prelude::*, JsValue};
use wasm_bindgen_futures::JsFuture;
use wasm_bindgen_test::*;
use web_sys::console;
use web_sys::{Request, RequestInit, RequestMode, Response};
use web_sys::{console, Request, RequestInit, RequestMode, Response};

wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
async fn pass() -> Result<(), JsValue> {
#[cfg(web_sys_unstable_apis)]
log!(utils::has_gpu().await);

let tokenizer_url = "http://localhost:31300/TinyLlama_TinyLlama-1.1B-Chat-v1.0/tokenizer.json";
let model_url = "http://localhost:31300/TheBloke_TinyLlama-1.1B-Chat-v1.0-GGUF/tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf";

Expand Down

0 comments on commit 5ffb94d

Please sign in to comment.