tapewasm 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -11,3 +11,30 @@ export {
11
11
  sharedMemory,
12
12
  } from "./pkg/tapewasm.js";
13
13
  export { default } from "./pkg/tapewasm.js";
14
+
15
+ /** What `"auto"` uses: right for SpiderMonkey and JavaScriptCore. */
16
+ export const RE_ROLL_ABOVE: number;
17
+ /** For an engine that prefers straight-line, as V8 does. */
18
+ export const V8_RE_ROLL_ABOVE: number;
19
+
20
+ export interface Calibration {
21
+ /** Threshold to pass to `compileTape`. */
22
+ above: number;
23
+ /** False when the measurement could not run; `above` is the built-in value. */
24
+ measured: boolean;
25
+ prefersStraight?: boolean;
26
+ straightMs?: number;
27
+ loopedMs?: number;
28
+ error?: string;
29
+ }
30
+
31
+ /**
32
+ * Measure which shape this engine prefers and return a threshold for
33
+ * `compileTape`'s `reroll` argument. Call after `init()`. Cached; pass
34
+ * `{ force: true }` to measure again. Never throws — on failure it returns
35
+ * the built-in threshold.
36
+ */
37
+ export function calibrateReroll(options?: { force?: boolean; rounds?: number }): Promise<number>;
38
+
39
+ /** What the last `calibrateReroll` measured, or `null` before the first call. */
40
+ export function lastCalibration(): Calibration | null;
package/index.js CHANGED
@@ -14,4 +14,5 @@ export {
14
14
  clearAotExports,
15
15
  sharedMemory,
16
16
  } from "./pkg/tapewasm.js";
17
+ export { calibrateReroll, lastCalibration, RE_ROLL_ABOVE, V8_RE_ROLL_ABOVE } from "./calibrate.js";
17
18
  export default init;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tapewasm",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Compile an autodiff tape to a WebAssembly module and sample it with nuts-rs, in the browser.",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/pkg/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "tapewasm",
3
3
  "type": "module",
4
4
  "description": "Compile an autodiff tape to a wasm module and sample it with nuts-rs, in the browser. The wasm-bindgen API over tapewasm-codegen.",
5
- "version": "0.3.0",
5
+ "version": "0.3.1",
6
6
  "license": "MIT OR Apache-2.0",
7
7
  "repository": {
8
8
  "type": "git",
package/pkg/tapewasm.d.ts CHANGED
@@ -69,6 +69,10 @@ export class AotSampler {
69
69
  advi(init: Float64Array, num_iters: number, mc_samples: number, learning_rate: number, seed: bigint, snapshot_every: number, on_snapshot?: ((iter: number, mu: Float64Array, elbo: Float64Array) => void) | null): AdviResult;
70
70
  /**
71
71
  * `[log_prob, d/dparam...]`.
72
+ *
73
+ * The evaluator behind it is built on the first call and reused, so
74
+ * calling this in a row costs one `scratch_init` copy rather than one per
75
+ * call — the same evaluator `sample` and `advi` keep for a whole run.
72
76
  */
73
77
  logProbGrad(params: Float64Array): Float64Array;
74
78
  /**
@@ -173,11 +177,17 @@ export function clearAotExports(): void;
173
177
  * is written and consumed inside one call.
174
178
  *
175
179
  * `reroll` says when a vectorised statement becomes a wasm loop: `"auto"`
176
- * (the default, straight-line below a size threshold), `"always"` or
177
- * `"never"`. Which is faster is an engine's preference, not the model's —
178
- * on one real model straight-line was faster on V8 and slower on
179
- * SpiderMonkey and JavaScriptCore — and `"always"` is also the smallest
180
- * module, often by an order of magnitude.
180
+ * (the default, straight-line below a size threshold), `"always"`, `"never"`,
181
+ * or a node count to re-roll past, written as a number.
182
+ *
183
+ * **Which is faster is an engine's preference, not the model's.** Measured
184
+ * across three engines, straight-line and re-rolled cross over between 8,026
185
+ * and 24,564 nodes in V8 and around 2,000 in SpiderMonkey and JavaScriptCore
186
+ * — an order of magnitude apart, so no single threshold serves all three. `"auto"` takes the
187
+ * lower one: near-optimal for two of the three, and up to 7.6x off on V8 for
188
+ * a trace between them. A caller that knows its engine passes the number.
189
+ *
190
+ * `"always"` is also the smallest module, often by an order of magnitude.
181
191
  */
182
192
  export function compileTape(tape: string, reroll?: string | null): CompiledTape;
183
193
 
package/pkg/tapewasm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  /* @ts-self-types="./tapewasm.d.ts" */
2
- import { aot_logp } from './snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js';
3
- import * as import1 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
4
- import * as import2 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
5
- import * as import3 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
6
- import * as import4 from "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js"
2
+ import { aot_logp } from './snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js';
3
+ import * as import1 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
4
+ import * as import2 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
5
+ import * as import3 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
6
+ import * as import4 from "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js"
7
7
 
8
8
 
9
9
  /**
@@ -146,6 +146,10 @@ export class AotSampler {
146
146
  }
147
147
  /**
148
148
  * `[log_prob, d/dparam...]`.
149
+ *
150
+ * The evaluator behind it is built on the first call and reused, so
151
+ * calling this in a row costs one `scratch_init` copy rather than one per
152
+ * call — the same evaluator `sample` and `advi` keep for a whole run.
149
153
  * @param {Float64Array} params
150
154
  * @returns {Float64Array}
151
155
  */
@@ -417,11 +421,17 @@ export function clearAotExports() {
417
421
  * is written and consumed inside one call.
418
422
  *
419
423
  * `reroll` says when a vectorised statement becomes a wasm loop: `"auto"`
420
- * (the default, straight-line below a size threshold), `"always"` or
421
- * `"never"`. Which is faster is an engine's preference, not the model's —
422
- * on one real model straight-line was faster on V8 and slower on
423
- * SpiderMonkey and JavaScriptCore — and `"always"` is also the smallest
424
- * module, often by an order of magnitude.
424
+ * (the default, straight-line below a size threshold), `"always"`, `"never"`,
425
+ * or a node count to re-roll past, written as a number.
426
+ *
427
+ * **Which is faster is an engine's preference, not the model's.** Measured
428
+ * across three engines, straight-line and re-rolled cross over between 8,026
429
+ * and 24,564 nodes in V8 and around 2,000 in SpiderMonkey and JavaScriptCore
430
+ * — an order of magnitude apart, so no single threshold serves all three. `"auto"` takes the
431
+ * lower one: near-optimal for two of the three, and up to 7.6x off on V8 for
432
+ * a trace between them. A caller that knows its engine passes the number.
433
+ *
434
+ * `"always"` is also the smallest module, often by an order of magnitude.
425
435
  * @param {string} tape
426
436
  * @param {string | null} [reroll]
427
437
  * @returns {CompiledTape}
@@ -514,11 +524,11 @@ function __wbg_get_imports() {
514
524
  __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
515
525
  throw new Error(getStringFromWasm0(arg0, arg1));
516
526
  },
517
- __wbg_aot_logp_73e1e4a75800334a: function(arg0, arg1, arg2, arg3) {
527
+ __wbg_aot_logp_88e25d7a78bf7680: function(arg0, arg1, arg2, arg3) {
518
528
  const ret = aot_logp(arg0 >>> 0, arg1 >>> 0, arg2 >>> 0, arg3 >>> 0);
519
529
  return ret;
520
530
  },
521
- __wbg_call_5c65f3296b077120: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
531
+ __wbg_call_d9fe056b59ca67cb: function() { return handleError(function (arg0, arg1, arg2, arg3, arg4, arg5, arg6) {
522
532
  var v0 = getArrayF64FromWasm0(arg3, arg4).slice();
523
533
  wasm.__wbindgen_free(arg3, arg4 * 8, 8);
524
534
  var v1 = getArrayF64FromWasm0(arg5, arg6).slice();
@@ -561,10 +571,10 @@ function __wbg_get_imports() {
561
571
  return {
562
572
  __proto__: null,
563
573
  "./tapewasm_bg.js": import0,
564
- "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import1,
565
- "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import2,
566
- "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import3,
567
- "./snippets/tapewasm-6c5813ce65cccbcf/js/aot_bridge.js": import4,
574
+ "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import1,
575
+ "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import2,
576
+ "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import3,
577
+ "./snippets/tapewasm-cbf82a3d7bc31b1b/js/aot_bridge.js": import4,
568
578
  };
569
579
  }
570
580
 
Binary file