fix(training): WASM contrastive loss + NAPI optimizer step#339
Merged
Conversation
…tep semantics ADR-145: Fix training pipeline issues across WASM and NAPI bindings. WASM (ruvector-attention-wasm): - Replace serde_wasm_bindgen deserialization of negatives param with explicit js_sys::Float32Array conversion. TypedArrays don't deserialize via serde — use js_sys::Array iteration instead. NAPI (ruvector-attention-node): - Add stepInPlace() to SGD, Adam, AdamW optimizers for zero-copy in-place parameter mutation via Float32Array's AsMut<[f32]> - Document that step() returns a NEW array (callers must use return) Note: LoRA B=0 initialization in learning-wasm is correct by design (Hu et al. 2021) — documented in ADR-145, no code change needed. Co-Authored-By: claude-flow <ruv@ruv.net>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes training pipeline issues across WASM and NAPI bindings (ADR-145).
WasmInfoNCELoss::compute()failed onFloat32Array[]input — replacedserde_wasm_bindgendeserialization with explicitjs_sys::Float32ArrayconversionstepInPlace()to all 3 optimizers (SGD, Adam, AdamW) for zero-copy in-place parameter mutation viaAsMut<[f32]>. Documented thatstep()returns a new array.Test plan
cargo check -p ruvector-attention-wasm --target wasm32-unknown-unknownpassescargo check -p ruvector-attention-nodepasses🤖 Generated with claude-flow