spear-kernels 1.7.0 → 1.8.0
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/README.md +2 -2
- package/index.cjs +23 -23
- package/index.js +23 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -42,5 +42,5 @@ instance.exports.spear(2); // same protected-division semantics as the JS backen
|
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
Division is **protected** exactly like the engine: denominators floored at
|
|
45
|
-
|
|
46
|
-
these rails
|
|
45
|
+
±1e-4 (sign-preserving), results clamped to ±1e4. Discovered formulas rely on
|
|
46
|
+
these rails — do not swap in bare `/`.
|
package/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Auto-generated by scripts/gen-kernels-package.ts
|
|
1
|
+
// Auto-generated by scripts/gen-kernels-package.ts — DO NOT EDIT.
|
|
2
2
|
'use strict';
|
|
3
3
|
const kernels = {
|
|
4
4
|
"silu": {
|
|
@@ -29,11 +29,11 @@ const kernels = {
|
|
|
29
29
|
"gelu": {
|
|
30
30
|
id: "gelu",
|
|
31
31
|
precise: {
|
|
32
|
-
js: "((x) => (
|
|
33
|
-
eval: ((x) => (
|
|
34
|
-
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.
|
|
35
|
-
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.
|
|
36
|
-
wasmBase64: "
|
|
32
|
+
js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); })",
|
|
33
|
+
eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); }),
|
|
34
|
+
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.5f * x) * (1f + erff((x * 0.707107f))));\n}",
|
|
35
|
+
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.5 * x) * (1 + torch.erf((x * 0.707107))))",
|
|
36
|
+
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQopAScARAAAAAAAAOA/IACiRAAAAAAAAPA/IABEzDt/Zp6g5j+iEACgogs=",
|
|
37
37
|
},
|
|
38
38
|
fast: {
|
|
39
39
|
js: "((x) => Math.max(0, x))",
|
|
@@ -43,11 +43,11 @@ const kernels = {
|
|
|
43
43
|
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AwIBAAcJAQVzcGVhcgAAChABDgAgAEQAAAAAAAAAAKUL",
|
|
44
44
|
},
|
|
45
45
|
meta: {
|
|
46
|
-
metric:
|
|
46
|
+
metric: 1.5455587803707568e-34,
|
|
47
47
|
level: 5,
|
|
48
|
-
formulaCost:
|
|
48
|
+
formulaCost: 5,
|
|
49
49
|
exactCost: 46,
|
|
50
|
-
speedupVsExact:
|
|
50
|
+
speedupVsExact: 9.2,
|
|
51
51
|
vsIterative: null,
|
|
52
52
|
},
|
|
53
53
|
},
|
|
@@ -919,25 +919,25 @@ const kernels = {
|
|
|
919
919
|
"erf_prob": {
|
|
920
920
|
id: "erf_prob",
|
|
921
921
|
precise: {
|
|
922
|
-
js: "((x) =>
|
|
923
|
-
eval: ((x) =>
|
|
924
|
-
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return (
|
|
925
|
-
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return
|
|
926
|
-
wasmBase64: "
|
|
922
|
+
js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
|
|
923
|
+
eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
|
|
924
|
+
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
|
|
925
|
+
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
|
|
926
|
+
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
|
|
927
927
|
},
|
|
928
928
|
fast: {
|
|
929
|
-
js: "((x) => Math.
|
|
930
|
-
eval: ((x) => Math.
|
|
931
|
-
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return
|
|
932
|
-
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.
|
|
933
|
-
wasmBase64: "
|
|
929
|
+
js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
|
|
930
|
+
eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
|
|
931
|
+
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
|
|
932
|
+
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
|
|
933
|
+
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
|
|
934
934
|
},
|
|
935
935
|
meta: {
|
|
936
|
-
metric: 0
|
|
937
|
-
level:
|
|
938
|
-
formulaCost:
|
|
936
|
+
metric: 0,
|
|
937
|
+
level: 5,
|
|
938
|
+
formulaCost: 1,
|
|
939
939
|
exactCost: 26,
|
|
940
|
-
speedupVsExact:
|
|
940
|
+
speedupVsExact: 26,
|
|
941
941
|
vsIterative: null,
|
|
942
942
|
},
|
|
943
943
|
},
|
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Auto-generated by scripts/gen-kernels-package.ts
|
|
1
|
+
// Auto-generated by scripts/gen-kernels-package.ts — DO NOT EDIT.
|
|
2
2
|
// Self-contained runtime: the arrow functions below ARE the kernels.
|
|
3
3
|
export const kernels = {
|
|
4
4
|
"silu": {
|
|
@@ -29,11 +29,11 @@ export const kernels = {
|
|
|
29
29
|
"gelu": {
|
|
30
30
|
id: "gelu",
|
|
31
31
|
precise: {
|
|
32
|
-
js: "((x) => (
|
|
33
|
-
eval: ((x) => (
|
|
34
|
-
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.
|
|
35
|
-
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.
|
|
36
|
-
wasmBase64: "
|
|
32
|
+
js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); })",
|
|
33
|
+
eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return ((0.5 * x) * (1 + __erf((x * 0.7071067811865475)))); }),
|
|
34
|
+
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return ((0.5f * x) * (1f + erff((x * 0.707107f))));\n}",
|
|
35
|
+
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return ((0.5 * x) * (1 + torch.erf((x * 0.707107))))",
|
|
36
|
+
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQopAScARAAAAAAAAOA/IACiRAAAAAAAAPA/IABEzDt/Zp6g5j+iEACgogs=",
|
|
37
37
|
},
|
|
38
38
|
fast: {
|
|
39
39
|
js: "((x) => Math.max(0, x))",
|
|
@@ -43,11 +43,11 @@ export const kernels = {
|
|
|
43
43
|
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AwIBAAcJAQVzcGVhcgAAChABDgAgAEQAAAAAAAAAAKUL",
|
|
44
44
|
},
|
|
45
45
|
meta: {
|
|
46
|
-
metric:
|
|
46
|
+
metric: 1.5455587803707568e-34,
|
|
47
47
|
level: 5,
|
|
48
|
-
formulaCost:
|
|
48
|
+
formulaCost: 5,
|
|
49
49
|
exactCost: 46,
|
|
50
|
-
speedupVsExact:
|
|
50
|
+
speedupVsExact: 9.2,
|
|
51
51
|
vsIterative: null,
|
|
52
52
|
},
|
|
53
53
|
},
|
|
@@ -919,25 +919,25 @@ export const kernels = {
|
|
|
919
919
|
"erf_prob": {
|
|
920
920
|
id: "erf_prob",
|
|
921
921
|
precise: {
|
|
922
|
-
js: "((x) =>
|
|
923
|
-
eval: ((x) =>
|
|
924
|
-
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return (
|
|
925
|
-
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return
|
|
926
|
-
wasmBase64: "
|
|
922
|
+
js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
|
|
923
|
+
eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
|
|
924
|
+
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
|
|
925
|
+
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
|
|
926
|
+
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
|
|
927
927
|
},
|
|
928
928
|
fast: {
|
|
929
|
-
js: "((x) => Math.
|
|
930
|
-
eval: ((x) => Math.
|
|
931
|
-
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return
|
|
932
|
-
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.
|
|
933
|
-
wasmBase64: "
|
|
929
|
+
js: "((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); })",
|
|
930
|
+
eval: ((x) => { const __erf = (x) => { const s = x < 0 ? -1 : 1; const ax = Math.abs(x); const t = 1 / (1 + 0.3275911 * ax); return s * (1 - ((((1.061405429 * t - 1.453152027) * t + 1.421413741) * t - 0.284496736) * t + 0.254829592) * t * Math.exp(-ax * ax)); }; return __erf(x); }),
|
|
931
|
+
c: "// Evolved by SPEAR — algebraic only, FP16 safe\n__device__ inline float spear_fn(const float x) {\n return erff(x);\n}",
|
|
932
|
+
py: "import torch\n\ndef spear_fn(x):\n # Evolved by SPEAR — zero transcendental ops (exp/erf/tanh free)\n return torch.erf(x)",
|
|
933
|
+
wasmBase64: "AGFzbQEAAAABCwJgAXwBfGABfAF8AgsBA2VudgNlcmYAAQMCAQAHCQEFc3BlYXIAAQoIAQYAIAAQAAs=",
|
|
934
934
|
},
|
|
935
935
|
meta: {
|
|
936
|
-
metric: 0
|
|
937
|
-
level:
|
|
938
|
-
formulaCost:
|
|
936
|
+
metric: 0,
|
|
937
|
+
level: 5,
|
|
938
|
+
formulaCost: 1,
|
|
939
939
|
exactCost: 26,
|
|
940
|
-
speedupVsExact:
|
|
940
|
+
speedupVsExact: 26,
|
|
941
941
|
vsIterative: null,
|
|
942
942
|
},
|
|
943
943
|
},
|
package/package.json
CHANGED