@genai-fi/nanogpt 1.1.0 → 1.1.2
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/TeachableLLM.d.ts +1 -0
- package/dist/TeachableLLM.js +17 -8
- package/dist/api/responses.d.ts +1 -0
- package/dist/api/responses.js +3 -0
- package/dist/backend.js +1 -1
- package/dist/{dist-9wGF4ci9.js → dist-BGVm64AY.js} +224 -224
- package/dist/ops/webgpu/adamAdjust.js +4 -4
- package/dist/ops/webgpu/adamMoments.js +4 -4
- package/dist/ops/webgpu/appendCache.js +10 -10
- package/dist/ops/webgpu/attentionMask32_program.js +6 -6
- package/dist/ops/webgpu/concat16.js +4 -4
- package/dist/ops/webgpu/dropout16.js +4 -4
- package/dist/ops/webgpu/gatherSub.js +4 -4
- package/dist/ops/webgpu/gelu.js +8 -8
- package/dist/ops/webgpu/normRMSGrad.js +6 -6
- package/dist/ops/webgpu/pack16_program.js +18 -18
- package/dist/ops/webgpu/rope.js +12 -12
- package/dist/ops/webgpu/scatterSub.js +4 -4
- package/dist/ops/webgpu/slice16.js +7 -7
- package/dist/ops/webgpu/softmax16_program.js +5 -5
- package/dist/ops/webgpu/softmax16_subgroup_program.js +10 -10
- package/dist/ops/webgpu/transpose16_program.js +15 -15
- package/dist/ops/webgpu/transpose16_shared_program.js +14 -14
- package/dist/ops/webgpu/unpack16.js +4 -4
- package/dist/ops/webgpu/utils/binary_op.js +10 -10
- package/dist/ops/webgpu/utils/reductions.js +6 -6
- package/dist/patches/webgpu_backend.js +8 -8
- package/dist/patches/webgpu_base.d.ts +1 -0
- package/dist/patches/webgpu_base.js +20 -14
- package/dist/training/BasicTrainer.js +5 -1
- package/dist/{webgpu-B19Tw8Nd.js → webgpu-IAn9VotJ.js} +8 -8
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as e, i as t } from "../../webgpu_util-DfODg6XI.js";
|
|
2
|
+
import { i as n, o as r, s as i } from "../../webgpu_program-B0PokuRJ.js";
|
|
3
3
|
//#region lib/ops/webgpu/transpose16_program.ts
|
|
4
4
|
function a(e) {
|
|
5
|
-
let
|
|
6
|
-
if (
|
|
7
|
-
let
|
|
8
|
-
for (let
|
|
9
|
-
return
|
|
5
|
+
let t = e.length;
|
|
6
|
+
if (t > 6) throw Error(`Transpose for rank ${t} is not yet supported`);
|
|
7
|
+
let n = Array(t);
|
|
8
|
+
for (let t = 0; t < e.length; t++) n[e[t]] = `coords.${r(t)}`;
|
|
9
|
+
return n.join();
|
|
10
10
|
}
|
|
11
11
|
var o = class {
|
|
12
12
|
variableNames = ["A"];
|
|
@@ -22,25 +22,25 @@ var o = class {
|
|
|
22
22
|
];
|
|
23
23
|
newDim;
|
|
24
24
|
size = !0;
|
|
25
|
-
constructor(
|
|
26
|
-
let
|
|
27
|
-
for (let
|
|
28
|
-
this.outputShape =
|
|
25
|
+
constructor(n, r) {
|
|
26
|
+
let i = Array(n.length);
|
|
27
|
+
for (let e = 0; e < i.length; e++) i[e] = n[r[e]];
|
|
28
|
+
this.outputShape = i, this.dispatchLayout = e(this.outputShape), this.dispatch = t(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
29
29
|
this.workPerThread,
|
|
30
30
|
1,
|
|
31
31
|
1
|
|
32
|
-
]), this.newDim =
|
|
32
|
+
]), this.newDim = r, this.shaderKey = `transpose16_${r}`;
|
|
33
33
|
}
|
|
34
34
|
getUserCode() {
|
|
35
|
-
let
|
|
35
|
+
let e = n(this.outputShape.length), t = a(this.newDim);
|
|
36
36
|
return `
|
|
37
|
-
${
|
|
37
|
+
${i("index")} {
|
|
38
38
|
for(var i = 0; i < ${this.workPerThread}; i = i + 1) {
|
|
39
39
|
let flatIndex = index * ${this.workPerThread} + i;
|
|
40
40
|
if(flatIndex < uniforms.size) {
|
|
41
41
|
let coords = getCoordsFromIndex(flatIndex);
|
|
42
42
|
result[flatIndex] = A[getIndexFromCoords${this.outputShape.length}D(
|
|
43
|
-
${
|
|
43
|
+
${e}(${t}), uniforms.aShape)];
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ps as e } from "../../dist-Da20xy8E.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { i as t } from "../../webgpu_util-DfODg6XI.js";
|
|
3
|
+
import { s as n } from "../../webgpu_program-B0PokuRJ.js";
|
|
4
4
|
//#region lib/ops/webgpu/transpose16_shared_program.ts
|
|
5
5
|
var r = class {
|
|
6
6
|
variableNames = ["A"];
|
|
@@ -13,10 +13,10 @@ var r = class {
|
|
|
13
13
|
8,
|
|
14
14
|
1
|
|
15
15
|
];
|
|
16
|
-
constructor(e,
|
|
16
|
+
constructor(e, n) {
|
|
17
17
|
let r = e.length, i = Array(r), a = e.slice();
|
|
18
18
|
a[a.length - 1] *= 2;
|
|
19
|
-
for (let e = 0; e < i.length; e++) i[e] = a[
|
|
19
|
+
for (let e = 0; e < i.length; e++) i[e] = a[n[e]];
|
|
20
20
|
i[i.length - 1] /= 2, this.outputShape = i, this.dispatchLayout = r === 2 ? {
|
|
21
21
|
x: [0],
|
|
22
22
|
y: [1]
|
|
@@ -24,27 +24,27 @@ var r = class {
|
|
|
24
24
|
x: [1],
|
|
25
25
|
y: [2],
|
|
26
26
|
z: [0]
|
|
27
|
-
}, this.dispatch =
|
|
27
|
+
}, this.dispatch = t(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
28
28
|
2,
|
|
29
29
|
1,
|
|
30
30
|
1
|
|
31
31
|
]), this.shaderKey = `transposeShared16_${r}`;
|
|
32
32
|
}
|
|
33
33
|
getUserCode() {
|
|
34
|
-
let
|
|
34
|
+
let t = this.outputShape.length;
|
|
35
35
|
e(this.workgroupSize[0] === this.workgroupSize[1], () => `Must be a square tile, current tile shape is ${this.workgroupSize[0]} x ${this.workgroupSize[1]}`);
|
|
36
36
|
let r = this.workgroupSize[0] * 2;
|
|
37
37
|
return `
|
|
38
38
|
var<workgroup> tile : array<array<f32, ${r + 1}>, ${r}>;
|
|
39
|
-
${
|
|
39
|
+
${n()} {
|
|
40
40
|
var x = i32(workgroupId.x) * ${r / 2} + i32(localId.x);
|
|
41
41
|
var y = i32(workgroupId.y) * ${r} + i32(localId.y);
|
|
42
|
-
let batch = ${
|
|
43
|
-
let batchOffsetA = ${
|
|
44
|
-
let batchOffsetOut = ${
|
|
42
|
+
let batch = ${t === 3 ? "i32(workgroupId.z)" : "0"};
|
|
43
|
+
let batchOffsetA = ${t === 3 ? "batch * uniforms.aShapeStrides[0]" : "0"};
|
|
44
|
+
let batchOffsetOut = ${t === 3 ? "batch * uniforms.outShapeStrides[0]" : "0"};
|
|
45
45
|
|
|
46
|
-
let inputWidth = uniforms.outShape[${
|
|
47
|
-
let inputHeight = uniforms.outShape[${
|
|
46
|
+
let inputWidth = uniforms.outShape[${t === 3 ? "1" : "0"}] / 2; // Output height
|
|
47
|
+
let inputHeight = uniforms.outShape[${t === 3 ? "2" : "1"}] * 2; // Output width
|
|
48
48
|
if (x < inputWidth && y < inputHeight) {
|
|
49
49
|
let unpackedA = unpack2x16float(u32(A[batchOffsetA + y * inputWidth + x]));
|
|
50
50
|
tile[localId.y][localId.x * 2] = unpackedA.x;
|
|
@@ -59,8 +59,8 @@ var r = class {
|
|
|
59
59
|
}
|
|
60
60
|
workgroupBarrier();
|
|
61
61
|
|
|
62
|
-
let outputWidth = uniforms.outShape[${
|
|
63
|
-
let outputHeight = uniforms.outShape[${
|
|
62
|
+
let outputWidth = uniforms.outShape[${t === 3 ? "2" : "1"}]; // Output width
|
|
63
|
+
let outputHeight = uniforms.outShape[${t === 3 ? "1" : "0"}] * 2; // Output height
|
|
64
64
|
x = i32(workgroupId.y) * ${r / 2} + i32(localId.x);
|
|
65
65
|
y = i32(workgroupId.x) * ${r} + i32(localId.y);
|
|
66
66
|
if (x < outputWidth && y < outputHeight) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Ii as e } from "../../dist-Da20xy8E.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { c as t, i as n } from "../../webgpu_util-DfODg6XI.js";
|
|
3
|
+
import { s as r } from "../../webgpu_program-B0PokuRJ.js";
|
|
4
4
|
//#region lib/ops/webgpu/unpack16.ts
|
|
5
5
|
var i = class {
|
|
6
6
|
outputShape;
|
|
@@ -19,7 +19,7 @@ var i = class {
|
|
|
19
19
|
variableComponents = [2];
|
|
20
20
|
scaling = !1;
|
|
21
21
|
constructor(e) {
|
|
22
|
-
this.outputShape = [...e.slice(0, -1), e[e.length - 1] * 2], this.dispatchLayout =
|
|
22
|
+
this.outputShape = [...e.slice(0, -1), e[e.length - 1] * 2], this.dispatchLayout = t(this.outputShape), this.dispatch = n(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
23
23
|
4,
|
|
24
24
|
1,
|
|
25
25
|
1
|
|
@@ -30,7 +30,7 @@ var i = class {
|
|
|
30
30
|
}
|
|
31
31
|
getUserCode() {
|
|
32
32
|
return `
|
|
33
|
-
${
|
|
33
|
+
${r("index")} {
|
|
34
34
|
let outIndex = index;
|
|
35
35
|
if (outIndex < uniforms.size) {
|
|
36
36
|
let xvec2 = x[index];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { In as e, Js as t } from "../../../dist-Da20xy8E.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { c as n, i as r } from "../../../webgpu_util-DfODg6XI.js";
|
|
3
|
+
import { s as i } from "../../../webgpu_program-B0PokuRJ.js";
|
|
4
4
|
import { n as a, t as o } from "../../../binary_op_util-CrYk9LXL.js";
|
|
5
5
|
//#region lib/ops/webgpu/utils/binary_op.ts
|
|
6
6
|
var s = class {
|
|
@@ -14,17 +14,17 @@ var s = class {
|
|
|
14
14
|
variableNames = ["A", "B"];
|
|
15
15
|
workgroupSize;
|
|
16
16
|
variableComponents;
|
|
17
|
-
constructor(
|
|
18
|
-
this.outputShape = e(a, o), this.dispatchLayout =
|
|
17
|
+
constructor(i, a, o) {
|
|
18
|
+
this.outputShape = e(a, o), this.dispatchLayout = n(this.outputShape), this.op = i;
|
|
19
19
|
let s = a.length > 0 && a[a.length - 1] % 4 == 0, c = o.length > 0 && o[o.length - 1] % 4 == 0;
|
|
20
20
|
if (s && c) this.outputComponent = 4, this.variableComponents = [4, 4];
|
|
21
21
|
else if (s && (t(o) || o[o.length - 1] === 1) || c && (t(a) || a[a.length - 1] === 1)) throw Error("Cannot broadcast 16-bit float binary ops with mixed vector sizes");
|
|
22
22
|
else throw Error("16-bit float binary ops require inner dimension to be multiple of 4");
|
|
23
|
-
this.shaderKey = `binary_${
|
|
23
|
+
this.shaderKey = `binary_${i}_${this.variableComponents}`, this.workgroupSize = [
|
|
24
24
|
128,
|
|
25
25
|
1,
|
|
26
26
|
1
|
|
27
|
-
], this.dispatch =
|
|
27
|
+
], this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
28
28
|
this.outputComponent,
|
|
29
29
|
1,
|
|
30
30
|
1
|
|
@@ -38,7 +38,7 @@ var s = class {
|
|
|
38
38
|
${a(this.op, this.outputComponent === 4)}
|
|
39
39
|
};
|
|
40
40
|
`}
|
|
41
|
-
${
|
|
41
|
+
${i("index")} {
|
|
42
42
|
if (index < uniforms.size) {
|
|
43
43
|
let a = A[index];
|
|
44
44
|
let b = B[index];
|
|
@@ -87,13 +87,13 @@ var s = class {
|
|
|
87
87
|
workgroupSize;
|
|
88
88
|
variableComponents;
|
|
89
89
|
constructor(e, t) {
|
|
90
|
-
if (this.outputShape = t, this.dispatchLayout =
|
|
90
|
+
if (this.outputShape = t, this.dispatchLayout = n(this.outputShape), this.op = e, t.length > 0 && t[t.length - 1] % 4 == 0) this.outputComponent = 4, this.variableComponents = [4, 1];
|
|
91
91
|
else throw Error("16-bit float binary ops require inner dimension to be multiple of 4");
|
|
92
92
|
this.shaderKey = `binary_scal_${e}_${this.variableComponents}`, this.workgroupSize = [
|
|
93
93
|
128,
|
|
94
94
|
1,
|
|
95
95
|
1
|
|
96
|
-
], this.dispatch =
|
|
96
|
+
], this.dispatch = r(this.dispatchLayout, this.outputShape, this.workgroupSize, [
|
|
97
97
|
this.outputComponent,
|
|
98
98
|
1,
|
|
99
99
|
1
|
|
@@ -107,7 +107,7 @@ var s = class {
|
|
|
107
107
|
${a(this.op, this.outputComponent === 4)}
|
|
108
108
|
};
|
|
109
109
|
`}
|
|
110
|
-
${
|
|
110
|
+
${i("index")} {
|
|
111
111
|
if (index < uniforms.size) {
|
|
112
112
|
let a = A[index];
|
|
113
113
|
let b = B[0];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ii as e, kt as t, nc as n, oc as r, wn as i } from "../../../dist-Da20xy8E.js";
|
|
2
2
|
import { reshape16 as a } from "../../reshape16.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { c as o } from "../../../webgpu_util-DfODg6XI.js";
|
|
4
|
+
import { s } from "../../../webgpu_program-B0PokuRJ.js";
|
|
5
5
|
//#region lib/ops/webgpu/utils/reductions.ts
|
|
6
6
|
function c(e, t, n, r) {
|
|
7
7
|
return e && !t ? "\n bestValue = subgroupAdd(bestValue);\n " : e ? `
|
|
@@ -50,7 +50,7 @@ function l(e) {
|
|
|
50
50
|
${n}
|
|
51
51
|
${e.utilityFunctions ?? ""}
|
|
52
52
|
|
|
53
|
-
${
|
|
53
|
+
${s("index")} {
|
|
54
54
|
let outputIndex = index / ${t};
|
|
55
55
|
let offset = outputIndex * uniforms.reduceSize;
|
|
56
56
|
var bestValue = 0.0f;
|
|
@@ -92,7 +92,7 @@ function u(e) {
|
|
|
92
92
|
${n}
|
|
93
93
|
${e.utilityFunctions ?? ""}
|
|
94
94
|
|
|
95
|
-
${
|
|
95
|
+
${s("index")} {
|
|
96
96
|
let outputIndex = index / ${t};
|
|
97
97
|
let offset1 = outputIndex * 2 * uniforms.reduceSize;
|
|
98
98
|
let offset2 = offset1 + uniforms.reduceSize;
|
|
@@ -139,7 +139,7 @@ function f(e) {
|
|
|
139
139
|
${n}
|
|
140
140
|
${e.utilityFunctions ?? ""}
|
|
141
141
|
|
|
142
|
-
${
|
|
142
|
+
${s("index")} {
|
|
143
143
|
let outputIndex = index / ${e.workgroupSizeX};
|
|
144
144
|
let offset = outputIndex * uniforms.reduceSize;
|
|
145
145
|
var bestValue = 0.0f;
|
|
@@ -205,7 +205,7 @@ var m = class {
|
|
|
205
205
|
Math.min(i, e.subgroupMaxSize),
|
|
206
206
|
1,
|
|
207
207
|
1
|
|
208
|
-
], this.subgroups = !0, e.variableSubgroups && (this.subgroupBuiltins = !0)) : this.workgroupSize[0] = i, this.outputShape = n.elementwise ? [t.batchSize, t.inSize] : r ? [t.outSize / 2] : [t.outSize], this.dispatchLayout =
|
|
208
|
+
], this.subgroups = !0, e.variableSubgroups && (this.subgroupBuiltins = !0)) : this.workgroupSize[0] = i, this.outputShape = n.elementwise ? [t.batchSize, t.inSize] : r ? [t.outSize / 2] : [t.outSize], this.dispatchLayout = o(this.outputShape), this.dispatch = [
|
|
209
209
|
n.elementwise ? t.batchSize : r ? t.batchSize / 2 : t.batchSize,
|
|
210
210
|
1,
|
|
211
211
|
1
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ms as e, Ps as t, Vs as n, oc as r } from "../dist-Da20xy8E.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { t as i } from "../webgpu-IAn9VotJ.js";
|
|
3
|
+
import { l as a } from "../webgpu_program-B0PokuRJ.js";
|
|
4
|
+
import { compileProgram as o } from "./webgpu_program.js";
|
|
5
5
|
//#region lib/patches/webgpu_backend.ts
|
|
6
6
|
var s = (e, n) => {
|
|
7
7
|
let r = e.limits.maxComputeWorkgroupsPerDimension, i = n.dispatchLayout, a = n.dispatch;
|
|
@@ -17,16 +17,16 @@ var s = (e, n) => {
|
|
|
17
17
|
o,
|
|
18
18
|
1
|
|
19
19
|
];
|
|
20
|
-
}, c = class extends
|
|
20
|
+
}, c = class extends i {
|
|
21
21
|
subgroupMaxSize;
|
|
22
22
|
subgroupMinSize;
|
|
23
23
|
constructor(e, t) {
|
|
24
24
|
super(e, t), this.subgroupMaxSize = t?.subgroupMaxSize ?? 0, this.subgroupMinSize = t?.subgroupMinSize ?? 0;
|
|
25
25
|
}
|
|
26
|
-
runWebGPUProgram(t,
|
|
26
|
+
runWebGPUProgram(t, i, c, l, u) {
|
|
27
27
|
if (u ||= this.makeTensorInfo(t.outputShape, c), r(u.shape) === 0) return this.tensorMap.get(u.dataId).values = n(u.dtype, 0), u;
|
|
28
28
|
this.uploadToGPU(u.dataId), t.dispatch = s(this.device, t);
|
|
29
|
-
let d =
|
|
29
|
+
let d = i.map((e, n) => {
|
|
30
30
|
if (e.dtype === "complex64") throw Error("GPGPUProgram does not support complex64 input. For complex64 dtypes, please separate the program into real and imaginary parts.");
|
|
31
31
|
return this.uploadToGPU(e.dataId), {
|
|
32
32
|
dtype: this.tensorMap.get(e.dataId).dtype,
|
|
@@ -34,9 +34,9 @@ var s = (e, n) => {
|
|
|
34
34
|
name: t.variableNames[n]
|
|
35
35
|
};
|
|
36
36
|
});
|
|
37
|
-
t.shaderKey =
|
|
37
|
+
t.shaderKey = a(t, d, u);
|
|
38
38
|
let f = e().getBool("WEBGPU_ENGINE_COMPILE_ONLY");
|
|
39
|
-
return t.shaderKey in this.pipelineCache || (this.pipelineCache[t.shaderKey] =
|
|
39
|
+
return t.shaderKey in this.pipelineCache || (this.pipelineCache[t.shaderKey] = o(this.device, t, d, u, f)), t.pipeline = this.pipelineCache[t.shaderKey], f || this.recordAndSubmit(t, u, i, l), u;
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
//#endregion
|
|
@@ -18,4 +18,5 @@ export interface GPUOptions {
|
|
|
18
18
|
powerPreference?: 'low-power' | 'high-performance';
|
|
19
19
|
disableSubgroups?: boolean;
|
|
20
20
|
}
|
|
21
|
+
export declare function getBackendDevice(): GPUDevice | undefined;
|
|
21
22
|
export declare function registerWebGPUBackend(options?: GPUOptions): void;
|
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
import { li as e } from "../dist-Da20xy8E.js";
|
|
2
2
|
import t from "./webgpu_backend.js";
|
|
3
3
|
//#region lib/patches/webgpu_base.ts
|
|
4
|
-
|
|
4
|
+
var n;
|
|
5
|
+
function r() {
|
|
6
|
+
return n;
|
|
7
|
+
}
|
|
8
|
+
function i(r) {
|
|
5
9
|
e("webgpu", async () => {
|
|
6
|
-
let e = { powerPreference:
|
|
10
|
+
let e = { powerPreference: r?.powerPreference ?? "high-performance" };
|
|
7
11
|
console.log("Using custom WebGPU backend with power preference:", e.powerPreference);
|
|
8
|
-
let
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
maxComputeWorkgroupStorageSize:
|
|
13
|
-
maxComputeWorkgroupsPerDimension:
|
|
14
|
-
maxStorageBufferBindingSize:
|
|
15
|
-
maxBufferSize:
|
|
16
|
-
maxComputeWorkgroupSizeX:
|
|
17
|
-
maxComputeInvocationsPerWorkgroup:
|
|
18
|
-
}
|
|
12
|
+
let i = await navigator.gpu.requestAdapter(e), a = {}, o = [];
|
|
13
|
+
i.features.has("timestamp-query") && o.push("timestamp-query"), i.features.has("bgra8unorm-storage") && o.push(["bgra8unorm-storage"]), !r?.disableSubgroups && i.features.has("subgroups") && o.push("subgroups"), a.requiredFeatures = o;
|
|
14
|
+
let s = i.limits;
|
|
15
|
+
a.requiredLimits = {
|
|
16
|
+
maxComputeWorkgroupStorageSize: s.maxComputeWorkgroupStorageSize,
|
|
17
|
+
maxComputeWorkgroupsPerDimension: s.maxComputeWorkgroupsPerDimension,
|
|
18
|
+
maxStorageBufferBindingSize: s.maxStorageBufferBindingSize,
|
|
19
|
+
maxBufferSize: s.maxBufferSize,
|
|
20
|
+
maxComputeWorkgroupSizeX: s.maxComputeWorkgroupSizeX,
|
|
21
|
+
maxComputeInvocationsPerWorkgroup: s.maxComputeInvocationsPerWorkgroup
|
|
22
|
+
};
|
|
23
|
+
let c = await i.requestDevice(a), l = "info" in i ? i.info : "requestAdapterInfo" in i ? await i.requestAdapterInfo() : void 0;
|
|
24
|
+
return n = c, new t(c, l);
|
|
19
25
|
}, 3);
|
|
20
26
|
}
|
|
21
27
|
//#endregion
|
|
22
|
-
export {
|
|
28
|
+
export { r as getBackendDevice, i as registerWebGPUBackend };
|
|
@@ -220,7 +220,11 @@ var p = {
|
|
|
220
220
|
let c = o * (t?.epochSteps || 1e3);
|
|
221
221
|
t.metrics && this.setMetrics(t.metrics);
|
|
222
222
|
let l = this.createEmptyState();
|
|
223
|
-
this.lastState = l,
|
|
223
|
+
if (this.lastState = l, l.step >= c) return {
|
|
224
|
+
losses: l.losses,
|
|
225
|
+
validationLosses: l.validationLosses
|
|
226
|
+
};
|
|
227
|
+
await this.dummyPass(), t?.metrics?.includes("memoryUsage") && (this.model.getProfiler() || this.model.setProfiler(new s()));
|
|
224
228
|
let d = Date.now();
|
|
225
229
|
this.running = !0, l.logStartTime = d;
|
|
226
230
|
let f = n ? new u(this.model, n, this.maskedLoss) : void 0, m = await e.iterator(), h = m.next();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Ai as e, Ms as t, Oi as n, Ps as r, Rs as i, Vs as a, Xr as o, Ys as s, fc as c, ii as l, ki as u, lc as d, oc as f, pc as p, zs as m } from "./dist-Da20xy8E.js";
|
|
2
2
|
import { s as h } from "./complex_util-CkazZsaH.js";
|
|
3
|
-
import { l as g,
|
|
4
|
-
import { l as y, t as b } from "./
|
|
3
|
+
import { l as g, t as _ } from "./webgpu_util-DfODg6XI.js";
|
|
4
|
+
import { l as v, n as y, t as b } from "./webgpu_program-B0PokuRJ.js";
|
|
5
5
|
//#region node_modules/@tensorflow/tfjs-backend-webgpu/dist/flags_webgpu.js
|
|
6
6
|
var x = t();
|
|
7
7
|
x.registerFlag("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE", () => 15), x.registerFlag("WEBGPU_CPU_FORWARD", () => !0), x.registerFlag("WEBGPU_MATMUL_PROGRAM_TYPE", () => -1), x.registerFlag("WEBGPU_USE_NAIVE_CONV2D_TRANSPOSE", () => !0), x.registerFlag("WEBGPU_USE_LOW_POWER_GPU", () => !1), x.registerFlag("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD", () => 1e3), x.registerFlag("WEBGPU_USE_PROFILE_TOOL", () => !1), x.registerFlag("WEBGPU_IMPORT_EXTERNAL_TEXTURE", () => !0), x.registerFlag("WEBGPU_USE_NAIVE_CONV2D_DEBUG", () => !1), x.registerFlag("WEBGPU_THRESHOLD_TO_INCREASE_WORKGROUPS_FOR_MATMUL", () => -1), x.registerFlag("WEBGPU_CONV_SEPARATE_IM2COL_SHADER", () => !1), x.registerFlag("WEBGPU_PRINT_SHADER", () => ""), x.registerFlag("WEBGPU_ENGINE_COMPILE_ONLY", () => !1);
|
|
@@ -141,7 +141,7 @@ var O = t().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), k = (e, t) => {
|
|
|
141
141
|
return x.nextDataId++;
|
|
142
142
|
}
|
|
143
143
|
constructor(e, n) {
|
|
144
|
-
if (super(), this.commandQueueOwnedIds = /* @__PURE__ */ new WeakSet(), this.dispatchCountInPass = 0, this.disposed = !1, this.downloadWaitMs = 0, this.tensorDataPendingDisposal = [], this.queryResolveBuffer = null, this.querySet = null, this.querySetCount = 2, this.stagingPendingDisposal = [], this.uniformPendingDisposal = [], this.uploadWaitMs = 0, this.hasReadSyncWarned = !1, this.hasTimestampQueryWarned = !1, !
|
|
144
|
+
if (super(), this.commandQueueOwnedIds = /* @__PURE__ */ new WeakSet(), this.dispatchCountInPass = 0, this.disposed = !1, this.downloadWaitMs = 0, this.tensorDataPendingDisposal = [], this.queryResolveBuffer = null, this.querySet = null, this.querySetCount = 2, this.stagingPendingDisposal = [], this.uniformPendingDisposal = [], this.uploadWaitMs = 0, this.hasReadSyncWarned = !1, this.hasTimestampQueryWarned = !1, !g()) throw Error("WebGPU is not supported on this device");
|
|
145
145
|
this.pipelineCache = {}, this.device = e, this.queue = e.queue, this.commandEncoder = null, this.computePassEncoder = null, this.adapterInfo = new S(n), this.supportTimestampQuery = this.device.features.has("timestamp-query"), this.thresholdToIncreaseWorkgroups = this.adapterInfo.intelGPUGeneration >= 12 ? 16 : 8, this.bufferManager = new C(this.device), this.textureManager = new T(this.device), this.tensorMap = new c(this, l()), t().getBool("WEBGPU_USE_PROFILE_TOOL") && (this.dummyCanvas = document.createElement("canvas"), this.dummyCanvas.width = 1, this.dummyCanvas.height = 1, this.dummyContext = this.dummyCanvas.getContext("webgpu"), this.dummyContext.configure({
|
|
146
146
|
device: e,
|
|
147
147
|
format: "bgra8unorm"
|
|
@@ -308,7 +308,7 @@ var O = t().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), k = (e, t) => {
|
|
|
308
308
|
refCount: 1,
|
|
309
309
|
external: e.zeroCopy
|
|
310
310
|
});
|
|
311
|
-
let a = this.tensorMap.get(i), o =
|
|
311
|
+
let a = this.tensorMap.get(i), o = _(a.dtype) * f(a.shape);
|
|
312
312
|
if (e.buffer.size < o) throw Error(`GPUBuffer size(${e.buffer.size}) is smaller than tensor size(${o})!`);
|
|
313
313
|
if ((e.buffer.usage & (GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC)) !== (GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC)) throw Error("GPUBuffer.usage should include GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC!");
|
|
314
314
|
return e.zeroCopy !== !0 && (r = this.copyBuffer(r)), a.resource = r, l().makeTensorFromDataId(i, t, n, this);
|
|
@@ -367,7 +367,7 @@ var O = t().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), k = (e, t) => {
|
|
|
367
367
|
uploadToGPU(e) {
|
|
368
368
|
let t = this.tensorMap.get(e);
|
|
369
369
|
if (t.resource != null) return;
|
|
370
|
-
let n =
|
|
370
|
+
let n = _(t.dtype) * f(t.shape), r, i = GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC | GPUBufferUsage.COPY_DST;
|
|
371
371
|
if (t.values) {
|
|
372
372
|
if (r = this.bufferManager.acquireBuffer(n, i, !0), r.mapState === "unmapped") {
|
|
373
373
|
let e = this.bufferManager.acquireBuffer(n, GPUBufferUsage.MAP_WRITE | GPUBufferUsage.COPY_SRC, !0, !1), i = e.getMappedRange();
|
|
@@ -431,9 +431,9 @@ var O = t().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), k = (e, t) => {
|
|
|
431
431
|
name: e.variableNames[n]
|
|
432
432
|
};
|
|
433
433
|
});
|
|
434
|
-
e.shaderKey =
|
|
434
|
+
e.shaderKey = v(e, s, o);
|
|
435
435
|
let c = t().getBool("WEBGPU_ENGINE_COMPILE_ONLY");
|
|
436
|
-
return e.shaderKey in this.pipelineCache || (this.pipelineCache[e.shaderKey] =
|
|
436
|
+
return e.shaderKey in this.pipelineCache || (this.pipelineCache[e.shaderKey] = y(this.device, e, s, o, c)), e.pipeline = this.pipelineCache[e.shaderKey], c || this.recordAndSubmit(e, o, n, i), o;
|
|
437
437
|
}
|
|
438
438
|
recordAndSubmit(e, n, r, a) {
|
|
439
439
|
if (e.pipeline instanceof Promise) throw Error("Please call checkCompileCompletionAsync to ensure parallel compilation is done!");
|
|
@@ -497,7 +497,7 @@ var O = t().getNumber("WEBGPU_CPU_HANDOFF_SIZE_THRESHOLD"), k = (e, t) => {
|
|
|
497
497
|
querySet: this.querySet,
|
|
498
498
|
beginningOfPassWriteIndex: 0,
|
|
499
499
|
endOfPassWriteIndex: 1
|
|
500
|
-
}, this.computePassEncoder = this.commandEncoder.beginComputePass(p)) : this.computePassEncoder ||= this.commandEncoder.beginComputePass(p), this.computePassEncoder.setPipeline(e.pipeline), this.computePassEncoder.setBindGroup(0, u), this.computePassEncoder.dispatchWorkgroups(e.dispatch[0], e.dispatch[1], e.dispatch[2]), this.dispatchCountInPass++, (d || t().get("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE") <= this.dispatchCountInPass || e.pixelsOpType ===
|
|
500
|
+
}, this.computePassEncoder = this.commandEncoder.beginComputePass(p)) : this.computePassEncoder ||= this.commandEncoder.beginComputePass(p), this.computePassEncoder.setPipeline(e.pipeline), this.computePassEncoder.setBindGroup(0, u), this.computePassEncoder.dispatchWorkgroups(e.dispatch[0], e.dispatch[1], e.dispatch[2]), this.dispatchCountInPass++, (d || t().get("WEBGPU_DEFERRED_SUBMIT_BATCH_SIZE") <= this.dispatchCountInPass || e.pixelsOpType === b.DRAW) && (this.endComputePassEncoder(), d ? this.activeTimers.push({
|
|
501
501
|
name: e.constructor.name,
|
|
502
502
|
query: this.getQueryTime()
|
|
503
503
|
}) : this.submitQueue());
|