@genai-fi/nanogpt 0.2.6 → 0.2.7
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { gatherSub as
|
|
2
|
-
import { scatterSub as
|
|
3
|
-
import { o as l, c as d, E as f, M as
|
|
1
|
+
import { gatherSub as w } from "../ops/gatherSub.js";
|
|
2
|
+
import { scatterSub as K } from "../ops/scatterSub.js";
|
|
3
|
+
import { o as l, c as d, E as f, M as _, p as z, L as I, q as N, a as E, t as M, u as T, e as m, v as g, w as $, z as S } from "../index-D1SlunD-.js";
|
|
4
4
|
import { s as F, r as b } from "../sum-02UQ5Eaq.js";
|
|
5
5
|
/**
|
|
6
6
|
* @license
|
|
@@ -47,9 +47,9 @@ function q(n, s) {
|
|
|
47
47
|
*/
|
|
48
48
|
function A(n, s = null, t = !1) {
|
|
49
49
|
const e = { x: d(n, "x", "max") }, r = { reductionIndices: s, keepDims: t };
|
|
50
|
-
return f.runKernel(
|
|
50
|
+
return f.runKernel(_, e, r);
|
|
51
51
|
}
|
|
52
|
-
const
|
|
52
|
+
const L = /* @__PURE__ */ l({ max_: A });
|
|
53
53
|
/**
|
|
54
54
|
* @license
|
|
55
55
|
* Copyright 2018 Google LLC. All Rights Reserved.
|
|
@@ -109,7 +109,7 @@ const j = /* @__PURE__ */ l({ log_: W });
|
|
|
109
109
|
* =============================================================================
|
|
110
110
|
*/
|
|
111
111
|
function B(n, s = null, t = !1) {
|
|
112
|
-
const a = d(n, "x", "logSumExp"), e = N(s, a.shape), r =
|
|
112
|
+
const a = d(n, "x", "logSumExp"), e = N(s, a.shape), r = L(
|
|
113
113
|
a,
|
|
114
114
|
e,
|
|
115
115
|
!0
|
|
@@ -148,30 +148,30 @@ function J(n, s = -1) {
|
|
|
148
148
|
const Q = /* @__PURE__ */ l({ softmax_: J });
|
|
149
149
|
function R(n, s) {
|
|
150
150
|
return $(() => {
|
|
151
|
-
const t = n.shape[n.shape.length - 1], e = n.shape.slice(0, -1).reduce((h, x) => h * x, 1), r = n.shape.length > 2 ? n.reshape([e, t]) : n, c = s.shape.length > 1 ? s.reshape([e]).cast("int32") : s.cast("int32"), o =
|
|
152
|
-
return
|
|
151
|
+
const t = n.shape[n.shape.length - 1], e = n.shape.slice(0, -1).reduce((h, x) => h * x, 1), r = n.shape.length > 2 ? n.reshape([e, t]) : n, c = s.shape.length > 1 ? s.reshape([e]).cast("int32") : s.cast("int32"), o = L(r, -1, !0), p = E(r, o), u = H(p, -1);
|
|
152
|
+
return w(u, c, p);
|
|
153
153
|
});
|
|
154
154
|
}
|
|
155
|
-
function
|
|
156
|
-
return m().backendName === "tensorflow" ?
|
|
155
|
+
function ss() {
|
|
156
|
+
return m().backendName === "tensorflow" ? g((s, t, a) => {
|
|
157
157
|
const e = s.shape.length > 2 ? s.reshape([-1, s.shape[s.shape.length - 1]]) : s, r = t.shape.length > 1 ? t.reshape([-1]).cast("int32") : t.cast("int32"), [c, o] = m().runKernel(
|
|
158
158
|
"NativeSparseSoftmaxCrossEntropy",
|
|
159
159
|
{ logits: e, labels: r },
|
|
160
160
|
{}
|
|
161
161
|
);
|
|
162
|
-
return a([o.reshape(s.shape)]), { value: c, gradFunc: (p, u) => [u[0],
|
|
163
|
-
}) :
|
|
162
|
+
return a([o.reshape(s.shape)]), { value: c, gradFunc: (p, u) => [u[0], S(t)] };
|
|
163
|
+
}) : g(
|
|
164
164
|
// @ts-expect-error Invalid params
|
|
165
165
|
(s, t, a) => {
|
|
166
166
|
const e = s.shape[s.shape.length - 1], c = s.shape.slice(0, -1).reduce((h, x) => h * x, 1), o = s.reshape([c, e]), p = t.reshape([c]).cast("int32"), u = R(o, p);
|
|
167
167
|
return a([o, p]), o.dispose(), p.dispose(), { value: u, gradFunc: (h, x) => $(() => {
|
|
168
|
-
const
|
|
169
|
-
return [
|
|
168
|
+
const k = x[0], y = x[1], C = Q(k), G = K(C, y, h), v = S(t);
|
|
169
|
+
return [G.reshape(s.shape), v];
|
|
170
170
|
}) };
|
|
171
171
|
}
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
174
|
export {
|
|
175
|
-
|
|
175
|
+
ss as createSoftmaxCrossEntropyWithGrad,
|
|
176
176
|
R as sparseSoftmaxCrossEntropy
|
|
177
177
|
};
|