@genai-fi/nanogpt 0.6.3 → 0.7.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/dist/Generator.js +17 -13
- package/dist/NanoGPTModel.d.ts +2 -2
- package/dist/NanoGPTModel.js +104 -136
- package/dist/{RealDiv-BYViZwhN.js → RealDiv-CVYNbZxu.js} +30 -29
- package/dist/{Reshape-t7Kcikjk.js → Reshape-CEsEp0AI.js} +5 -5
- package/dist/Reshape-Do18N3gO.js +30 -0
- package/dist/TeachableLLM.js +9 -5
- package/dist/{TiedEmbedding-9WeDwvjO.js → TiedEmbedding-ccLBFiZi.js} +4 -4
- package/dist/{axis_util-Bu4h7XWV.js → axis_util-5DTW2tFV.js} +3 -3
- package/dist/backend.d.ts +1 -0
- package/dist/backend.js +7 -0
- package/dist/backend_util-C9Ut8n0Q.js +749 -0
- package/dist/{broadcast_to-DARN-DBD.js → broadcast_to-Ba9h_8DO.js} +2 -2
- package/dist/{concat-5aPGqw3Z.js → concat-CbXTetof.js} +8 -8
- package/dist/{dataset-pgqp-YfL.js → dataset-U3PrjwgU.js} +7 -7
- package/dist/{dropout-Bciw46HT.js → dropout-DPfPgWWe.js} +8 -8
- package/dist/{gather-DjyCjmOD.js → gather-Bbh8DHhM.js} +1 -1
- package/dist/gelu-BFwVnd1r.js +26 -0
- package/dist/gpgpu_math-DffelNS-.js +2371 -0
- package/dist/index-DYD_yPa-.js +12076 -0
- package/dist/{index-BAzbokzv.js → index-UdZhlibC.js} +414 -398
- package/dist/{kernel_funcs_utils-CUxJCg0g.js → kernel_funcs_utils-CXDy3EN7.js} +31 -30
- package/dist/layers/BaseLayer.js +2 -2
- package/dist/layers/CausalSelfAttention.js +8 -8
- package/dist/layers/MLP.js +5 -5
- package/dist/layers/RMSNorm.js +3 -3
- package/dist/layers/RoPECache.js +4 -4
- package/dist/layers/TiedEmbedding.js +5 -5
- package/dist/layers/TransformerBlock.js +1 -1
- package/dist/loader/loadTransformers.js +1 -1
- package/dist/loader/oldZipLoad.js +11 -7
- package/dist/{log_sum_exp-YEo2h3gb.js → log_sum_exp-BnmCkHWl.js} +16 -16
- package/dist/main.d.ts +13 -0
- package/dist/main.js +44 -23
- package/dist/{mat_mul-7121rsJk.js → mat_mul-dwmZz69e.js} +4 -4
- package/dist/{max-DtlIuVeW.js → max-ByjEGoFx.js} +3 -3
- package/dist/{mulmat_packed_gpu-D4nKF7Je.js → mulmat_packed_gpu-IGPBp6h9.js} +1 -1
- package/dist/non_max_suppression_impl-CsEgBuMA.js +134 -0
- package/dist/{ones-BBlSRqn1.js → ones-C8Mfln6-.js} +2 -2
- package/dist/ops/adamAdjust.d.ts +2 -0
- package/dist/ops/adamAdjust.js +9 -0
- package/dist/ops/adamMoments.d.ts +2 -0
- package/dist/ops/adamMoments.js +9 -0
- package/dist/ops/appendCache.js +3 -3
- package/dist/ops/attentionMask.js +1 -1
- package/dist/ops/cpu/adamAdjust.d.ts +1 -0
- package/dist/ops/cpu/adamAdjust.js +18 -0
- package/dist/ops/cpu/adamMoments.d.ts +1 -0
- package/dist/ops/cpu/adamMoments.js +16 -0
- package/dist/ops/cpu/appendCache.js +8 -8
- package/dist/ops/cpu/attentionMask.js +9 -9
- package/dist/ops/cpu/fusedSoftmax.js +17 -11
- package/dist/ops/cpu/gatherSub.js +7 -7
- package/dist/ops/cpu/gelu.js +13 -13
- package/dist/ops/cpu/matMulGelu.js +36 -24
- package/dist/ops/cpu/matMulMul.js +14 -8
- package/dist/ops/cpu/mulDropout.js +9 -3
- package/dist/ops/cpu/normRMS.js +5 -5
- package/dist/ops/cpu/qkv.js +3 -3
- package/dist/ops/cpu/rope.js +5 -5
- package/dist/ops/cpu/scatterSub.js +11 -11
- package/dist/ops/fusedSoftmax.js +1 -1
- package/dist/ops/gatherSub.js +1 -1
- package/dist/ops/gelu.js +2 -2
- package/dist/ops/grads/attentionMask.js +1 -1
- package/dist/ops/grads/fusedSoftmax.js +2 -2
- package/dist/ops/grads/gelu.js +3 -24
- package/dist/ops/grads/matMulGelu.js +5 -5
- package/dist/ops/grads/normRMS.js +6 -6
- package/dist/ops/grads/qkv.js +1 -1
- package/dist/ops/grads/rope.js +3 -3
- package/dist/ops/matMulGelu.js +1 -1
- package/dist/ops/matMulMul.js +1 -1
- package/dist/ops/mulDrop.js +1 -1
- package/dist/ops/normRMS.js +1 -1
- package/dist/ops/qkv.js +1 -1
- package/dist/ops/rope.js +4 -4
- package/dist/ops/scatterSub.js +1 -1
- package/dist/ops/webgl/adamAdjust.d.ts +1 -0
- package/dist/ops/webgl/adamAdjust.js +50 -0
- package/dist/ops/webgl/adamMoments.d.ts +1 -0
- package/dist/ops/webgl/adamMoments.js +38 -0
- package/dist/ops/webgl/appendCache.js +1 -1
- package/dist/ops/webgl/attentionMask.js +1 -1
- package/dist/ops/webgl/fusedSoftmax.js +4 -4
- package/dist/ops/webgl/gatherSub.js +8 -8
- package/dist/ops/webgl/gelu.js +2 -2
- package/dist/ops/webgl/log.js +5 -5
- package/dist/ops/webgl/matMulGelu.js +17 -17
- package/dist/ops/webgl/matMulMul.js +1 -1
- package/dist/ops/webgl/mulDropout.js +4 -4
- package/dist/ops/webgl/normRMS.js +2 -2
- package/dist/ops/webgl/qkv.js +1 -1
- package/dist/ops/webgl/rope.js +1 -1
- package/dist/ops/webgl/scatterSub.js +1 -1
- package/dist/ops/webgpu/adamAdjust.d.ts +1 -0
- package/dist/ops/webgpu/adamAdjust.js +52 -0
- package/dist/ops/webgpu/adamMoments.d.ts +1 -0
- package/dist/ops/webgpu/adamMoments.js +51 -0
- package/dist/ops/webgpu/appendCache.d.ts +1 -0
- package/dist/ops/webgpu/appendCache.js +57 -0
- package/dist/ops/webgpu/attentionMask.d.ts +1 -0
- package/dist/ops/webgpu/attentionMask.js +65 -0
- package/dist/ops/webgpu/gatherSub.d.ts +1 -0
- package/dist/ops/webgpu/gatherSub.js +52 -0
- package/dist/ops/webgpu/gelu.d.ts +14 -0
- package/dist/ops/webgpu/gelu.js +87 -0
- package/dist/ops/webgpu/index.d.ts +0 -0
- package/dist/ops/webgpu/index.js +11 -0
- package/dist/ops/webgpu/normRMS.d.ts +1 -0
- package/dist/ops/webgpu/normRMS.js +41 -0
- package/dist/ops/webgpu/normRMSGrad.d.ts +1 -0
- package/dist/ops/webgpu/normRMSGrad.js +128 -0
- package/dist/ops/webgpu/qkv.d.ts +1 -0
- package/dist/ops/webgpu/qkv.js +57 -0
- package/dist/ops/webgpu/rope.d.ts +1 -0
- package/dist/ops/webgpu/rope.js +69 -0
- package/dist/ops/webgpu/scatterSub.d.ts +1 -0
- package/dist/ops/webgpu/scatterSub.js +38 -0
- package/dist/ops/webgpu/utils/reductions.d.ts +9 -0
- package/dist/ops/webgpu/utils/reductions.js +68 -0
- package/dist/{ops-C0sQEcPw.js → ops-aRTXR2Sr.js} +433 -508
- package/dist/{random_width-DWzaOgrn.js → random_width-DbSpgl4o.js} +144 -144
- package/dist/{range-DYsrnfiy.js → range-D9CZhVlR.js} +1 -1
- package/dist/{reciprocal-CJQeasVa.js → reciprocal-CGB48wZB.js} +1 -1
- package/dist/{register_all_kernels-BfFCQAqs.js → register_all_kernels-DnbAyBXt.js} +203 -200
- package/dist/{reshape-krWGKraP.js → reshape-BR0eoLYN.js} +1 -1
- package/dist/{scatter_nd_util-93ln7Hut.js → scatter_nd_util-OjyAxku2.js} +3 -3
- package/dist/{selu_util-sntGesxr.js → selu_util-Ce6pu9IM.js} +44 -44
- package/dist/{shared-Ca6iDobD.js → shared-Czipaeb6.js} +541 -606
- package/dist/shared-DS5waSIY.js +69 -0
- package/dist/{sin-D_h-qCSx.js → sin-CiBxrDqX.js} +1 -1
- package/dist/slice-BHbDHObE.js +28 -0
- package/dist/{softmax-fsdtf6JC.js → softmax-JMEIUo2J.js} +1 -1
- package/dist/{split-eiktj-6L.js → split-CRU0PjVV.js} +4 -4
- package/dist/{stack-dfEEz2OY.js → stack-ikk2Y8_P.js} +2 -2
- package/dist/{sum-BE_Irnim.js → sum-NLYbiDag.js} +3 -3
- package/dist/{tensor-Xyi595sG.js → tensor-Do9PKbIE.js} +1 -1
- package/dist/{tensor2d-CPEkynbH.js → tensor2d-CWHxHpLh.js} +1 -1
- package/dist/training/Adam.d.ts +22 -0
- package/dist/training/Adam.js +93 -0
- package/dist/training/AdamExt.d.ts +1 -1
- package/dist/training/AdamExt.js +13 -12
- package/dist/training/DatasetBuilder.js +2 -2
- package/dist/training/Evaluator.js +1 -1
- package/dist/training/FullTrainer.js +27 -27
- package/dist/training/Trainer.d.ts +5 -6
- package/dist/training/Trainer.js +54 -55
- package/dist/training/sparseCrossEntropy.d.ts +0 -4
- package/dist/training/sparseCrossEntropy.js +7 -7
- package/dist/utilities/arrayClose.d.ts +1 -0
- package/dist/utilities/arrayClose.js +11 -0
- package/dist/utilities/dummy.js +19 -19
- package/dist/utilities/generate.js +15 -16
- package/dist/utilities/multinomialCPU.d.ts +2 -0
- package/dist/utilities/multinomialCPU.js +13 -0
- package/dist/utilities/performance.d.ts +2 -0
- package/dist/utilities/performance.js +16 -0
- package/dist/utilities/profile.d.ts +1 -0
- package/dist/utilities/profile.js +9 -6
- package/dist/utilities/safetensors.js +2 -2
- package/dist/utilities/weights.js +2 -2
- package/dist/{variable-wSS22xj5.js → variable-BTBkayv_.js} +1 -1
- package/dist/webgpu_program-WaoMq-WD.js +548 -0
- package/dist/webgpu_util-DhSeP4b6.js +80 -0
- package/dist/{zeros-YJDE7oRb.js → zeros-DnPT2nD4.js} +10 -10
- package/package.json +2 -1
- package/dist/gpgpu_math-CNslybmD.js +0 -3115
- package/dist/norm-CzltS9Fz.js +0 -86
|
@@ -0,0 +1,548 @@
|
|
|
1
|
+
import { aa as k, ab as z, ac as E, a1 as j, l as A } from "./index-UdZhlibC.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
function L(e, s) {
|
|
19
|
+
if (Math.max(...e) > 5)
|
|
20
|
+
throw new Error("Cannot symbolically compute strides for rank > 6 tensor.");
|
|
21
|
+
const t = e.length, o = "xyzwuv", i = e.map((n) => `${s}.${o[n]}`), u = new Array(t - 1);
|
|
22
|
+
u[t - 2] = i[t - 1];
|
|
23
|
+
for (let n = t - 3; n >= 0; --n)
|
|
24
|
+
u[n] = `(${u[n + 1]} * ${i[n + 1]})`;
|
|
25
|
+
return u;
|
|
26
|
+
}
|
|
27
|
+
const X = (e, s, t) => t === "int32" ? `atomicAdd(${e}, bitcast<i32>(${s}));` : `
|
|
28
|
+
{
|
|
29
|
+
var oldValue = 0;
|
|
30
|
+
loop {
|
|
31
|
+
let newValueF32 = bitcast<f32>(oldValue) + (${s});
|
|
32
|
+
let newValue = bitcast<i32>(newValueF32);
|
|
33
|
+
let res = atomicCompareExchangeWeak(${e}, oldValue, newValue);
|
|
34
|
+
if res.exchanged {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
oldValue = res.old_value;
|
|
38
|
+
}
|
|
39
|
+
}`;
|
|
40
|
+
/**
|
|
41
|
+
* @license
|
|
42
|
+
* Copyright 2022 Google LLC. All Rights Reserved.
|
|
43
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
44
|
+
* you may not use this file except in compliance with the License.
|
|
45
|
+
* You may obtain a copy of the License at
|
|
46
|
+
*
|
|
47
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
48
|
+
*
|
|
49
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
50
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
51
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
52
|
+
* See the License for the specific language governing permissions and
|
|
53
|
+
* limitations under the License.
|
|
54
|
+
* =============================================================================
|
|
55
|
+
*/
|
|
56
|
+
var b;
|
|
57
|
+
(function(e) {
|
|
58
|
+
e[e.FROM_PIXELS = 0] = "FROM_PIXELS", e[e.DRAW = 1] = "DRAW";
|
|
59
|
+
})(b || (b = {}));
|
|
60
|
+
const H = (e, s, t, o, i) => {
|
|
61
|
+
const u = { dtype: o.dtype, shape: o.shape }, n = D(t, u, s), r = e.createShaderModule({ code: n, label: s.constructor.name });
|
|
62
|
+
let d = E().get("WEBGPU_PRINT_SHADER");
|
|
63
|
+
if (d !== "") {
|
|
64
|
+
d = d.toLowerCase();
|
|
65
|
+
const p = d.split(",");
|
|
66
|
+
(d === "all" || p.some((a) => s.shaderKey.toLowerCase().includes(a))) && (console.group(s.shaderKey), console.debug(n), console.groupEnd());
|
|
67
|
+
}
|
|
68
|
+
return i ? e.createComputePipelineAsync({
|
|
69
|
+
compute: { module: r, entryPoint: "_start" },
|
|
70
|
+
label: s.constructor.name,
|
|
71
|
+
layout: "auto"
|
|
72
|
+
}) : e.createComputePipeline({
|
|
73
|
+
compute: { module: r, entryPoint: "_start" },
|
|
74
|
+
label: s.constructor.name,
|
|
75
|
+
layout: "auto"
|
|
76
|
+
});
|
|
77
|
+
}, f = (e, s = "f32") => {
|
|
78
|
+
switch (e) {
|
|
79
|
+
case 1:
|
|
80
|
+
return `${s}`;
|
|
81
|
+
case 2:
|
|
82
|
+
return `vec2<${s}>`;
|
|
83
|
+
case 3:
|
|
84
|
+
return `vec3<${s}>`;
|
|
85
|
+
case 4:
|
|
86
|
+
return `vec4<${s}>`;
|
|
87
|
+
default:
|
|
88
|
+
throw new Error(`${e}-component ${s} is not supported.`);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function v(e) {
|
|
92
|
+
if (e <= 1)
|
|
93
|
+
return "i32";
|
|
94
|
+
if (e === 2)
|
|
95
|
+
return "vec2<i32>";
|
|
96
|
+
if (e === 3)
|
|
97
|
+
return "vec3<i32>";
|
|
98
|
+
if (e === 4)
|
|
99
|
+
return "vec4<i32>";
|
|
100
|
+
if (e === 5)
|
|
101
|
+
return "vec5";
|
|
102
|
+
if (e === 6)
|
|
103
|
+
return "vec6";
|
|
104
|
+
throw Error(`GPU for rank ${e} is not yet supported`);
|
|
105
|
+
}
|
|
106
|
+
function I(e) {
|
|
107
|
+
if (e === 0)
|
|
108
|
+
return "x";
|
|
109
|
+
if (e === 1)
|
|
110
|
+
return "y";
|
|
111
|
+
if (e === 2)
|
|
112
|
+
return "z";
|
|
113
|
+
if (e === 3)
|
|
114
|
+
return "w";
|
|
115
|
+
if (e === 4)
|
|
116
|
+
return "u";
|
|
117
|
+
if (e === 5)
|
|
118
|
+
return "v";
|
|
119
|
+
throw Error(`Index ${e} is not yet supported`);
|
|
120
|
+
}
|
|
121
|
+
function Y(...e) {
|
|
122
|
+
let s;
|
|
123
|
+
switch (e.length) {
|
|
124
|
+
case 0:
|
|
125
|
+
s = `
|
|
126
|
+
fn main()
|
|
127
|
+
`;
|
|
128
|
+
break;
|
|
129
|
+
case 1:
|
|
130
|
+
s = `
|
|
131
|
+
fn main(${e[0]} : i32)
|
|
132
|
+
`;
|
|
133
|
+
break;
|
|
134
|
+
default:
|
|
135
|
+
throw Error("Unreachable");
|
|
136
|
+
}
|
|
137
|
+
return s;
|
|
138
|
+
}
|
|
139
|
+
function w(e, s) {
|
|
140
|
+
let t;
|
|
141
|
+
return t = `
|
|
142
|
+
${N(s)}
|
|
143
|
+
fn _start(@builtin(local_invocation_id) LocalId : vec3<u32>,
|
|
144
|
+
@builtin(global_invocation_id) GlobalId : vec3<u32>,
|
|
145
|
+
@builtin(local_invocation_index) LocalIndex: u32,
|
|
146
|
+
@builtin(workgroup_id) WorkgroupId : vec3<u32>,
|
|
147
|
+
@builtin(num_workgroups) NumWorkgroups : vec3<u32>) {
|
|
148
|
+
localId = LocalId;
|
|
149
|
+
localIndex = LocalIndex;
|
|
150
|
+
globalId = GlobalId;
|
|
151
|
+
numWorkgroups = NumWorkgroups;
|
|
152
|
+
workgroupId = WorkgroupId;
|
|
153
|
+
${e ? "main(getGlobalIndex());" : "main();"};
|
|
154
|
+
}
|
|
155
|
+
`, t;
|
|
156
|
+
}
|
|
157
|
+
function N(e) {
|
|
158
|
+
return `
|
|
159
|
+
@compute @workgroup_size(${e.workgroupSize[0]}, ${e.workgroupSize[1]}, ${e.workgroupSize[2]})
|
|
160
|
+
`;
|
|
161
|
+
}
|
|
162
|
+
function D(e, s, t) {
|
|
163
|
+
const o = [], i = t.workgroupSize[0] * t.workgroupSize[1] * t.workgroupSize[2];
|
|
164
|
+
if (t.outputComponent = t.outputComponent ? t.outputComponent : 1, o.push(`
|
|
165
|
+
|
|
166
|
+
var<private> localId: vec3<u32>;
|
|
167
|
+
var<private> localIndex: u32;
|
|
168
|
+
var<private> globalId: vec3<u32>;
|
|
169
|
+
var<private> numWorkgroups: vec3<u32>;
|
|
170
|
+
var<private> workgroupId: vec3<u32>;
|
|
171
|
+
|
|
172
|
+
// Only used when the y/z dimension of workgroup size is 1.
|
|
173
|
+
fn getGlobalIndex() -> i32 {
|
|
174
|
+
${F(t) ? " return i32(globalId.x);" : ` return i32((workgroupId.z * numWorkgroups.x * numWorkgroups.y +
|
|
175
|
+
workgroupId.y * numWorkgroups.x + workgroupId.x) * ${i}u +
|
|
176
|
+
localIndex);
|
|
177
|
+
`}
|
|
178
|
+
}
|
|
179
|
+
`), t.pixelsOpType != null) {
|
|
180
|
+
const h = t.pixelsOpType === b.FROM_PIXELS ? `@group(0) @binding(0) var<storage, read_write> result: array<${x(s.dtype, t.outputComponent)}>;` : `@group(0) @binding(1) var<storage, read> inBuf : array<${x(e[0].dtype, t.outputComponent)}>;`, c = s.shape.length === 3 ? "vec2<i32>" : "i32";
|
|
181
|
+
o.push(`
|
|
182
|
+
struct Uniform {
|
|
183
|
+
outShapeStrides : ${c},
|
|
184
|
+
size : i32,
|
|
185
|
+
numChannels : i32,
|
|
186
|
+
alpha : f32,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
${h}
|
|
190
|
+
@group(0) @binding(2) var<uniform> uniforms: Uniform;
|
|
191
|
+
`);
|
|
192
|
+
const S = m(t);
|
|
193
|
+
return [
|
|
194
|
+
C,
|
|
195
|
+
o.join(`
|
|
196
|
+
`),
|
|
197
|
+
y(s.shape),
|
|
198
|
+
t.getUserCode(),
|
|
199
|
+
w(S, t)
|
|
200
|
+
].join(`
|
|
201
|
+
`);
|
|
202
|
+
}
|
|
203
|
+
let u, n, r = "struct Uniforms { NAN : f32, INFINITY : f32, ";
|
|
204
|
+
t.variableNames.forEach((h, c) => {
|
|
205
|
+
const S = v(e[c].shape.length);
|
|
206
|
+
r += `${h.charAt(0).toLowerCase() + h.slice(1)}Shape : ${S}, `, u = e[c].shape.length - 1, n = v(u), r += `${h.charAt(0).toLowerCase() + h.slice(1)}ShapeStrides: ${n}, `;
|
|
207
|
+
});
|
|
208
|
+
const d = v(s.shape.length);
|
|
209
|
+
r += `outShape : ${d}, `, u = s.shape.length - 1, n = v(u), r += `
|
|
210
|
+
outShapeStrides: ${n}, `, t.size && (r += "size : i32, "), t.uniforms && (r += t.uniforms), r += "};", r = B(r), o.push(r), t.atomic ? o.push(`
|
|
211
|
+
@group(0) @binding(0) var<storage, read_write> result: array<atomic<i32>>;
|
|
212
|
+
`) : o.push(`
|
|
213
|
+
@group(0) @binding(0) var<storage, read_write> result: array<${x(s.dtype, t.outputComponent)}>;
|
|
214
|
+
`), t.variableNames.forEach((h, c) => {
|
|
215
|
+
o.push(`
|
|
216
|
+
@group(0) @binding(${1 + c}) var<storage, read> ${h}: array<${t.variableComponents ? x(e[c].dtype, t.variableComponents[c]) : x(e[c].dtype, t.outputComponent)}>;
|
|
217
|
+
`);
|
|
218
|
+
}), r !== "" && o.push(`
|
|
219
|
+
@group(0) @binding(${1 + t.variableNames.length}) var<uniform> uniforms: Uniforms;
|
|
220
|
+
`);
|
|
221
|
+
const p = R(s.shape, t.dispatchLayout), a = [
|
|
222
|
+
C,
|
|
223
|
+
o.join(`
|
|
224
|
+
`) + T,
|
|
225
|
+
y(s.shape),
|
|
226
|
+
p,
|
|
227
|
+
G(s.shape.length)
|
|
228
|
+
];
|
|
229
|
+
t.atomic || a.push(V(s.shape, s.dtype, t.outputComponent)), t.variableNames.forEach((h, c) => {
|
|
230
|
+
a.push(`${y(e[c].shape, h)}`);
|
|
231
|
+
});
|
|
232
|
+
const g = e.map((h, c) => P(h, s.shape, t.variableComponents ? t.variableComponents[c] : t.outputComponent, t.dispatchLayout.x.length === s.shape.length)).join(`
|
|
233
|
+
`);
|
|
234
|
+
a.push(g), a.push(t.getUserCode());
|
|
235
|
+
const l = m(t);
|
|
236
|
+
return a.push(w(l, t)), a.join(`
|
|
237
|
+
`);
|
|
238
|
+
}
|
|
239
|
+
function q(e, s, t) {
|
|
240
|
+
let o = e.shaderKey;
|
|
241
|
+
if (e.pixelsOpType != null)
|
|
242
|
+
return o;
|
|
243
|
+
const i = [], u = [];
|
|
244
|
+
s.forEach((a) => {
|
|
245
|
+
i.push(a.shape), u.push(a.dtype);
|
|
246
|
+
}), i.push(t.shape), u.push(t.dtype);
|
|
247
|
+
const n = s.map((a) => k(a.shape, t.shape)), r = s.map((a) => z(a.shape, t.shape)).join("_"), d = n.map((a) => a.join("_")).join(";"), p = F(e) ? "flatDispatch" : "";
|
|
248
|
+
return o += "_" + (e.workgroupSize ? e.workgroupSize.join(",") : "") + i.map((a) => a.length).join(",") + u.join(",") + e.variableNames.join(",") + d + r + p, o;
|
|
249
|
+
}
|
|
250
|
+
const C = `
|
|
251
|
+
struct vec5 {x: i32, y: i32, z: i32, w: i32, u: i32};
|
|
252
|
+
struct vec6 {x: i32, y: i32, z: i32, w: i32, u: i32, v: i32};
|
|
253
|
+
|
|
254
|
+
// Checks whether coordinates lie within the bounds of the shape.
|
|
255
|
+
fn coordsInBounds2D(coord : vec2<i32>, shape : vec2<i32>) -> bool {
|
|
256
|
+
return all(coord >= vec2<i32>(0)) && all(coord < shape);
|
|
257
|
+
}
|
|
258
|
+
fn coordsInBounds3D(coord : vec3<i32>, shape : vec3<i32>) -> bool {
|
|
259
|
+
return all(coord >= vec3<i32>(0)) && all(coord < shape);
|
|
260
|
+
}
|
|
261
|
+
fn coordsInBounds4D(coord : vec4<i32>, shape : vec4<i32>) -> bool {
|
|
262
|
+
return all(coord >= vec4<i32>(0)) && all(coord < shape);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fn getIndexFromCoords1D(coord : i32, shape : i32) -> i32 {
|
|
266
|
+
return coord;
|
|
267
|
+
}
|
|
268
|
+
fn getIndexFromCoords2D(coords : vec2<i32>, shape : vec2<i32>) -> i32 {
|
|
269
|
+
return dot(coords, vec2<i32>(shape.y, 1));
|
|
270
|
+
}
|
|
271
|
+
fn getIndexFromCoords3D(coords : vec3<i32>, shape : vec3<i32>) -> i32 {
|
|
272
|
+
return dot(coords, vec3<i32>(shape.y * shape.z, shape.z, 1));
|
|
273
|
+
}
|
|
274
|
+
fn getIndexFromCoords4D(coords : vec4<i32>, shape : vec4<i32>) -> i32 {
|
|
275
|
+
return dot(coords, vec4<i32>(
|
|
276
|
+
shape.y * shape.z * shape.w, shape.z * shape.w, shape.w, 1));
|
|
277
|
+
}
|
|
278
|
+
fn getIndexFromCoords5D(coords : vec5, shape : vec5) -> i32 {
|
|
279
|
+
let shapeStrides: vec5 = vec5(shape.y * shape.z * shape.w * shape.u, shape.z * shape.w * shape.u, shape.w * shape.u, shape.u, 1);
|
|
280
|
+
return coords.x*shapeStrides.x + coords.y*shapeStrides.y + coords.z*shapeStrides.z + coords.w*shapeStrides.w + coords.u*shapeStrides.u;
|
|
281
|
+
}
|
|
282
|
+
fn getIndexFromCoords6D(coords : vec6, shape : vec6) -> i32 {
|
|
283
|
+
let shapeStrides: vec6 = vec6(shape.y * shape.z * shape.w * shape.u * shape.v, shape.z * shape.w * shape.u * shape.v, shape.w * shape.u * shape.v, shape.u * shape.v, shape.v, 1);
|
|
284
|
+
return coords.x*shapeStrides.x + coords.y*shapeStrides.y + coords.z*shapeStrides.z + coords.w*shapeStrides.w + coords.u*shapeStrides.u + coords.v*shapeStrides.v;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// NaN defination in IEEE 754-1985 is :
|
|
288
|
+
// - sign = either 0 or 1.
|
|
289
|
+
// - biased exponent = all 1 bits.
|
|
290
|
+
// - fraction = anything except all 0 bits (since all 0 bits represents infinity).
|
|
291
|
+
// https://en.wikipedia.org/wiki/IEEE_754-1985#Representation_of_non-numbers
|
|
292
|
+
fn isnan(val: f32) -> bool {
|
|
293
|
+
let floatToUint: u32 = bitcast<u32>(val);
|
|
294
|
+
return (floatToUint & 0x7fffffffu) > 0x7f800000u;
|
|
295
|
+
}
|
|
296
|
+
fn isnanVec4(val : vec4<f32>) -> vec4<bool> {
|
|
297
|
+
let floatToUint: vec4<u32> = bitcast<vec4<u32>>(val);
|
|
298
|
+
return (floatToUint & vec4<u32>(0x7fffffffu)) > vec4<u32>(0x7f800000u);
|
|
299
|
+
}
|
|
300
|
+
`, T = `
|
|
301
|
+
fn isinf(val: f32) -> bool {
|
|
302
|
+
return abs(val) == uniforms.INFINITY;
|
|
303
|
+
}
|
|
304
|
+
`;
|
|
305
|
+
function y(e, s = "") {
|
|
306
|
+
const t = e.length, o = s !== "" ? `get${s.charAt(0).toUpperCase() + s.slice(1)}CoordsFromIndex` : "getCoordsFromIndex", i = s !== "" ? `${s.charAt(0).toLowerCase() + s.slice(1)}ShapeStrides` : "outShapeStrides";
|
|
307
|
+
if (t <= 1)
|
|
308
|
+
return `fn ${o}(index : i32) -> i32 { return index; }`;
|
|
309
|
+
const u = j(e), n = v(t), r = [];
|
|
310
|
+
for (let p = 0; p < t; p++)
|
|
311
|
+
r.push(`d${p}`);
|
|
312
|
+
if (u.length === 1)
|
|
313
|
+
return ` fn ${o}(index : i32) -> vec2<i32> {
|
|
314
|
+
let d0 = index / uniforms.${i}; let d1 = index - d0 * uniforms.${i};
|
|
315
|
+
return vec2<i32>(d0, d1);
|
|
316
|
+
}`;
|
|
317
|
+
let d;
|
|
318
|
+
return d = "var index2 = index;" + u.map((p, a) => {
|
|
319
|
+
const g = `let ${r[a]} = index2 / uniforms.${i}.${I(a)}`, l = a === u.length - 1 ? `let ${r[a + 1]} = index2 - ${r[a]} * uniforms.${i}.${I(a)}` : `index2 = index2 - ${r[a]} * uniforms.${i}.${I(a)}`;
|
|
320
|
+
return `${g}; ${l};`;
|
|
321
|
+
}).join(""), `
|
|
322
|
+
fn ${o}(index : i32) -> ${n} {
|
|
323
|
+
${d}
|
|
324
|
+
return ${n}(${r.join(",")});
|
|
325
|
+
}
|
|
326
|
+
`;
|
|
327
|
+
}
|
|
328
|
+
function U(e, s) {
|
|
329
|
+
const t = e.name, o = e.shape.length, i = v(o), u = "get" + t.charAt(0).toUpperCase() + t.slice(1), n = ["d0", "d1", "d2", "d3", "d4", "d5"].slice(0, o), r = n.map((a) => `${a} : i32`).join(", ");
|
|
330
|
+
if (o < 1)
|
|
331
|
+
return `
|
|
332
|
+
fn ${u}() -> ${f(s)} {
|
|
333
|
+
return ${f(s)}(${t}[0]);
|
|
334
|
+
}
|
|
335
|
+
`;
|
|
336
|
+
const d = `uniforms.${t.charAt(0).toLowerCase() + t.slice(1)}Shape`;
|
|
337
|
+
let p = `${o}D`;
|
|
338
|
+
return o === 0 && (p = "1D"), `
|
|
339
|
+
fn ${u}(${r}) -> ${f(s)} {
|
|
340
|
+
return ${f(s)}(${t}[getIndexFromCoords${p}(${i}(${n.join(",")}),
|
|
341
|
+
${d})${s === 1 ? "" : ` / ${s}`}]);
|
|
342
|
+
}
|
|
343
|
+
`;
|
|
344
|
+
}
|
|
345
|
+
function W(e, s, t, o) {
|
|
346
|
+
const i = e.name, u = i.charAt(0).toUpperCase() + i.slice(1), n = "get" + u + "ByOutput", r = e.shape.length, d = s.length, p = v(d);
|
|
347
|
+
if (z(e.shape, s) && o)
|
|
348
|
+
return `
|
|
349
|
+
fn ${n}Index(globalIndex : i32) -> ${f(t)} {
|
|
350
|
+
return ${f(t)}(${i}[globalIndex]);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
fn ${n}Coords(coords : ${p}) -> ${f(t)} {
|
|
354
|
+
return ${f(t)}(${i}[${d > 1 ? "getOutputIndexFromCoords(coords)" : "coords"}${t === 1 ? "" : ` / ${t}`}]);
|
|
355
|
+
}
|
|
356
|
+
`;
|
|
357
|
+
const a = k(e.shape, s), g = d - r;
|
|
358
|
+
let l = "";
|
|
359
|
+
if (r === 0)
|
|
360
|
+
return `
|
|
361
|
+
fn ${n}Index(globalIndex : i32) -> ${f(t)}{
|
|
362
|
+
return get${u}();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
fn ${n}Coords(coords : ${p}) -> ${f(t)}{
|
|
366
|
+
return get${u}();
|
|
367
|
+
}
|
|
368
|
+
`;
|
|
369
|
+
d < 2 && a.length >= 1 ? l = "coords = 0;" : l = a.map((S) => `coords.${I(S + g)} = 0;`).join(`
|
|
370
|
+
`);
|
|
371
|
+
let $ = "";
|
|
372
|
+
if (d < 2 && r > 0)
|
|
373
|
+
$ = "coords";
|
|
374
|
+
else if (d > 1) {
|
|
375
|
+
const S = v(r), O = e.shape.map((M, _) => `coords.${I(_ + g)}`).join(", ");
|
|
376
|
+
$ = `${S}(${O})`;
|
|
377
|
+
} else
|
|
378
|
+
$ = "coords";
|
|
379
|
+
const h = `uniforms.${i.charAt(0).toLowerCase() + i.slice(1)}Shape`, c = `${r}D`;
|
|
380
|
+
return `
|
|
381
|
+
fn ${n}Index(globalIndex : i32) -> ${f(t)} {
|
|
382
|
+
var coords = getCoordsFromIndex(globalIndex);
|
|
383
|
+
${l}
|
|
384
|
+
return ${f(t)}(${i}[getIndexFromCoords${c}(${$}, ${h})${t === 1 ? "" : ` / ${t}`}]);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
fn ${n}Coords(coordsIn : ${p}) -> ${f(t)} {
|
|
388
|
+
var coords = coordsIn;
|
|
389
|
+
${l}
|
|
390
|
+
return ${f(t)}(${i}[getIndexFromCoords${c}(${$}, ${h})${t === 1 ? "" : ` / ${t}`}]);
|
|
391
|
+
}
|
|
392
|
+
`;
|
|
393
|
+
}
|
|
394
|
+
function P(e, s, t, o) {
|
|
395
|
+
let i = U(e, t);
|
|
396
|
+
return e.shape.length <= s.length && (i += W(e, s, t, o)), i;
|
|
397
|
+
}
|
|
398
|
+
function R(e, s) {
|
|
399
|
+
const { x: t, y: o = [], z: i = [] } = s, u = e.length, n = t.length + o.length + i.length;
|
|
400
|
+
if (n !== u)
|
|
401
|
+
return "";
|
|
402
|
+
if (t.length === u)
|
|
403
|
+
return `fn getOutputCoords() -> ${v(u)}{
|
|
404
|
+
let globalIndex = getGlobalIndex();
|
|
405
|
+
return getCoordsFromIndex(globalIndex);
|
|
406
|
+
}
|
|
407
|
+
`;
|
|
408
|
+
let r = "";
|
|
409
|
+
const d = [t, o, i];
|
|
410
|
+
for (let l = 0; l < d.length; l++) {
|
|
411
|
+
const $ = d[l];
|
|
412
|
+
if ($.length !== 0)
|
|
413
|
+
if ($.length === 1)
|
|
414
|
+
r += `let d${$[0]} = i32(globalId[${l}]);`;
|
|
415
|
+
else {
|
|
416
|
+
const h = L($, "uniforms.outShape");
|
|
417
|
+
r += `var index${l} = i32(globalId[${l}]);`;
|
|
418
|
+
for (let c = 0; c < h.length; c++)
|
|
419
|
+
r += `let d${$[c]} = index${l} / ${h[c]};`, c === h.length - 1 ? r += `let d${$[c + 1]} = index${l} - d${$[c]} * ${h[c]};` : r += `index${l} = index${l} - d${$[c]} * ${h[c]};`;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
const p = [];
|
|
423
|
+
for (let l = 0; l < n; l++)
|
|
424
|
+
p.push(`d${l}`);
|
|
425
|
+
const a = v(n);
|
|
426
|
+
let g = `fn getOutputCoords() -> ${a} {
|
|
427
|
+
${r}
|
|
428
|
+
`;
|
|
429
|
+
return p.length === 0 ? g += `return ${a}(0); }` : g += `return ${a}(${p.join(",")}); }`, g;
|
|
430
|
+
}
|
|
431
|
+
function G(e) {
|
|
432
|
+
let s = "";
|
|
433
|
+
switch (e) {
|
|
434
|
+
case 0:
|
|
435
|
+
case 1:
|
|
436
|
+
s += `
|
|
437
|
+
fn getOutputIndexFromCoords(coords : i32) -> i32 {
|
|
438
|
+
return coords;
|
|
439
|
+
}
|
|
440
|
+
`;
|
|
441
|
+
break;
|
|
442
|
+
case 2:
|
|
443
|
+
s += `
|
|
444
|
+
fn getOutputIndexFromCoords(coords : vec2<i32>) -> i32 {
|
|
445
|
+
return dot(coords, vec2<i32>(uniforms.outShapeStrides, 1));
|
|
446
|
+
}
|
|
447
|
+
`;
|
|
448
|
+
break;
|
|
449
|
+
case 3:
|
|
450
|
+
s += `
|
|
451
|
+
fn getOutputIndexFromCoords(coords : vec3<i32>) -> i32 {
|
|
452
|
+
return dot(coords, vec3<i32>(uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, 1));
|
|
453
|
+
}
|
|
454
|
+
`;
|
|
455
|
+
break;
|
|
456
|
+
case 4:
|
|
457
|
+
s += `
|
|
458
|
+
fn getOutputIndexFromCoords(coords : vec4<i32>) -> i32 {
|
|
459
|
+
return dot(coords, vec4<i32>(
|
|
460
|
+
uniforms.outShapeStrides.x, uniforms.outShapeStrides.y, uniforms.outShapeStrides.z, 1));
|
|
461
|
+
}
|
|
462
|
+
`;
|
|
463
|
+
break;
|
|
464
|
+
case 5:
|
|
465
|
+
s += `
|
|
466
|
+
fn getOutputIndexFromCoords(coords : vec5) -> i32 {
|
|
467
|
+
return coords.x * uniforms.outShapeStrides.x +
|
|
468
|
+
coords.y * uniforms.outShapeStrides.y +
|
|
469
|
+
coords.z * uniforms.outShapeStrides.z +
|
|
470
|
+
coords.w * uniforms.outShapeStrides.w +
|
|
471
|
+
coords.u;
|
|
472
|
+
}
|
|
473
|
+
`;
|
|
474
|
+
break;
|
|
475
|
+
case 6:
|
|
476
|
+
s += `
|
|
477
|
+
fn getOutputIndexFromCoords(coords : vec6) -> i32 {
|
|
478
|
+
return coords.x * uniforms.outShapeStrides.x +
|
|
479
|
+
coords.y * uniforms.outShapeStrides.y +
|
|
480
|
+
coords.z * uniforms.outShapeStrides.z +
|
|
481
|
+
coords.w * uniforms.outShapeStrides.w +
|
|
482
|
+
coords.u * uniforms.outShapeStrides.u +
|
|
483
|
+
coords.v;
|
|
484
|
+
}
|
|
485
|
+
`;
|
|
486
|
+
break;
|
|
487
|
+
default:
|
|
488
|
+
A(!1, () => `Unsupported ${e}D shape`);
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
return s;
|
|
492
|
+
}
|
|
493
|
+
function F(e) {
|
|
494
|
+
return e.dispatch[1] === 1 && e.dispatch[2] === 1;
|
|
495
|
+
}
|
|
496
|
+
function x(e, s = 1) {
|
|
497
|
+
if (e === "float32")
|
|
498
|
+
return f(s, "f32");
|
|
499
|
+
if (e === "int32" || e === "bool")
|
|
500
|
+
return f(s, "i32");
|
|
501
|
+
throw new Error(`type ${e} is not supported.`);
|
|
502
|
+
}
|
|
503
|
+
function V(e, s, t) {
|
|
504
|
+
const o = e.length, i = x(s, t);
|
|
505
|
+
let u = `fn setOutputAtIndex(flatIndex : i32, value : ${f(t)}) {
|
|
506
|
+
result[flatIndex] = ${i}(value);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
fn setOutputAtIndexI32(flatIndex : i32, value : ${f(t, "i32")}) {
|
|
510
|
+
result[flatIndex] = ${i}(value);
|
|
511
|
+
}
|
|
512
|
+
`;
|
|
513
|
+
if (o >= 2) {
|
|
514
|
+
const n = ["d0", "d1", "d2", "d3", "d4", "d5"].slice(0, o), r = v(o);
|
|
515
|
+
u += `
|
|
516
|
+
fn setOutputAtCoords(${n.map((d) => `${d} : i32`).join(", ")}, value : ${f(t)}) {
|
|
517
|
+
let flatIndex = getOutputIndexFromCoords(${r}(${n.join(", ")}));
|
|
518
|
+
setOutputAtIndex(flatIndex${t === 1 ? "" : ` / ${t}`}, value);
|
|
519
|
+
}
|
|
520
|
+
fn setOutputAtCoordsI32(${n.map((d) => `${d} : i32`).join(", ")}, value : ${f(t, "i32")}) {
|
|
521
|
+
let flatIndex = getOutputIndexFromCoords(${r}(${n.join(", ")}));
|
|
522
|
+
setOutputAtIndexI32(flatIndex${t === 1 ? "" : ` / ${t}`}, value);
|
|
523
|
+
}
|
|
524
|
+
`;
|
|
525
|
+
}
|
|
526
|
+
return u;
|
|
527
|
+
}
|
|
528
|
+
function B(e) {
|
|
529
|
+
const s = /(\w+)\s*:\s*vec(5|6)/g;
|
|
530
|
+
e = e.replace(s, (o) => "@align(16) " + o);
|
|
531
|
+
const t = /vec(5|6)\s*,\s*(\w+)/g;
|
|
532
|
+
return e = e.replace(t, (o, i, u) => `vec${i}, @align(16) ${u}`), e;
|
|
533
|
+
}
|
|
534
|
+
function m(e) {
|
|
535
|
+
return !(e.dispatchLayout.hasOwnProperty("y") && e.dispatchLayout.y.length !== 0 || e.dispatchLayout.hasOwnProperty("z") && e.dispatchLayout.z.length !== 0);
|
|
536
|
+
}
|
|
537
|
+
export {
|
|
538
|
+
b as P,
|
|
539
|
+
X as a,
|
|
540
|
+
v as b,
|
|
541
|
+
H as c,
|
|
542
|
+
I as d,
|
|
543
|
+
x as e,
|
|
544
|
+
y as f,
|
|
545
|
+
Y as g,
|
|
546
|
+
q as m,
|
|
547
|
+
f as t
|
|
548
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { l as u } from "./index-UdZhlibC.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2019 Google LLC. All Rights Reserved.
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
* =============================================================================
|
|
17
|
+
*/
|
|
18
|
+
const e = (r) => {
|
|
19
|
+
let t = 1;
|
|
20
|
+
for (let n = 0; n < r.length; n++)
|
|
21
|
+
t *= r[n];
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
function m(r, t, n = [1, 1, 1], a = [1, 1, 1]) {
|
|
25
|
+
const [o, i, f] = [
|
|
26
|
+
Math.ceil(e(r.x.map((c) => t[c])) / (n[0] * a[0])),
|
|
27
|
+
r.y ? Math.ceil(e(r.y.map((c) => t[c])) / (n[1] * a[1])) : 1,
|
|
28
|
+
r.z ? Math.ceil(e(r.z.map((c) => t[c])) / (n[2] * a[2])) : 1
|
|
29
|
+
];
|
|
30
|
+
return [o, i, f];
|
|
31
|
+
}
|
|
32
|
+
function d(r, t, n, a = !1) {
|
|
33
|
+
const o = [8, 8, 1], i = [4, 4, 1];
|
|
34
|
+
return a || (r <= 8 && (i[1] = 1), t <= 16 && n <= 16 && (o[0] = 4)), { workgroupSize: o, elementsPerThread: i };
|
|
35
|
+
}
|
|
36
|
+
function p(r, t, n = !1) {
|
|
37
|
+
if (n)
|
|
38
|
+
return [8, 8, 1];
|
|
39
|
+
const a = e(r.x.map((i) => t[i])), o = e(r.y.map((i) => t[i]));
|
|
40
|
+
return a <= 4 ? [4, 16, 1] : o <= 4 ? [16, 4, 1] : [16, 16, 1];
|
|
41
|
+
}
|
|
42
|
+
function M(r, t, n = !1) {
|
|
43
|
+
if (n)
|
|
44
|
+
return [4, 4, 1];
|
|
45
|
+
const a = e(r.x.map((i) => t[i])), o = e(r.y.map((i) => t[i]));
|
|
46
|
+
return a <= 4 ? [1, 2, 1] : o <= 4 ? [2, 1, 1] : [2, 2, 1];
|
|
47
|
+
}
|
|
48
|
+
function h(r) {
|
|
49
|
+
return { x: r.map((t, n) => n) };
|
|
50
|
+
}
|
|
51
|
+
function x(r) {
|
|
52
|
+
if (r === "float32" || r === "int32" || r === "bool" || r === "string")
|
|
53
|
+
return 4;
|
|
54
|
+
if (r === "complex64")
|
|
55
|
+
return 8;
|
|
56
|
+
throw new Error(`Unknown dtype ${r}`);
|
|
57
|
+
}
|
|
58
|
+
function g() {
|
|
59
|
+
return !!(typeof globalThis < "u" && globalThis.navigator && globalThis.navigator.gpu);
|
|
60
|
+
}
|
|
61
|
+
function b(r, t) {
|
|
62
|
+
Array.isArray(r) || (r = [r]), r.forEach((n) => {
|
|
63
|
+
n != null && u(n.dtype !== "complex64", () => `${t} does not support complex64 tensors in the WebGPU backend.`);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
var s;
|
|
67
|
+
(function(r) {
|
|
68
|
+
r[r.MatMulReduceProgram = 0] = "MatMulReduceProgram", r[r.MatMulSplitKProgram = 1] = "MatMulSplitKProgram", r[r.MatMulSmallOutputSizeProgram = 2] = "MatMulSmallOutputSizeProgram", r[r.MatMulPackedProgram = 3] = "MatMulPackedProgram", r[r.MatMulMax = 4] = "MatMulMax";
|
|
69
|
+
})(s || (s = {}));
|
|
70
|
+
export {
|
|
71
|
+
x as G,
|
|
72
|
+
s as M,
|
|
73
|
+
d as a,
|
|
74
|
+
b,
|
|
75
|
+
m as c,
|
|
76
|
+
p as d,
|
|
77
|
+
M as e,
|
|
78
|
+
h as f,
|
|
79
|
+
g as i
|
|
80
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as m, C as r, a5 as l, E as c, a6 as i, F as p, a7 as u, j as f } from "./index-UdZhlibC.js";
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2020 Google LLC. All Rights Reserved.
|
|
@@ -15,13 +15,13 @@ import { o as m, q as r, Z as l, E as c, _ as i, x as p, $ as u, g as x } from "
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
* =============================================================================
|
|
17
17
|
*/
|
|
18
|
-
function
|
|
19
|
-
const
|
|
20
|
-
l(
|
|
21
|
-
const n = { real:
|
|
18
|
+
function x(a, e) {
|
|
19
|
+
const s = r(a, "real", "complex"), o = r(e, "imag", "complex");
|
|
20
|
+
l(s.shape, o.shape, `real and imag shapes, ${s.shape} and ${o.shape}, must match in call to tf.complex().`);
|
|
21
|
+
const n = { real: s, imag: o };
|
|
22
22
|
return c.runKernel(i, n);
|
|
23
23
|
}
|
|
24
|
-
const g = /* @__PURE__ */ m({ complex_:
|
|
24
|
+
const g = /* @__PURE__ */ m({ complex_: x });
|
|
25
25
|
/**
|
|
26
26
|
* @license
|
|
27
27
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -40,11 +40,11 @@ const g = /* @__PURE__ */ m({ complex_: f });
|
|
|
40
40
|
*/
|
|
41
41
|
function t(a, e = "float32") {
|
|
42
42
|
if (p(a), e === "complex64") {
|
|
43
|
-
const
|
|
44
|
-
return g(
|
|
43
|
+
const o = t(a, "float32"), n = t(a, "float32");
|
|
44
|
+
return g(o, n);
|
|
45
45
|
}
|
|
46
|
-
const
|
|
47
|
-
return c.makeTensor(
|
|
46
|
+
const s = u(f(a), e);
|
|
47
|
+
return c.makeTensor(s, a, e);
|
|
48
48
|
}
|
|
49
49
|
export {
|
|
50
50
|
g as c,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genai-fi/nanogpt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"types": "dist/main.d.ts",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@dsnp/parquetjs": "^1.8.7",
|
|
52
52
|
"@tensorflow/tfjs": "^4.22.0",
|
|
53
|
+
"@tensorflow/tfjs-backend-webgpu": "^4.22.0",
|
|
53
54
|
"eventemitter3": "^5.0.1",
|
|
54
55
|
"jszip": "^3.10.1",
|
|
55
56
|
"papaparse": "^5.5.3",
|