{"_id":"@cooljapan/trustformers","_rev":"6-f426cb06dd1445849ef3a691edfaf430","name":"@cooljapan/trustformers","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@cooljapan/trustformers","version":"0.1.0","keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"license":"Apache-2.0","_id":"@cooljapan/trustformers@0.1.0","maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"homepage":"https://github.com/cool-japan/trustformers","bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"dist":{"shasum":"bb83550f05b129a25919d4dfe218ae6770b722dd","tarball":"https://registry.npmjs.org/@cooljapan/trustformers/-/trustformers-0.1.0.tgz","fileCount":6,"integrity":"sha512-tEj/ekhltPnVWJks4WcN8+XlehxYryJXByGj1ZkpSDoRDmZZFg6wcq8d+ReDP6E85HwmfdPqieCRTwhNuf+jbQ==","signatures":[{"sig":"MEUCIBAdCtRWbuq77u0dPbTLCPjN5nl7CaepgqDZRc0SWSqeAiEA+hg5eGOVIp6ef/qKd/vmhtIRTHc4nKi3bldFVcX9hbM=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1074352},"main":"trustformers_wasm.js","type":"module","types":"trustformers_wasm.d.ts","_npmUser":{"name":"kitasan","email":"info@kitasan.io"},"repository":{"url":"git+https://github.com/cool-japan/trustformers.git","type":"git"},"_npmVersion":"10.9.4","description":"WebAssembly bindings for TrustformeRS transformer library","directories":{},"sideEffects":["./trustformers_wasm.js","./snippets/*"],"_nodeVersion":"22.22.1","collaborators":["COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>"],"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/trustformers_0.1.0_1774165750597_0.1944534848630226","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@cooljapan/trustformers","version":"0.1.1","keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"license":"Apache-2.0","_id":"@cooljapan/trustformers@0.1.1","maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"homepage":"https://github.com/cool-japan/trustformers","bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"dist":{"shasum":"b77fc6926a86cc014c74b2daf85118b423041244","tarball":"https://registry.npmjs.org/@cooljapan/trustformers/-/trustformers-0.1.1.tgz","fileCount":6,"integrity":"sha512-yiGNowJvLlr4VZYsOnPauOy+anxt1LhRw/n0J/JaVVpPrkWbP9+POSLS+7nKFgG3sW1Eour/1rhhOA9N4ctDfQ==","signatures":[{"sig":"MEUCIAyyanuOOJ8WoqUVGnOxq9xGwHku14EWa64olZixF/ihAiEAz2DXugsQJumOEMy1eNA6jKNkiM4/91yVpVtSy5EV0I4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1066660},"main":"trustformers_wasm.js","type":"module","types":"trustformers_wasm.d.ts","_npmUser":{"name":"kitasan","email":"info@kitasan.io"},"repository":{"url":"git+https://github.com/cool-japan/trustformers.git","type":"git"},"_npmVersion":"10.9.7","description":"WebAssembly bindings for TrustformeRS transformer library","directories":{},"sideEffects":["./trustformers_wasm.js","./snippets/*"],"_nodeVersion":"22.22.2","collaborators":["COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>"],"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/trustformers_0.1.1_1777260391887_0.11881143709777242","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@cooljapan/trustformers","version":"0.1.2","keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"license":"Apache-2.0","_id":"@cooljapan/trustformers@0.1.2","maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"homepage":"https://github.com/cool-japan/trustformers","bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"dist":{"shasum":"14e08d2c93ae63616b3b2057fb91b2abec598315","tarball":"https://registry.npmjs.org/@cooljapan/trustformers/-/trustformers-0.1.2.tgz","fileCount":6,"integrity":"sha512-BEJz3I0Q3fqyZS8I6TqWFT2QHiOAuUdNoAASkd2O6BKWDC2JTKmYWorVJRDttc7r3EdaPKnTrmRxKmyuVD+DUQ==","signatures":[{"sig":"MEYCIQC9oC05BAlmfi+80Cw9D/nTRciPw5L9m2phEFjlLbYG1wIhAL7Rj/XleHTUJJk7USSZQkkLweECYJ5rI2Zew8DHS1/E","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1069864},"main":"trustformers_wasm.js","type":"module","types":"trustformers_wasm.d.ts","_npmUser":{"name":"kitasan","email":"info@kitasan.io"},"repository":{"url":"git+https://github.com/cool-japan/trustformers.git","type":"git"},"_npmVersion":"10.9.8","description":"WebAssembly bindings for TrustformeRS transformer library","directories":{},"sideEffects":["./trustformers_wasm.js","./snippets/*"],"_nodeVersion":"22.22.3","collaborators":["COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>"],"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/trustformers_0.1.2_1781984241832_0.10428110259100198","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@cooljapan/trustformers","version":"0.1.3","keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"license":"Apache-2.0","_id":"@cooljapan/trustformers@0.1.3","maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"homepage":"https://github.com/cool-japan/trustformers","bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"dist":{"shasum":"61c60720fa62b2e0df92024278b6d620d5823ba0","tarball":"https://registry.npmjs.org/@cooljapan/trustformers/-/trustformers-0.1.3.tgz","fileCount":6,"integrity":"sha512-IgmC8ixUUOb3yPjBbFKCIr9xAQ5o3h0YSJUpSWsntCELGNCPxQlfQ0hdrOiL2k1i8nBrcPWjGPisLMFs8ZTcUA==","signatures":[{"sig":"MEUCIAdC2PLhsq26fYtxHsmfTMRIEJ+ELej6mqTBywzH8shXAiEAz/jBUNMA28Gz2GKuXOHgrcs2ZV92iuGD8VqYNQRSDd0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1069872},"main":"trustformers_wasm.js","type":"module","types":"trustformers_wasm.d.ts","_npmUser":{"name":"kitasan","email":"info@kitasan.io"},"repository":{"url":"git+https://github.com/cool-japan/trustformers.git","type":"git"},"_npmVersion":"10.9.8","description":"WebAssembly bindings for TrustformeRS transformer library","directories":{},"sideEffects":["./trustformers_wasm.js","./snippets/*"],"_nodeVersion":"22.22.3","collaborators":["COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>"],"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/trustformers_0.1.3_1782326503047_0.35583238160358444","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@cooljapan/trustformers","version":"0.1.4","keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"license":"Apache-2.0","_id":"@cooljapan/trustformers@0.1.4","maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"homepage":"https://github.com/cool-japan/trustformers","bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"dist":{"shasum":"a48845004a15e000e06e35f3843bbf37c462eae2","tarball":"https://registry.npmjs.org/@cooljapan/trustformers/-/trustformers-0.1.4.tgz","fileCount":6,"integrity":"sha512-AABYgl5DgSNbrE5gcXa2v+3k7tC5oSw+MwQJbaRLtFyN0YLIrpX3wpag3ZbyIFp4WsRK/4eV8g1PC4rkBa7Ing==","signatures":[{"sig":"MEYCIQDSp+rhOLhKG+8RiPvnWH+HC7DycPQ8+DDKve8Rnke4yQIhANczrWl4kNtq2o5CxJ//696ROq5aai9x6pl8WJ8QKvU3","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1073592},"main":"trustformers_wasm.js","type":"module","types":"trustformers_wasm.d.ts","_npmUser":{"name":"kitasan","email":"info@kitasan.io"},"repository":{"url":"git+https://github.com/cool-japan/trustformers.git","type":"git"},"_npmVersion":"10.9.8","description":"WebAssembly bindings for TrustformeRS transformer library","directories":{},"sideEffects":["./trustformers_wasm.js","./snippets/*"],"_nodeVersion":"22.23.1","collaborators":["COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>"],"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/trustformers_0.1.4_1783022375516_0.5348725415368556","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@cooljapan/trustformers","type":"module","collaborators":["COOLJAPAN OU (Team KitaSan) <contact@cooljapan.tech>"],"description":"WebAssembly bindings for TrustformeRS transformer library","version":"0.2.0","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/cool-japan/trustformers.git"},"main":"trustformers_wasm.js","homepage":"https://github.com/cool-japan/trustformers","types":"trustformers_wasm.d.ts","sideEffects":["./trustformers_wasm.js","./snippets/*"],"keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"_id":"@cooljapan/trustformers@0.2.0","bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"_nodeVersion":"22.23.1","_npmVersion":"10.9.8","dist":{"integrity":"sha512-I+P8XMw1bgDhe38EBQzfgoX5vEXz6edE15MhuYeCMKnF5oYYH3QpxSANnk/wIo4dxxN8g9fER5oIznOebDZNwQ==","shasum":"4e7bc3963c19e665ae8fd91b1f326b9724b5e83c","tarball":"https://registry.npmjs.org/@cooljapan/trustformers/-/trustformers-0.2.0.tgz","fileCount":6,"unpackedSize":1073701,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCypcVzpykMBtWpCs6FfcL0syMoJcz5R0tmRmdCT+mjpAIgKl52hnJKurLK/plEMOkZt1iduXO/E7DbX9XyrrrB06A="}]},"_npmUser":{"name":"kitasan","email":"info@kitasan.io"},"directories":{},"maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/trustformers_0.2.0_1783529562741_0.9469848782749264"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-22T07:49:10.496Z","modified":"2026-07-08T16:52:43.099Z","0.1.0":"2026-03-22T07:49:10.755Z","0.1.1":"2026-04-27T03:26:32.061Z","0.1.2":"2026-06-20T19:37:22.020Z","0.1.3":"2026-06-24T18:41:43.270Z","0.1.4":"2026-07-02T19:59:35.682Z","0.2.0":"2026-07-08T16:52:42.936Z"},"bugs":{"url":"https://github.com/cool-japan/trustformers/issues"},"license":"Apache-2.0","homepage":"https://github.com/cool-japan/trustformers","keywords":["transformers","webassembly","wasm","machine-learning","nlp"],"repository":{"type":"git","url":"git+https://github.com/cool-japan/trustformers.git"},"description":"WebAssembly bindings for TrustformeRS transformer library","maintainers":[{"name":"kitasan","email":"info@kitasan.io"}],"readme":"# TrustformeRS WebAssembly\n\nWebAssembly bindings for the TrustformeRS transformer library, enabling transformer models to run directly in web browsers and Node.js environments with WebGPU hardware acceleration.\n\n**Version:** 0.2.0 | **Status:** Stable | **Tests:** ~130 | **SLoC:** 55,721 | **Last Updated:** 2026-07-02\n\n## Features\n\n- **WebGPU Backend**: GPU compute via direct `web-sys`/`js-sys` bindings to the browser WebGPU API (no `wgpu` crate dependency), with automatic CPU fallback — see \"WebGPU Notes\" below for current dispatch-path coverage\n- **Web Workers Parallelism**: Multi-threaded inference via SharedArrayBuffer\n- **IndexedDB Caching**: Persistent model and KV-cache storage in the browser\n- **BERT WASM Model**: Complete BERT implementation running in-browser\n- **React/Vue/Angular/Web Components**: First-class framework bindings\n- **Streaming Inference**: Token-by-token generation with streaming API\n- **SIMD Support**: Hardware-accelerated tensor ops where available\n- **Mobile Optimization**: Battery-aware, network-adaptive loading\n\n## Building\n\n### Prerequisites\n\n- Rust (latest stable)\n- wasm-pack (`curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh`)\n\n### Build Commands\n\n```bash\n# Build for all targets\n./build.sh\n\n# Or build individually:\nwasm-pack build --target web --out-dir pkg-web\nwasm-pack build --target bundler --out-dir pkg-bundler\nwasm-pack build --target nodejs --out-dir pkg-node\n```\n\n## Usage\n\n### Browser (Direct)\n\n```html\n<script type=\"module\">\nimport init, { TrustformersWasm, WasmTensor } from './pkg-web/trustformers_wasm.js';\n\nasync function run() {\n    await init();\n\n    const tf = new TrustformersWasm();\n    console.log('Version:', tf.version);  // \"0.2.0\"\n\n    // Create and manipulate tensors\n    const tensor = WasmTensor.new([1, 2, 3, 4], [2, 2]);\n    const result = tensor.add(tensor);\n    console.log('Result:', result.data);\n}\n\nrun();\n</script>\n```\n\n### Node.js\n\n```javascript\nconst { TrustformersWasm, WasmTensor } = require('./pkg-node/trustformers_wasm.js');\n\nconst tf = new TrustformersWasm();\nconst tensor = WasmTensor.new([1, 2, 3, 4], [2, 2]);\nconsole.log(tensor.toString());\n```\n\n### Webpack/Bundler\n\n```javascript\nimport * as wasm from './pkg-bundler/trustformers_wasm';\n\nasync function run() {\n    await wasm.default();\n\n    const tf = new wasm.TrustformersWasm();\n    // Use the library...\n}\n```\n\n## API Overview\n\nThis crate exposes roughly **2,276 public items** (functions, structs, enums, and traits, including trait/impl-block methods) across 102 source files under `src/`; about 621 of those are top-level module-level declarations.\n\n### Core Classes\n\n#### `TrustformersWasm`\nMain entry point for the library.\n\n```javascript\nconst tf = new TrustformersWasm();\nconsole.log(tf.version);     // \"0.2.0\"\nconsole.log(tf.initialized); // true\n```\n\n#### `WasmTensor`\nCore tensor operations.\n\n```javascript\n// Creation\nconst a = WasmTensor.new([1, 2, 3, 4], [2, 2]);\nconst b = WasmTensor.zeros([3, 3]);\nconst c = WasmTensor.ones([2, 4]);\nconst d = WasmTensor.randn([5, 5]);\n\n// Operations\nconst sum = a.add(b);\nconst prod = a.matmul(b);\nconst transposed = a.transpose();\n\n// Activations\nconst relu_out = a.relu();\nconst gelu_out = a.gelu();\nconst softmax_out = a.softmax(-1);\n```\n\n#### `Linear`\nFully connected layer.\n\n```javascript\nconst linear = new Linear(input_size, output_size, use_bias);\nconst output = linear.forward(input_tensor);\n```\n\n#### `BertModelWasm`\nBERT model running entirely in WASM.\n\n```javascript\nconst config = BertConfig.tiny();\nconst model = new BertModelWasm(config);\nconst output = model.forward(input_ids, attention_mask);\n```\n\n### WebGPU Backend\n\n```javascript\nimport { is_webgpu_available, GpuTensorFactory } from './pkg-web/trustformers_wasm.js';\n\n// Check whether the browser exposes navigator.gpu at all\nconsole.log('WebGPU available:', is_webgpu_available());\n\n// create_tensor() tries WebGPU first and falls back to CPU automatically\n// (see \"WebGPU Notes\" below for current dispatch-path coverage)\nconst a = await GpuTensorFactory.create_tensor([1, 2, 3, 4], [2, 2]);\nconst b = await GpuTensorFactory.create_tensor([1, 1, 1, 1], [2, 2]);\nconst sum = await a.add(b);\nconsole.log('Result:', sum.data, 'backend:', sum.backend_info());\n```\n\n### Framework Bindings\n\n#### React\n\n```jsx\nimport { useTrustformers, TrustformersProvider } from 'trustformers-react';\n\nfunction App() {\n    const { model, generate, isLoading } = useTrustformers('bert-base');\n    return (\n        <TrustformersProvider>\n            <InferenceComponent model={model} onGenerate={generate} />\n        </TrustformersProvider>\n    );\n}\n```\n\n#### Vue\n\n```javascript\nimport { useTrustformers } from 'trustformers-vue';\n\nexport default {\n    setup() {\n        const { model, tokenizer, generate } = useTrustformers('bert-base');\n        return { model, generate };\n    }\n}\n```\n\n#### Angular\n\n```typescript\nimport { TrustformersService } from 'trustformers-angular';\n\n@Injectable({ providedIn: 'root' })\nexport class AppComponent {\n    constructor(private tf: TrustformersService) {}\n\n    async generate(prompt: string) {\n        return this.tf.generate(prompt).pipe(toArray()).toPromise();\n    }\n}\n```\n\n#### Web Components\n\n```html\n<trustformers-inference-engine model=\"bert-base\"></trustformers-inference-engine>\n<trustformers-model-loader src=\"./models/bert.bin\"></trustformers-model-loader>\n<trustformers-performance-monitor></trustformers-performance-monitor>\n```\n\n### Utilities\n\n```javascript\n// Performance measurement\nconst timer = new Timer(\"My Operation\");\n// ... do work ...\nconsole.log(`Elapsed: ${timer.elapsed()}ms`);\n\n// Memory statistics\nconst stats = get_memory_stats();\nconsole.log(`Memory used: ${stats.used_mb} MB`);\n\n// Feature detection\nconsole.log(`SIMD enabled: ${enable_simd()}`);\nconsole.log(`Features: ${features()}`);\n```\n\n## Feature Flags\n\n- `webgpu` — WebGPU compute backend via direct `web-sys`/`js-sys` bindings to the browser API (no `wgpu` crate dependency); gates `compute::webgpu`, `compute::gpu_tensor`, `compute::webgpu_simple`\n- `web-workers` — Web Workers-based multi-threaded execution (`src/compute/web_workers.rs`)\n- `shared-memory` — SharedArrayBuffer-backed cross-thread shared memory (`src/compute/threads.rs`)\n- `kernel-fusion` — Fused transformer kernel patterns (MHA, FFN, LayerNorm+Residual, RMSNorm, SwiGLU) in `compute/webgpu/kernel_fusion.rs` + `advanced_fusion_patterns.rs`; note these modules currently compile whenever `webgpu` is enabled, so this flag is not yet an independent source-level gate\n- `async-executor` — Async task executor for WebGPU dispatch (`compute/webgpu/async_executor.rs`); like `kernel-fusion`, currently compiles under `webgpu` regardless of this flag\n- `indexeddb` — IndexedDB model/KV-cache persistence; also gates the top-level `storage` module itself, so `memory64`/`streaming-loader`/`model-splitting` below need this enabled too\n- `memory64` — WASM memory64 addressing for models >4GB (`src/storage/memory64.rs`)\n- `streaming-loader` — Progressive chunked model loading (`src/storage/streaming_loader.rs`, `progressive_loader.rs`)\n- `model-splitting` — Splits large models into chunks for loading (`src/storage/model_splitting.rs`)\n- `react-components` — React hooks and component library (`src/react_components.rs`)\n- `vue-components` — Vue composables and plugin (`src/vue_components.rs`)\n- `angular-components` — Angular services and directives (`src/angular_components.rs`)\n- `web-components` — Framework-agnostic custom elements (`src/web_components/`)\n- `playground` — Interactive browser playground (`src/playground.rs`)\n- `streaming-generation` — Token-by-token streaming inference (`src/streaming_generation.rs`)\n- `mobile-optimization` — Battery/network-adaptive loading, touch gestures, camera integration, device-capability detection (`src/mobile.rs`, `touch_gestures.rs`, `camera_integration.rs`, `device_capability*`)\n- `console_panic` — Routes Rust panics to the browser console via `console_error_panic_hook` (part of `default`)\n- `dlmalloc-alloc` — Swaps the global allocator to `dlmalloc` (`src/allocator.rs`) for wasm32 (part of `default`)\n- `default` — `console_panic` + `dlmalloc-alloc`\n- `size-optimized` — Same composition as `default` today (`dlmalloc-alloc` + `console_panic`)\n- `performance-optimized` — `dlmalloc-alloc` + `kernel-fusion` + `async-executor`; does **not** include `webgpu` itself, so the fusion/executor code (gated behind `webgpu` at the module level) won't actually compile in unless `webgpu` is enabled too\n- `minimal` — Smallest viable build: `dlmalloc-alloc` only\n- `full` — Enables every additive feature except `webgpu` and `console_panic` (web-workers, shared-memory, kernel-fusion, async-executor, indexeddb, memory64, streaming-loader, model-splitting, react-components, vue-components, angular-components, web-components, playground, streaming-generation, mobile-optimization, dlmalloc-alloc); combine with `--features full,webgpu` for GPU support too\n\n## WebGPU Notes\n\nThis crate has **no dependency on the native `wgpu` crate**. WebGPU support is implemented by calling the browser's WebGPU API directly through hand-written `web-sys`/`js-sys` bindings:\n\n- **Types**: `GpuAdapter`, `GpuDevice`, `GpuQueue`, etc. are `js_sys::Object` aliases (`src/compute/webgpu/types.rs`), with extension traits (`GpuDeviceExt`, `GpuAdapterExt`, `GpuQueueExt`, `GpuBufferExt`) that use JS reflection for methods web-sys doesn't bind natively.\n- **Device negotiation**: `navigator.gpu` → `requestAdapter()` → `requestDevice()`, each awaited via `wasm_bindgen_futures::JsFuture` with explicit null/undefined checks (`GpuTensor::init_webgpu` in `src/compute/gpu_tensor.rs`; `WebGPUOps::initialize` in `src/compute/webgpu_simple.rs`).\n- **Shared backend handle**: the negotiated backend is wrapped in `Rc<RefCell<WebGPUBackend>>` (`src/compute/gpu_tensor.rs`) for cheap sharing across derived tensors plus interior mutability for pipeline caching; `RefCell` borrows are scoped so none is ever held across an `.await`.\n- **CPU fallback is real** at multiple levels: `WebGPUBackend::is_available()` probes for `navigator.gpu` before attempting GPU init; `GpuTensorFactory::create_tensor` falls back silently on any initialization error; per-op methods on `GpuTensor` (`matmul`/`add`/`relu`) route to CPU tensor math whenever no GPU backend is active.\n- **Two dispatch paths of different completeness** coexist — know which one you're using:\n  - `WebGPUOps` (`src/compute/webgpu_simple.rs`) is fully wired end-to-end: it compiles 7 real WGSL compute shaders (matmul, add, relu, sigmoid, tanh, gelu, softmax), builds storage buffers/bind groups/command encoders, dispatches compute passes, and reads results back via a staging buffer + `map_async`/`getMappedRange`.\n  - `WebGPUBackend`/`SimpleGpuOps` (`src/compute/webgpu/backend.rs`, `simple_ops.rs`) — the path behind the `Rc<RefCell>`-wrapped `GpuTensor` — allocate real GPU buffers and pipelines, but their dispatch methods (`dispatch_add`/`dispatch_relu`/`dispatch_matmul`, and `SimpleGpuOps::matmul`/`softmax`/`layer_norm`/`attention`) currently execute the CPU fallback path by explicit documented design; GPU dispatch for these ops isn't wired in yet.\n  - **Recommendation**: use `WebGPUOps` directly if you need guaranteed end-to-end GPU execution today; `GpuTensor` is convenient but currently CPU-backed for most ops even when a GPU device was successfully acquired.\n\n## Examples\n\nSee the `examples/` directory for complete examples:\n\n- `index.html` / `playground.html` — Interactive browser demo\n- `demo/` — Full-featured playground application\n- Node.js example in `examples/`\n\n## Performance Tips\n\n1. **Enable WebGPU**: Use Chrome 113+ / Edge 113+ for 50-100x speedup\n2. **Enable SIMD**: Compile with WASM SIMD128 target feature\n3. **Batch operations**: Process multiple inputs together\n4. **Use IndexedDB caching**: Avoid re-downloading models between sessions\n5. **Enable kernel fusion**: `webgpu` + `kernel-fusion` features\n6. **Reuse tensors**: Minimize allocations in hot loops\n\n## Testing\n\nThis crate has two distinct test layers:\n\n- **Rust unit tests** — in-source tests use plain `#[test]` attributes (163 occurrences across 39 files; 0 `#[wasm_bindgen_test]`, despite `wasm-bindgen-test` being a dev-dependency), so they compile and run as ordinary host-target Rust tests; no browser or `wasm-pack` runner is required for this layer.\n- **Browser/E2E tests** — a separate JS-driven suite under `tests/*.js` (Playwright + Jest: cross-browser, e2e, performance, visual-regression, memory-leak checks), run via `npm test` / `npx playwright test` from `tests/package.json`, independent of the Rust test binary.\n\n```bash\n# Run the Rust unit tests (host target)\ncargo test\ncargo nextest run\n\n# Run with specific features\ncargo test --features webgpu\n\n# Check that the actual wasm32 build compiles\ncargo check --target wasm32-unknown-unknown\n\n# Run the browser/E2E JS suite\ncd tests && npm test               # Jest-based suite\ncd tests && npx playwright test    # Playwright cross-browser/e2e suite\n```\n\n~130 unit tests with 100% pass rate for this crate, covering:\n- Core tensor operations\n- WebGPU backend (mock device)\n- BERT forward pass\n- Framework binding contracts\n- Streaming generation\n- IndexedDB model cache\n\nWorkspace-wide (`cargo nextest run --workspace --all-features`, 2026-07-01): 18,102 passed / 0 failed / 119 skipped; 0 clippy warnings; 0 rustdoc warnings.\n\n## Limitations\n\n- WebGPU requires Chrome 113+, Edge 113+, or Safari (experimental)\n- SharedArrayBuffer requires cross-origin isolation headers\n- SIMD requires WASM SIMD128 browser support\n- Memory typically capped at 2-4GB (use `memory64` + quantization for large models)\n- `WebGPUBackend`/`SimpleGpuOps` (the dispatch path behind `GpuTensor`) currently execute the CPU fallback for matmul/add/relu/softmax/layer_norm/attention by documented design — use `WebGPUOps` (`compute::webgpu_simple`) directly for guaranteed end-to-end GPU dispatch today (see \"WebGPU Notes\")\n- 0 `todo!()`/`unimplemented!()` macros in source, but several documented simplifications remain (none block compilation or panic): a no-op cache-clear recovery action (`src/error.rs`), fixed-bytes-per-element quantization stats (`src/optimization/quantization/quantizer.rs`), hardcoded device-capability probes (`src/device_capability/detector.rs`), fixed-constant (non-bit-width-aware) basic quantization math (`src/optimization/quantization/algorithms/basic.rs`), synthesized `blob:`/`data:` URLs in place of `URL.createObjectURL()` (`src/storage/model_splitting.rs`, `src/compute/threads.rs`), and default (non-queried) device capabilities (`src/compute/webgpu/mod.rs`)\n\n## License\n\nApache-2.0\n","readmeFilename":"README.md"}