Skip to content

Commit

Permalink
rm TODO comments; re-try the deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
swfsql committed Feb 29, 2024
1 parent 072efc0 commit aa809d8
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 79 deletions.
64 changes: 21 additions & 43 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.9.4/css/bulma.min.css">
</head>

<!-- TODO: maybe a <body> is not required - see yew example -->

<body>
<noscript>This page uses wasm and js. Please enable them.</noscript>
<script type="module" src="./index.js"></script>
Expand Down
1 change: 0 additions & 1 deletion src/common/mamba.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<DModel>,
// TODO: delete this layer? It's the same weights from the embedding.
#[module]
pub lm_head: LinearConfig<DModel, Vocab>,
}
Expand Down
2 changes: 0 additions & 2 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 0 additions & 6 deletions src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -22,9 +19,6 @@ pub async fn wasm_main() {
use crate::wasm::yew_ui::Msg;
let handle = yew::Renderer::<yew_ui::Model>::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");
Expand Down
2 changes: 0 additions & 2 deletions src/wasm/non_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 0 additions & 4 deletions src/wasm/yew_ui/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use tokenizers::Tokenizer;

pub struct Model {
// general data
// TODO: allow to use wgpu device
/// Dfdx [Cpu] device.
pub device: Cpu,

Expand Down Expand Up @@ -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<u8>, device: &Cpu) {
match selection {
ModelSelection::Tokenizer => {
Expand All @@ -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,
Expand Down
20 changes: 12 additions & 8 deletions src/wasm/yew_ui/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions src/wasm/yew_ui/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ impl model::Model {
<div class="navbar-menu">
<div class="navbar-end">
<div class="navbar-item">
// TODO: make into a button that can try to connect/disconnect
if self.cache_api.is_exactly_connected() {
<span class="tag is-success is-light">
{"Connected to cache"}
Expand Down Expand Up @@ -252,10 +251,6 @@ fn model_data<M: yew::Component<Message = Msg>>(
(false, _loaded @ true, false) => html_nested! {<>
<button
class="button is-success is-light"
// TODO:
// if generating: stop generation
// also if models built: unload them
// also if models data loaded: drop them
onclick={link.callback(move |_| Msg::ModelDataUnload(selection))}
>
{format!("Loaded ({total_bytes_human})..")}
Expand Down Expand Up @@ -290,7 +285,6 @@ fn model_data<M: yew::Component<Message = Msg>>(
(_checking @ false, _cached @ false, _fetching @ false) => html_nested! {<>
<button
class="button"
// todo: download missing chunks
onclick={link.callback(move |_| Msg::StartModelDataFetch(selection))}
>
{"Not cached"}
Expand All @@ -312,7 +306,6 @@ fn model_data<M: yew::Component<Message = Msg>>(
(false, _cached @ true, false) => html_nested! {<>
<button
class="button is-success is-light"
// todo: erase downloaded chunks
onclick={link.callback(move |_| Msg::StartModelDataErase(selection))}
>
{format!("Cached ({total_bytes_human})")}
Expand Down Expand Up @@ -363,7 +356,6 @@ fn model_data<M: yew::Component<Message = Msg>>(
<button
class="button"
disabled={true}
// todo: load data directly, skipping the fetch and the cache
onclick={link.callback(move |_| Msg::StartModelDataUpload(selection))}
>
{"Load from file"}
Expand Down

0 comments on commit aa809d8

Please sign in to comment.