From aa809d81b899e67688e6784081cde04e4247e8ec Mon Sep 17 00:00:00 2001 From: Thiago Machado Date: Thu, 29 Feb 2024 01:00:31 -0500 Subject: [PATCH] rm TODO comments; re-try the deploy --- .github/workflows/deploy.yml | 64 ++++++++++++------------------------ README.md | 7 ++-- index.html | 2 -- src/common/mamba.rs | 1 - src/common/mod.rs | 2 -- src/wasm/mod.rs | 6 ---- src/wasm/non_ui.rs | 2 -- src/wasm/yew_ui/model.rs | 4 --- src/wasm/yew_ui/update.rs | 20 ++++++----- src/wasm/yew_ui/view.rs | 8 ----- 10 files changed, 37 insertions(+), 79 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d11ce8b..7804f96 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -16,17 +16,9 @@ env: jobs: build: runs-on: ubuntu-latest + # permissions: + # contents: write steps: - # rust compiler for running tests - - uses: actions/checkout@v2 - - name: Install latest nightly (for linux-gnu) - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - target: x86_64-unknown-linux-gnu - components: rustfmt, clippy - # override: true - # rust compiler for creating binaries - name: Install latest nightly (for wasm) uses: actions-rs/toolchain@v1 @@ -43,43 +35,29 @@ jobs: # Runs some Rust-related caching - uses: Swatinem/rust-cache@v2 + + - name: Install wasm-pack + uses: actions-rs/cargo@v1 + with: + command: install + args: --target-dir ./target/wasm/ wasm-pack - # Get Trunk (can prepare assets for publishing) - - uses: jetli/trunk-action@v0.1.0 - with: - version: 'latest' - - # Used to optimize wasm binaries - # based on - # https://github.com/rustwasm/walrus/blob/9d6c9de432d6a97478dc76ebdf18aed51584c3af/.github/workflows/main.yml#L56 - - name: Install binaryen - run: | - set -e - curl -L https://github.com/WebAssembly/binaryen/releases/download/version_117/binaryen-version_117-x86_64-linux.tar.gz | tar xzf - - echo "`pwd`/binaryen-version_117/bin" >> $GITHUB_PATH - - # Build the Mamba App - - name: Trunk Build (Mamba) - run: | - set -e - trunk build --release --public-url ./ - - # Prepare assets for publishing - - name: Move and optimize assets - run: | - set -e + - name: Build Release wasm + run: wasm-pack build --release --target web --no-default-features --features "wasm_yew_ui" - # Prepare the publishing structure - mkdir -p publish/ + - name: Prepare Wasm deploy + run: | + set -e + # Prepare the publishing structure + mkdir -p publish/ - # move Mamba App assets - mv -vn ./dist/* publish/ + # move assets + mv index.html publish/ + mv index.js publish/ + mv pkg/ publish/pkg/ - # Optimize wasm binaries - find publish/ \ - -name \*.wasm \ - -prune \ - -exec wasm-opt -Oz -o "{}" "{}" \; + # rm gitignore + rm publish/pkg/.gitignore # Publish - name: Frontend Deploy diff --git a/README.md b/README.md index e154f77..42b43af 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # mamba-minimal-dfdx-example -Adapted from [huggingface/candle/mamba-minimal](https://github.com/huggingface/candle/blob/fd7c8565646039e35925b8730d27ddad195d7e73/candle-examples/examples/mamba-minimal/). +Click [here](https://swfsql.github.io/mamba-minimal-dfdx-example/) to run the model in your browser. + +### Information -This is a temporary commit. Later this will be squashed etc. +Adapted from [huggingface/candle/mamba-minimal](https://github.com/huggingface/candle/blob/fd7c8565646039e35925b8730d27ddad195d7e73/candle-examples/examples/mamba-minimal/). ### Building @@ -11,7 +13,6 @@ This is a temporary commit. Later this will be squashed etc. RUSTFLAGS="-C target-cpu=native" cargo run --release --no-default-features --features "native" ``` -TODO: add starting prompt as an arg parameter to the binary ##### WASM ```bash diff --git a/index.html b/index.html index 71dcb1a..34fc8f8 100644 --- a/index.html +++ b/index.html @@ -8,8 +8,6 @@ - - diff --git a/src/common/mamba.rs b/src/common/mamba.rs index 6e3e3e6..8665d61 100644 --- a/src/common/mamba.rs +++ b/src/common/mamba.rs @@ -69,7 +69,6 @@ pub struct MambaConfig { // note: in here no result discards are made, which differs from the references. #[module] pub norm_f: LayerRMSNorm1DConfig, - // TODO: delete this layer? It's the same weights from the embedding. #[module] pub lm_head: LinearConfig, } diff --git a/src/common/mod.rs b/src/common/mod.rs index baa66e6..4839883 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -233,8 +233,6 @@ impl LogitsProcessorWrapper { } } - // TODO: check if `i` should really start a zero, or check if something else is wrong. - // /// Add logits that represents a token. /// /// `i` is the i-th call. For the first call, `i` should be `0`. diff --git a/src/wasm/mod.rs b/src/wasm/mod.rs index 11a3519..0c2fd4d 100644 --- a/src/wasm/mod.rs +++ b/src/wasm/mod.rs @@ -3,9 +3,6 @@ pub mod non_ui; #[cfg(feature = "wasm_yew_ui")] pub mod yew_ui; -// TODO -// pub mod dioxus_ui; - use wasm_bindgen::prelude::wasm_bindgen; #[wasm_bindgen] @@ -22,9 +19,6 @@ pub async fn wasm_main() { use crate::wasm::yew_ui::Msg; let handle = yew::Renderer::::new().render(); handle.send_message_batch(vec![Msg::StartConnectApi]); - // TODO: shouldn't the handle be awaited or something? - // otherwise shouldn't the main thread drop on "wasm finished"? - // wtf } log::info!("wasm finished"); diff --git a/src/wasm/non_ui.rs b/src/wasm/non_ui.rs index 882ef72..8c36c9b 100644 --- a/src/wasm/non_ui.rs +++ b/src/wasm/non_ui.rs @@ -60,8 +60,6 @@ pub async fn run() -> anyhow::Result<()> { let padded_vocab_size = 50280; let d_model = 768; - // TODO: avoid random initialization and just initialize with zeroes - // TODO: avoid initialization and instead initialize directly from the data timing = web_time::Instant::now(); log::info!("initializing random mamba model"); let mamba = diff --git a/src/wasm/yew_ui/model.rs b/src/wasm/yew_ui/model.rs index 6ef9a29..6fb7fc3 100644 --- a/src/wasm/yew_ui/model.rs +++ b/src/wasm/yew_ui/model.rs @@ -9,7 +9,6 @@ use tokenizers::Tokenizer; pub struct Model { // general data - // TODO: allow to use wgpu device /// Dfdx [Cpu] device. pub device: Cpu, @@ -124,7 +123,6 @@ impl MambaWrapperBuilder { pub fn build(self) -> Wrapper { self.into() } - // TODO: load in the background with webworkers pub fn with(&mut self, selection: &ModelSelection, data: Vec, device: &Cpu) { match selection { ModelSelection::Tokenizer => { @@ -139,8 +137,6 @@ impl MambaWrapperBuilder { let padded_vocab_size = 50280; let d_model = 768; - // TODO: avoid random initialization and just initialize with zeroes - // TODO: avoid initialization and instead initialize directly from the data log::info!("initializing random mamba model"); let mamba = mamba::MambaConfig::new( n_layer, diff --git a/src/wasm/yew_ui/update.rs b/src/wasm/yew_ui/update.rs index 0d89a0e..200bcf1 100644 --- a/src/wasm/yew_ui/update.rs +++ b/src/wasm/yew_ui/update.rs @@ -35,12 +35,15 @@ impl model::Model { } true } - // TODO: check if indexedDB needs some async operations to disconnect Msg::StartDisconnectApi => { - todo!() + log::error!("Msg::StartDisconnectApi not yet implemented"); + // todo!() + false } Msg::FinishDisconnectApi => { - todo!() + log::error!("Msg::FinishDisconnectApi not yet implemented"); + // todo!() + false } Msg::StartModelDataCheck(selection) => { let model_data = self.select(&selection); @@ -74,7 +77,6 @@ impl model::Model { let link = ctx.link().clone(); let api_repo = model_data.config.api_repo(&api); let url = model_data.config.file_url(); - // TODO: allow parallel chunk downloads ctx.link().send_future(async move { for (i, chunk_file) in chunk_files.into_iter().enumerate() { if let Err(chunk_file) = chunk_file { @@ -102,10 +104,14 @@ impl model::Model { true } Msg::StartModelDataUpload(_selection) => { - todo!() + log::error!("Msg::StartModelDataUpload not yet implemented"); + // todo!() + false } Msg::FinishModelDataUpload(_selection) => { - todo!() + log::error!("Msg::FinishModelDataUpload not yet implemented"); + // todo!() + false } Msg::StartModelDataLoad(selection) => { let api = self.cache_api.as_connected().unwrap().clone(); @@ -243,7 +249,6 @@ impl model::Model { }, // inference - // TODO: have a webworker to run in the background Msg::StartGeneration => { assert!(self.is_reset); assert!(!self.is_input_dirty); @@ -273,7 +278,6 @@ impl model::Model { true } - // TODO: have an interval to tick for step generations? Msg::StepGeneration => { if !self.is_generating { return true; diff --git a/src/wasm/yew_ui/view.rs b/src/wasm/yew_ui/view.rs index 3b4a11b..a67b611 100644 --- a/src/wasm/yew_ui/view.rs +++ b/src/wasm/yew_ui/view.rs @@ -18,7 +18,6 @@ impl model::Model {