Team Ai
Datasetpublic

Brunobkr/llama.cpp_AlgMor24_github

ΩFFFΣLLIa • llama.cpp • AlgMor24 ██████╗ ███████╗███████╗███████╗██╗ ██╗ ██╗ █████╗ ██╔═══██╗██╔════╝██╔════╝██╔════╝██║ ██║ ██║██╔══██╗ ██║ ██║█████╗ █████╗ █████╗ ██║ ██║ ██║███████║ ██║ ██║██╔══╝ ██╔══╝ ██╔══╝ ██║ ██║ ██║██╔══██║ ╚██████╔╝██║ ██║ ███████╗███████╗███████╗██║██║ ██║ ╚═════╝ ╚═╝ ╚═╝ ╚══════╝╚══════╝╚══════╝╚═╝╚═╝ ╚═╝ High-Performance LLM / VLM Inference & Autonomous Agentic Ecosystem… See the full description on the dataset page: https://huggingface.co/datasets/Brunobkr/llama.cpp_AlgMor24_github.

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes3.1kdownloads
node.cjs2734 linesDownload Raw Back to lib
1"use strict";2// DEFLATE is a complex format; to read this code, you should probably check the RFC first:3// https://tools.ietf.org/html/rfc19514// You may also wish to take a look at the guide I made about this program:5// https://gist.github.com/101arrowz/253f31eb5abc3d9275ab943003ffecad6exports.deflate = deflate;7exports.deflateSync = deflateSync;8exports.inflate = inflate;9exports.inflateSync = inflateSync;10exports.gzip = gzip;11exports.compress = gzip;12exports.gzipSync = gzipSync;13exports.compressSync = gzipSync;14exports.gunzip = gunzip;15exports.gunzipSync = gunzipSync;16exports.zlib = zlib;17exports.zlibSync = zlibSync;18exports.unzlib = unzlib;19exports.unzlibSync = unzlibSync;20exports.gzip = gzip;21exports.compress = gzip;22exports.decompress = decompress;23exports.decompressSync = decompressSync;24exports.strToU8 = strToU8;25exports.strFromU8 = strFromU8;26exports.zip = zip;27exports.zipSync = zipSync;28exports.unzip = unzip;29exports.unzipSync = unzipSync;30// Some of the following code is similar to that of UZIP.js:31// https://github.com/photopea/UZIP.js32// However, the vast majority of the codebase has diverged from UZIP.js to increase performance and reduce bundle size.33// Sometimes 0 will appear where -1 would be more appropriate. This is because using a uint34// is better for memory in most engines (I *think*).35var _a;36// Mediocre shim37var Worker;38var isMarkedAsUntransferable;39var workerAdd = ";var __w=require('worker_threads');__w.parentPort.on('message',function(m){onmessage({data:m})}),postMessage=function(m,t){__w.parentPort.postMessage(m,t)},close=process.exit;self=global";40try {41    (_a = require('worker_threads'), Worker = _a.Worker, isMarkedAsUntransferable = _a.isMarkedAsUntransferable);42}43catch (e) {44}45var node_worker_1 = {};46node_worker_1["default"] = Worker ? function (c, _, msg, transfer, cb) {47    var done = false;48    var w = new Worker(c + workerAdd, { eval: true })49        .on('error', function (e) { return cb(e, null); })50        .on('message', function (m) { return cb(null, m); })51        .on('exit', function (c) {52        if (c && !done)53            cb(new Error('exited with code ' + c), null);54    });55    if (isMarkedAsUntransferable)56        transfer = transfer.filter(function (t) { return !isMarkedAsUntransferable(t); });57    w.postMessage(msg, transfer);58    w.terminate = function () {59        done = true;60        return Worker.prototype.terminate.call(w);61    };62    return w;63} : function (_, __, ___, ____, cb) {64    setImmediate(function () { return cb(new Error('async operations unsupported - update to Node 12+ (or Node 10-11 with the --experimental-worker CLI flag)'), null); });65    var NOP = function () { };66    return {67        terminate: NOP,68        postMessage: NOP69    };70};71 72// aliases for shorter compressed code (most minifers don't do this)73var u8 = Uint8Array, u16 = Uint16Array, i32 = Int32Array;74// fixed length extra bits75var fleb = new u8([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, /* unused */ 0, 0, /* impossible */ 0]);76// fixed distance extra bits77var fdeb = new u8([0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, /* unused */ 0, 0]);78// code length index map79var clim = new u8([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);80// get base, reverse index map from extra bits81var freb = function (eb, start) {82    var b = new u16(31);83    for (var i = 0; i < 31; ++i) {84        b[i] = start += 1 << eb[i - 1];85    }86    // numbers here are at max 18 bits87    var r = new i32(b[30]);88    for (var i = 1; i < 30; ++i) {89        for (var j = b[i]; j < b[i + 1]; ++j) {90            r[j] = ((j - b[i]) << 5) | i;91        }92    }93    return { b: b, r: r };94};95var _a = freb(fleb, 2), fl = _a.b, revfl = _a.r;96// we can ignore the fact that the other numbers are wrong; they never happen anyway97fl[28] = 258, revfl[258] = 28;98var _b = freb(fdeb, 0), fd = _b.b, revfd = _b.r;99// map of value to reverse (assuming 16 bits)100var rev = new u16(32768);101for (var i = 0; i < 32768; ++i) {102    // reverse table algorithm from SO103    var x = ((i & 0xAAAA) >> 1) | ((i & 0x5555) << 1);104    x = ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2);105    x = ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4);106    rev[i] = (((x & 0xFF00) >> 8) | ((x & 0x00FF) << 8)) >> 1;107}108// create huffman tree from u8 "map": index -> code length for code index109// mb (max bits) must be at most 15110// TODO: optimize/split up?111var hMap = (function (cd, mb, r) {112    var s = cd.length;113    // index114    var i = 0;115    // u16 "map": index -> # of codes with bit length = index116    var l = new u16(mb);117    // length of cd must be 288 (total # of codes)118    for (; i < s; ++i) {119        if (cd[i])120            ++l[cd[i] - 1];121    }122    // u16 "map": index -> minimum code for bit length = index123    var le = new u16(mb);124    for (i = 1; i < mb; ++i) {125        le[i] = (le[i - 1] + l[i - 1]) << 1;126    }127    var co;128    if (r) {129        // u16 "map": index -> number of actual bits, symbol for code130        co = new u16(1 << mb);131        // bits to remove for reverser132        var rvb = 15 - mb;133        for (i = 0; i < s; ++i) {134            // ignore 0 lengths135            if (cd[i]) {136                // num encoding both symbol and bits read137                var sv = (i << 4) | cd[i];138                // free bits139                var r_1 = mb - cd[i];140                // start value141                var v = le[cd[i] - 1]++ << r_1;142                // m is end value143                for (var m = v | ((1 << r_1) - 1); v <= m; ++v) {144                    // every 16 bit value starting with the code yields the same result145                    co[rev[v] >> rvb] = sv;146                }147            }148        }149    }150    else {151        co = new u16(s);152        for (i = 0; i < s; ++i) {153            if (cd[i]) {154                co[i] = rev[le[cd[i] - 1]++] >> (15 - cd[i]);155            }156        }157    }158    return co;159});160// fixed length tree161var flt = new u8(288);162for (var i = 0; i < 144; ++i)163    flt[i] = 8;164for (var i = 144; i < 256; ++i)165    flt[i] = 9;166for (var i = 256; i < 280; ++i)167    flt[i] = 7;168for (var i = 280; i < 288; ++i)169    flt[i] = 8;170// fixed distance tree171var fdt = new u8(32);172for (var i = 0; i < 32; ++i)173    fdt[i] = 5;174// fixed length map175var flm = /*#__PURE__*/ hMap(flt, 9, 0), flrm = /*#__PURE__*/ hMap(flt, 9, 1);176// fixed distance map177var fdm = /*#__PURE__*/ hMap(fdt, 5, 0), fdrm = /*#__PURE__*/ hMap(fdt, 5, 1);178// find max of array179var max = function (a) {180    var m = a[0];181    for (var i = 1; i < a.length; ++i) {182        if (a[i] > m)183            m = a[i];184    }185    return m;186};187// read d, starting at bit p and mask with m188var bits = function (d, p, m) {189    var o = (p / 8) | 0;190    return ((d[o] | (d[o + 1] << 8)) >> (p & 7)) & m;191};192// read d, starting at bit p continuing for at least 16 bits193var bits16 = function (d, p) {194    var o = (p / 8) | 0;195    return ((d[o] | (d[o + 1] << 8) | (d[o + 2] << 16)) >> (p & 7));196};197// get end of byte198var shft = function (p) { return ((p + 7) / 8) | 0; };199// typed array slice - allows garbage collector to free original reference,200// while being more compatible than .slice201var slc = function (v, s, e) {202    if (s == null || s < 0)203        s = 0;204    if (e == null || e > v.length)205        e = v.length;206    // can't use .constructor in case user-supplied207    return new u8(v.subarray(s, e));208};209/**210 * Codes for errors generated within this library211 */212exports.FlateErrorCode = {213    UnexpectedEOF: 0,214    InvalidBlockType: 1,215    InvalidLengthLiteral: 2,216    InvalidDistance: 3,217    StreamFinished: 4,218    NoStreamHandler: 5,219    InvalidHeader: 6,220    NoCallback: 7,221    InvalidUTF8: 8,222    ExtraFieldTooLong: 9,223    InvalidDate: 10,224    FilenameTooLong: 11,225    StreamFinishing: 12,226    InvalidZipData: 13,227    UnknownCompressionMethod: 14228};229// error codes230var ec = [231    'unexpected EOF',232    'invalid block type',233    'invalid length/literal',234    'invalid distance',235    'stream finished',236    'no stream handler',237    , // determined by compression function238    'no callback',239    'invalid UTF-8 data',240    'extra field too long',241    'date not in range 1980-2099',242    'filename too long',243    'stream finishing',244    'invalid zip data'245    // determined by unknown compression method246];247;248var err = function (ind, msg, nt) {249    var e = new Error(msg || ec[ind]);250    e.code = ind;251    if (Error.captureStackTrace)252        Error.captureStackTrace(e, err);253    if (!nt)254        throw e;255    return e;256};257// expands raw DEFLATE data258var inflt = function (dat, st, buf, dict) {259    // source length       dict length260    var sl = dat.length, dl = dict ? dict.length : 0;261    if (!sl || st.f && !st.l)262        return buf || new u8(0);263    var noBuf = !buf;264    // have to estimate size265    var resize = noBuf || st.i != 2;266    // no state267    var noSt = st.i;268    // Assumes roughly 33% compression ratio average269    if (noBuf)270        buf = new u8(sl * 3);271    // ensure buffer can fit at least l elements272    var cbuf = function (l) {273        var bl = buf.length;274        // need to increase size to fit275        if (l > bl) {276            // Double or set to necessary, whichever is greater277            var nbuf = new u8(Math.max(bl * 2, l));278            nbuf.set(buf);279            buf = nbuf;280        }281    };282    //  last chunk         bitpos           bytes283    var final = st.f || 0, pos = st.p || 0, bt = st.b || 0, lm = st.l, dm = st.d, lbt = st.m, dbt = st.n;284    // total bits285    var tbts = sl * 8;286    do {287        if (!lm) {288            // BFINAL - this is only 1 when last chunk is next289            final = bits(dat, pos, 1);290            // type: 0 = no compression, 1 = fixed huffman, 2 = dynamic huffman291            var type = bits(dat, pos + 1, 3);292            pos += 3;293            if (!type) {294                // go to end of byte boundary295                var s = shft(pos) + 4, l = dat[s - 4] | (dat[s - 3] << 8), t = s + l;296                if (t > sl) {297                    if (noSt)298                        err(0);299                    break;300                }301                // ensure size302                if (resize)303                    cbuf(bt + l);304                // Copy over uncompressed data305                buf.set(dat.subarray(s, t), bt);306                // Get new bitpos, update byte count307                st.b = bt += l, st.p = pos = t * 8, st.f = final;308                continue;309            }310            else if (type == 1)311                lm = flrm, dm = fdrm, lbt = 9, dbt = 5;312            else if (type == 2) {313                //  literal                            lengths314                var hLit = bits(dat, pos, 31) + 257, hcLen = bits(dat, pos + 10, 15) + 4;315                var tl = hLit + bits(dat, pos + 5, 31) + 1;316                pos += 14;317                // length+distance tree318                var ldt = new u8(tl);319                // code length tree320                var clt = new u8(19);321                for (var i = 0; i < hcLen; ++i) {322                    // use index map to get real code323                    clt[clim[i]] = bits(dat, pos + i * 3, 7);324                }325                pos += hcLen * 3;326                // code lengths bits327                var clb = max(clt), clbmsk = (1 << clb) - 1;328                // code lengths map329                var clm = hMap(clt, clb, 1);330                for (var i = 0; i < tl;) {331                    var r = clm[bits(dat, pos, clbmsk)];332                    // bits read333                    pos += r & 15;334                    // symbol335                    var s = r >> 4;336                    // code length to copy337                    if (s < 16) {338                        ldt[i++] = s;339                    }340                    else {341                        //  copy   count342                        var c = 0, n = 0;343                        if (s == 16)344                            n = 3 + bits(dat, pos, 3), pos += 2, c = ldt[i - 1];345                        else if (s == 17)346                            n = 3 + bits(dat, pos, 7), pos += 3;347                        else if (s == 18)348                            n = 11 + bits(dat, pos, 127), pos += 7;349                        while (n--)350                            ldt[i++] = c;351                    }352                }353                //    length tree                 distance tree354                var lt = ldt.subarray(0, hLit), dt = ldt.subarray(hLit);355                // max length bits356                lbt = max(lt);357                // max dist bits358                dbt = max(dt);359                lm = hMap(lt, lbt, 1);360                dm = hMap(dt, dbt, 1);361            }362            else363                err(1);364            if (pos > tbts) {365                if (noSt)366                    err(0);367                break;368            }369        }370        // Make sure the buffer can hold this + the largest possible addition371        // Maximum chunk size (practically, theoretically infinite) is 2^17372        if (resize)373            cbuf(bt + 131072);374        var lms = (1 << lbt) - 1, dms = (1 << dbt) - 1;375        var lpos = pos;376        for (;; lpos = pos) {377            // bits read, code378            var c = lm[bits16(dat, pos) & lms], sym = c >> 4;379            pos += c & 15;380            if (pos > tbts) {381                if (noSt)382                    err(0);383                break;384            }385            if (!c)386                err(2);387            if (sym < 256)388                buf[bt++] = sym;389            else if (sym == 256) {390                lpos = pos, lm = null;391                break;392            }393            else {394                var add = sym - 254;395                // no extra bits needed if less396                if (sym > 264) {397                    // index398                    var i = sym - 257, b = fleb[i];399                    add = bits(dat, pos, (1 << b) - 1) + fl[i];400                    pos += b;401                }402                // dist403                var d = dm[bits16(dat, pos) & dms], dsym = d >> 4;404                if (!d)405                    err(3);406                pos += d & 15;407                var dt = fd[dsym];408                if (dsym > 3) {409                    var b = fdeb[dsym];410                    dt += bits16(dat, pos) & (1 << b) - 1, pos += b;411                }412                if (pos > tbts) {413                    if (noSt)414                        err(0);415                    break;416                }417                if (resize)418                    cbuf(bt + 131072);419                var end = bt + add;420                if (bt < dt) {421                    var shift = dl - dt, dend = Math.min(dt, end);422                    if (shift + bt < 0)423                        err(3);424                    for (; bt < dend; ++bt)425                        buf[bt] = dict[shift + bt];426                }427                for (; bt < end; ++bt)428                    buf[bt] = buf[bt - dt];429            }430        }431        st.l = lm, st.p = lpos, st.b = bt, st.f = final;432        if (lm)433            final = 1, st.m = lbt, st.d = dm, st.n = dbt;434    } while (!final);435    // don't reallocate for streams or user buffers436    return bt != buf.length && noBuf ? slc(buf, 0, bt) : buf.subarray(0, bt);437};438// starting at p, write the minimum number of bits that can hold v to d439var wbits = function (d, p, v) {440    v <<= p & 7;441    var o = (p / 8) | 0;442    d[o] |= v;443    d[o + 1] |= v >> 8;444};445// starting at p, write the minimum number of bits (>8) that can hold v to d446var wbits16 = function (d, p, v) {447    v <<= p & 7;448    var o = (p / 8) | 0;449    d[o] |= v;450    d[o + 1] |= v >> 8;451    d[o + 2] |= v >> 16;452};453// creates code lengths from a frequency table454var hTree = function (d, mb) {455    // Need extra info to make a tree456    var t = [];457    for (var i = 0; i < d.length; ++i) {458        if (d[i])459            t.push({ s: i, f: d[i] });460    }461    var s = t.length;462    var t2 = t.slice();463    if (!s)464        return { t: et, l: 0 };465    if (s == 1) {466        var v = new u8(t[0].s + 1);467        v[t[0].s] = 1;468        return { t: v, l: 1 };469    }470    t.sort(function (a, b) { return a.f - b.f; });471    // after i2 reaches last ind, will be stopped472    // freq must be greater than largest possible number of symbols473    t.push({ s: -1, f: 25001 });474    var l = t[0], r = t[1], i0 = 0, i1 = 1, i2 = 2;475    t[0] = { s: -1, f: l.f + r.f, l: l, r: r };476    // efficient algorithm from UZIP.js477    // i0 is lookbehind, i2 is lookahead - after processing two low-freq478    // symbols that combined have high freq, will start processing i2 (high-freq,479    // non-composite) symbols instead480    // see https://reddit.com/r/photopea/comments/ikekht/uzipjs_questions/481    while (i1 != s - 1) {482        l = t[t[i0].f < t[i2].f ? i0++ : i2++];483        r = t[i0 != i1 && t[i0].f < t[i2].f ? i0++ : i2++];484        t[i1++] = { s: -1, f: l.f + r.f, l: l, r: r };485    }486    var maxSym = t2[0].s;487    for (var i = 1; i < s; ++i) {488        if (t2[i].s > maxSym)489            maxSym = t2[i].s;490    }491    // code lengths492    var tr = new u16(maxSym + 1);493    // max bits in tree494    var mbt = ln(t[i1 - 1], tr, 0);495    if (mbt > mb) {496        // more algorithms from UZIP.js497        // TODO: find out how this code works (debt)498        //  ind    debt499        var i = 0, dt = 0;500        //    left            cost501        var lft = mbt - mb, cst = 1 << lft;502        t2.sort(function (a, b) { return tr[b.s] - tr[a.s] || a.f - b.f; });503        for (; i < s; ++i) {504            var i2_1 = t2[i].s;505            if (tr[i2_1] > mb) {506                dt += cst - (1 << (mbt - tr[i2_1]));507                tr[i2_1] = mb;508            }509            else510                break;511        }512        dt >>= lft;513        while (dt > 0) {514            var i2_2 = t2[i].s;515            if (tr[i2_2] < mb)516                dt -= 1 << (mb - tr[i2_2]++ - 1);517            else518                ++i;519        }520        for (; i >= 0 && dt; --i) {521            var i2_3 = t2[i].s;522            if (tr[i2_3] == mb) {523                --tr[i2_3];524                ++dt;525            }526        }527        mbt = mb;528    }529    return { t: new u8(tr), l: mbt };530};531// get the max length and assign length codes532var ln = function (n, l, d) {533    return n.s == -1534        ? Math.max(ln(n.l, l, d + 1), ln(n.r, l, d + 1))535        : (l[n.s] = d);536};537// length codes generation538var lc = function (c) {539    var s = c.length;540    // Note that the semicolon was intentional541    while (s && !c[--s])542        ;543    var cl = new u16(++s);544    //  ind      num         streak545    var cli = 0, cln = c[0], cls = 1;546    var w = function (v) { cl[cli++] = v; };547    for (var i = 1; i <= s; ++i) {548        if (c[i] == cln && i != s)549            ++cls;550        else {551            if (!cln && cls > 2) {552                for (; cls > 138; cls -= 138)553                    w(32754);554                if (cls > 2) {555                    w(cls > 10 ? ((cls - 11) << 5) | 28690 : ((cls - 3) << 5) | 12305);556                    cls = 0;557                }558            }559            else if (cls > 3) {560                w(cln), --cls;561                for (; cls > 6; cls -= 6)562                    w(8304);563                if (cls > 2)564                    w(((cls - 3) << 5) | 8208), cls = 0;565            }566            while (cls--)567                w(cln);568            cls = 1;569            cln = c[i];570        }571    }572    return { c: cl.subarray(0, cli), n: s };573};574// calculate the length of output from tree, code lengths575var clen = function (cf, cl) {576    var l = 0;577    for (var i = 0; i < cl.length; ++i)578        l += cf[i] * cl[i];579    return l;580};581// writes a fixed block582// returns the new bit pos583var wfblk = function (out, pos, dat) {584    // no need to write 00 as type: TypedArray defaults to 0585    var s = dat.length;586    var o = shft(pos + 2);587    out[o] = s & 255;588    out[o + 1] = s >> 8;589    out[o + 2] = out[o] ^ 255;590    out[o + 3] = out[o + 1] ^ 255;591    for (var i = 0; i < s; ++i)592        out[o + i + 4] = dat[i];593    return (o + 4 + s) * 8;594};595// writes a block596var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {597    wbits(out, p++, final);598    ++lf[256];599    var _a = hTree(lf, 15), dlt = _a.t, mlb = _a.l;600    var _b = hTree(df, 15), ddt = _b.t, mdb = _b.l;601    var _c = lc(dlt), lclt = _c.c, nlc = _c.n;602    var _d = lc(ddt), lcdt = _d.c, ndc = _d.n;603    var lcfreq = new u16(19);604    for (var i = 0; i < lclt.length; ++i)605        ++lcfreq[lclt[i] & 31];606    for (var i = 0; i < lcdt.length; ++i)607        ++lcfreq[lcdt[i] & 31];608    var _e = hTree(lcfreq, 7), lct = _e.t, mlcb = _e.l;609    var nlcc = 19;610    for (; nlcc > 4 && !lct[clim[nlcc - 1]]; --nlcc)611        ;612    var flen = (bl + 5) << 3;613    var ftlen = clen(lf, flt) + clen(df, fdt) + eb;614    var dtlen = clen(lf, dlt) + clen(df, ddt) + eb + 14 + 3 * nlcc + clen(lcfreq, lct) + 2 * lcfreq[16] + 3 * lcfreq[17] + 7 * lcfreq[18];615    if (bs >= 0 && flen <= ftlen && flen <= dtlen)616        return wfblk(out, p, dat.subarray(bs, bs + bl));617    var lm, ll, dm, dl;618    wbits(out, p, 1 + (dtlen < ftlen)), p += 2;619    if (dtlen < ftlen) {620        lm = hMap(dlt, mlb, 0), ll = dlt, dm = hMap(ddt, mdb, 0), dl = ddt;621        var llm = hMap(lct, mlcb, 0);622        wbits(out, p, nlc - 257);623        wbits(out, p + 5, ndc - 1);624        wbits(out, p + 10, nlcc - 4);625        p += 14;626        for (var i = 0; i < nlcc; ++i)627            wbits(out, p + 3 * i, lct[clim[i]]);628        p += 3 * nlcc;629        var lcts = [lclt, lcdt];630        for (var it = 0; it < 2; ++it) {631            var clct = lcts[it];632            for (var i = 0; i < clct.length; ++i) {633                var len = clct[i] & 31;634                wbits(out, p, llm[len]), p += lct[len];635                if (len > 15)636                    wbits(out, p, (clct[i] >> 5) & 127), p += clct[i] >> 12;637            }638        }639    }640    else {641        lm = flm, ll = flt, dm = fdm, dl = fdt;642    }643    for (var i = 0; i < li; ++i) {644        var sym = syms[i];645        if (sym > 255) {646            var len = (sym >> 18) & 31;647            wbits16(out, p, lm[len + 257]), p += ll[len + 257];648            if (len > 7)649                wbits(out, p, (sym >> 23) & 31), p += fleb[len];650            var dst = sym & 31;651            wbits16(out, p, dm[dst]), p += dl[dst];652            if (dst > 3)653                wbits16(out, p, (sym >> 5) & 8191), p += fdeb[dst];654        }655        else {656            wbits16(out, p, lm[sym]), p += ll[sym];657        }658    }659    wbits16(out, p, lm[256]);660    return p + ll[256];661};662// deflate options (nice << 13) | chain663var deo = /*#__PURE__*/ new i32([65540, 131080, 131088, 131104, 262176, 1048704, 1048832, 2114560, 2117632]);664// empty665var et = /*#__PURE__*/ new u8(0);666// compresses data into a raw DEFLATE buffer667var dflt = function (dat, lvl, plvl, pre, post, st) {668    var s = st.z || dat.length;669    var o = new u8(pre + s + 5 * (1 + Math.ceil(s / 7000)) + post);670    // writing to this writes to the output buffer671    var w = o.subarray(pre, o.length - post);672    var lst = st.l;673    var pos = (st.r || 0) & 7;674    if (lvl) {675        if (pos)676            w[0] = st.r >> 3;677        var opt = deo[lvl - 1];678        var n = opt >> 13, c = opt & 8191;679        var msk_1 = (1 << plvl) - 1;680        //    prev 2-byte val map    curr 2-byte val map681        var prev = st.p || new u16(32768), head = st.h || new u16(msk_1 + 1);682        var bs1_1 = Math.ceil(plvl / 3), bs2_1 = 2 * bs1_1;683        var hsh = function (i) { return (dat[i] ^ (dat[i + 1] << bs1_1) ^ (dat[i + 2] << bs2_1)) & msk_1; };684        // 24576 is an arbitrary number of maximum symbols per block685        // 424 buffer for last block686        var syms = new i32(25000);687        // length/literal freq   distance freq688        var lf = new u16(288), df = new u16(32);689        //  l/lcnt  exbits  index          l/lind  waitdx          blkpos690        var lc_1 = 0, eb = 0, i = st.i || 0, li = 0, wi = st.w || 0, bs = 0;691        for (; i + 2 < s; ++i) {692            // hash value693            var hv = hsh(i);694            // index mod 32768    previous index mod695            var imod = i & 32767, pimod = head[hv];696            prev[imod] = pimod;697            head[hv] = imod;698            // We always should modify head and prev, but only add symbols if699            // this data is not yet processed ("wait" for wait index)700            if (wi <= i) {701                // bytes remaining702                var rem = s - i;703                if ((lc_1 > 7000 || li > 24576) && (rem > 423 || !lst)) {704                    pos = wblk(dat, w, 0, syms, lf, df, eb, li, bs, i - bs, pos);705                    li = lc_1 = eb = 0, bs = i;706                    for (var j = 0; j < 286; ++j)707                        lf[j] = 0;708                    for (var j = 0; j < 30; ++j)709                        df[j] = 0;710                }711                //  len    dist   chain712                var l = 2, d = 0, ch_1 = c, dif = imod - pimod & 32767;713                if (rem > 2 && hv == hsh(i - dif)) {714                    var maxn = Math.min(n, rem) - 1;715                    var maxd = Math.min(32767, i);716                    // max possible length717                    // not capped at dif because decompressors implement "rolling" index population718                    var ml = Math.min(258, rem);719                    while (dif <= maxd && --ch_1 && imod != pimod) {720                        if (dat[i + l] == dat[i + l - dif]) {721                            var nl = 0;722                            for (; nl < ml && dat[i + nl] == dat[i + nl - dif]; ++nl)723                                ;724                            if (nl > l) {725                                l = nl, d = dif;726                                // break out early when we reach "nice" (we are satisfied enough)727                                if (nl > maxn)728                                    break;729                                // now, find the rarest 2-byte sequence within this730                                // length of literals and search for that instead.731                                // Much faster than just using the start732                                var mmd = Math.min(dif, nl - 2);733                                var md = 0;734                                for (var j = 0; j < mmd; ++j) {735                                    var ti = i - dif + j & 32767;736                                    var pti = prev[ti];737                                    var cd = ti - pti & 32767;738                                    if (cd > md)739                                        md = cd, pimod = ti;740                                }741                            }742                        }743                        // check the previous match744                        imod = pimod, pimod = prev[imod];745                        dif += imod - pimod & 32767;746                    }747                }748                // d will be nonzero only when a match was found749                if (d) {750                    // store both dist and len data in one int32751                    // Make sure this is recognized as a len/dist with 28th bit (2^28)752                    syms[li++] = 268435456 | (revfl[l] << 18) | revfd[d];753                    var lin = revfl[l] & 31, din = revfd[d] & 31;754                    eb += fleb[lin] + fdeb[din];755                    ++lf[257 + lin];756                    ++df[din];757                    wi = i + l;758                    ++lc_1;759                }760                else {761                    syms[li++] = dat[i];762                    ++lf[dat[i]];763                }764            }765        }766        for (i = Math.max(i, wi); i < s; ++i) {767            syms[li++] = dat[i];768            ++lf[dat[i]];769        }770        pos = wblk(dat, w, lst, syms, lf, df, eb, li, bs, i - bs, pos);771        if (!lst) {772            st.r = (pos & 7) | w[(pos / 8) | 0] << 3;773            // shft(pos) now 1 less if pos & 7 != 0774            pos -= 7;775            st.h = head, st.p = prev, st.i = i, st.w = wi;776        }777    }778    else {779        for (var i = st.w || 0; i < s + lst; i += 65535) {780            // end781            var e = i + 65535;782            if (e >= s) {783                // write final block784                w[(pos / 8) | 0] = lst;785                e = s;786            }787            pos = wfblk(w, pos + 1, dat.subarray(i, e));788        }789        st.i = s;790    }791    return slc(o, 0, pre + shft(pos) + post);792};793// CRC32 table794var crct = /*#__PURE__*/ (function () {795    var t = new Int32Array(256);796    for (var i = 0; i < 256; ++i) {797        var c = i, k = 9;798        while (--k)799            c = ((c & 1) && -306674912) ^ (c >>> 1);800        t[i] = c;801    }802    return t;803})();804// CRC32805var crc = function () {806    var c = -1;807    return {808        p: function (d) {809            // closures have awful performance810            var cr = c;811            for (var i = 0; i < d.length; ++i)812                cr = crct[(cr & 255) ^ d[i]] ^ (cr >>> 8);813            c = cr;814        },815        d: function () { return ~c; }816    };817};818// Adler32819var adler = function () {820    var a = 1, b = 0;821    return {822        p: function (d) {823            // closures have awful performance824            var n = a, m = b;825            var l = d.length | 0;826            for (var i = 0; i != l;) {827                var e = Math.min(i + 2655, l);828                for (; i < e; ++i)829                    m += n += d[i];830                n = (n & 65535) + 15 * (n >> 16), m = (m & 65535) + 15 * (m >> 16);831            }832            a = n, b = m;833        },834        d: function () {835            a %= 65521, b %= 65521;836            return (a & 255) << 24 | (a & 0xFF00) << 8 | (b & 255) << 8 | (b >> 8);837        }838    };839};840;841// deflate with opts842var dopt = function (dat, opt, pre, post, st) {843    if (!st) {844        st = { l: 1 };845        if (opt.dictionary) {846            var dict = opt.dictionary.subarray(-32768);847            var newDat = new u8(dict.length + dat.length);848            newDat.set(dict);849            newDat.set(dat, dict.length);850            dat = newDat;851            st.w = dict.length;852        }853    }854    return dflt(dat, opt.level == null ? 6 : opt.level, opt.mem == null ? (st.l ? Math.ceil(Math.max(8, Math.min(13, Math.log(dat.length))) * 1.5) : 20) : (12 + opt.mem), pre, post, st);855};856// Walmart object spread857var mrg = function (a, b) {858    var o = {};859    for (var k in a)860        o[k] = a[k];861    for (var k in b)862        o[k] = b[k];863    return o;864};865// worker clone866// This is possibly the craziest part of the entire codebase, despite how simple it may seem.867// The only parameter to this function is a closure that returns an array of variables outside of the function scope.868// We're going to try to figure out the variable names used in the closure as strings because that is crucial for workerization.869// We will return an object mapping of true variable name to value (basically, the current scope as a JS object).870// The reason we can't just use the original variable names is minifiers mangling the toplevel scope.871// This took me three weeks to figure out how to do.872var wcln = function (fn, fnStr, td) {873    var dt = fn();874    var st = fn.toString();875    var ks = st.slice(st.indexOf('[') + 1, st.lastIndexOf(']')).replace(/\s+/g, '').split(',');876    for (var i = 0; i < dt.length; ++i) {877        var v = dt[i], k = ks[i];878        if (typeof v == 'function') {879            fnStr += ';' + k + '=';880            var st_1 = v.toString();881            if (v.prototype) {882                // for global objects883                if (st_1.indexOf('[native code]') != -1) {884                    var spInd = st_1.indexOf(' ', 8) + 1;885                    fnStr += st_1.slice(spInd, st_1.indexOf('(', spInd));886                }887                else {888                    fnStr += st_1;889                    for (var t in v.prototype)890                        fnStr += ';' + k + '.prototype.' + t + '=' + v.prototype[t].toString();891                }892            }893            else894                fnStr += st_1;895        }896        else897            td[k] = v;898    }899    return fnStr;900};901var ch = [];902// clone bufs903var cbfs = function (v) {904    var tl = [];905    for (var k in v) {906        if (v[k].buffer) {907            tl.push((v[k] = new v[k].constructor(v[k])).buffer);908        }909    }910    return tl;911};912// use a worker to execute code913var wrkr = function (fns, init, id, cb) {914    if (!ch[id]) {915        var fnStr = '', td_1 = {}, m = fns.length - 1;916        for (var i = 0; i < m; ++i)917            fnStr = wcln(fns[i], fnStr, td_1);918        ch[id] = { c: wcln(fns[m], fnStr, td_1), e: td_1 };919    }920    var td = mrg({}, ch[id].e);921    return (0, node_worker_1.default)(ch[id].c + ';onmessage=function(e){for(var k in e.data)self[k]=e.data[k];onmessage=' + init.toString() + '}', id, td, cbfs(td), cb);922};923// base async inflate fn924var bInflt = function () { return [u8, u16, i32, fleb, fdeb, clim, fl, fd, flrm, fdrm, rev, ec, hMap, max, bits, bits16, shft, slc, err, inflt, inflateSync, pbf, gopt]; };925var bDflt = function () { return [u8, u16, i32, fleb, fdeb, clim, revfl, revfd, flm, flt, fdm, fdt, rev, deo, et, hMap, wbits, wbits16, hTree, ln, lc, clen, wfblk, wblk, shft, slc, dflt, dopt, deflateSync, pbf]; };926// gzip extra927var gze = function () { return [gzh, gzhl, wbytes, crc, crct]; };928// gunzip extra929var guze = function () { return [gzs, gzl]; };930// zlib extra931var zle = function () { return [zlh, wbytes, adler]; };932// unzlib extra933var zule = function () { return [zls]; };934// post buf935var pbf = function (msg) { return postMessage(msg, [msg.buffer]); };936// get opts937var gopt = function (o) { return o && {938    out: o.size && new u8(o.size),939    dictionary: o.dictionary940}; };941// async helper942var cbify = function (dat, opts, fns, init, id, cb) {943    var w = wrkr(fns, init, id, function (err, dat) {944        w.terminate();945        cb(err, dat);946    });947    w.postMessage([dat, opts], opts.consume ? [dat.buffer] : []);948    return function () { w.terminate(); };949};950// auto stream951var astrm = function (strm) {952    strm.ondata = function (dat, final) { return postMessage([dat, final], [dat.buffer]); };953    return function (ev) {954        if (ev.data[0]) {955            strm.push(ev.data[0], ev.data[1]);956            postMessage([ev.data[0].length]);957        }958        else959            strm.flush(ev.data[1]);960    };961};962// async stream attach963var astrmify = function (fns, strm, opts, init, id, flush, ext) {964    var t;965    var w = wrkr(fns, init, id, function (err, dat) {966        if (err)967            w.terminate(), strm.ondata.call(strm, err);968        else if (!Array.isArray(dat))969            ext(dat);970        else if (dat.length == 1) {971            strm.queuedSize -= dat[0];972            if (strm.ondrain)973                strm.ondrain(dat[0]);974        }975        else {976            if (dat[1])977                w.terminate();978            strm.ondata.call(strm, err, dat[0], dat[1]);979        }980    });981    w.postMessage(opts);982    strm.queuedSize = 0;983    strm.push = function (d, f) {984        if (!strm.ondata)985            err(5);986        if (t)987            strm.ondata(err(4, 0, 1), null, !!f);988        strm.queuedSize += d.length;989        // can fail for cross-realm Uint8Array, but ok - only a small performance penalty990        w.postMessage([d, t = f], d.buffer instanceof ArrayBuffer ? [d.buffer] : []);991    };992    strm.terminate = function () { w.terminate(); };993    if (flush) {994        strm.flush = function (sync) { w.postMessage([0, sync]); };995    }996};997// read 2 bytes998var b2 = function (d, b) { return d[b] | (d[b + 1] << 8); };999// read 4 bytes1000var b4 = function (d, b) { return (d[b] | (d[b + 1] << 8) | (d[b + 2] << 16) | (d[b + 3] << 24)) >>> 0; };1001// read 8 bytes1002var b8 = function (d, b) { return b4(d, b) + (b4(d, b + 4) * 4294967296); };1003// write bytes1004var wbytes = function (d, b, v) {1005    for (; v; ++b)1006        d[b] = v, v >>>= 8;1007};1008// gzip header1009var gzh = function (c, o) {1010    var fn = o.filename;1011    c[0] = 31, c[1] = 139, c[2] = 8, c[8] = o.level < 2 ? 4 : o.level == 9 ? 2 : 0, c[9] = 3; // assume Unix1012    if (o.mtime != 0)1013        wbytes(c, 4, Math.floor(new Date(o.mtime || Date.now()) / 1000));1014    if (fn) {1015        c[3] = 8;1016        for (var i = 0; i <= fn.length; ++i)1017            c[i + 10] = fn.charCodeAt(i);1018    }1019};1020// gzip footer: -8 to -4 = CRC, -4 to -0 is length1021// gzip start1022var gzs = function (d) {1023    if (d[0] != 31 || d[1] != 139 || d[2] != 8)1024        err(6, 'invalid gzip data');1025    var flg = d[3];1026    var st = 10;1027    if (flg & 4)1028        st += (d[10] | d[11] << 8) + 2;1029    for (var zs = (flg >> 3 & 1) + (flg >> 4 & 1); zs > 0; zs -= !d[st++])1030        ;1031    return st + (flg & 2);1032};1033// gzip length1034var gzl = function (d) {1035    var l = d.length;1036    return (d[l - 4] | d[l - 3] << 8 | d[l - 2] << 16 | d[l - 1] << 24) >>> 0;1037};1038// gzip header length1039var gzhl = function (o) { return 10 + (o.filename ? o.filename.length + 1 : 0); };1040// zlib header1041var zlh = function (c, o) {1042    var lv = o.level, fl = lv == 0 ? 0 : lv < 6 ? 1 : lv == 9 ? 3 : 2;1043    c[0] = 120, c[1] = (fl << 6) | (o.dictionary && 32);1044    c[1] |= 31 - ((c[0] << 8) | c[1]) % 31;1045    if (o.dictionary) {1046        var h = adler();1047        h.p(o.dictionary);1048        wbytes(c, 2, h.d());1049    }1050};1051// zlib start1052var zls = function (d, dict) {1053    if ((d[0] & 15) != 8 || (d[0] >> 4) > 7 || ((d[0] << 8 | d[1]) % 31))1054        err(6, 'invalid zlib data');1055    if ((d[1] >> 5 & 1) == +!dict)1056        err(6, 'invalid zlib data: ' + (d[1] & 32 ? 'need' : 'unexpected') + ' dictionary');1057    return (d[1] >> 3 & 4) + 2;1058};1059function StrmOpt(opts, cb) {1060    if (typeof opts == 'function')1061        cb = opts, opts = {};1062    this.ondata = cb;1063    return opts;1064}1065/**1066 * Streaming DEFLATE compression1067 */1068var Deflate = /*#__PURE__*/ (function () {1069    function Deflate(opts, cb) {1070        if (typeof opts == 'function')1071            cb = opts, opts = {};1072        this.ondata = cb;1073        this.o = opts || {};1074        this.s = { l: 0, i: 32768, w: 32768, z: 32768 };1075        // Buffer length must always be 0 mod 32768 for index calculations to be correct when modifying head and prev1076        // 98304 = 32768 (lookback) + 65536 (common chunk size)1077        this.b = new u8(98304);1078        if (this.o.dictionary) {1079            var dict = this.o.dictionary.subarray(-32768);1080            this.b.set(dict, 32768 - dict.length);1081            this.s.i = 32768 - dict.length;1082        }1083    }1084    Deflate.prototype.p = function (c, f) {1085        this.ondata(dopt(c, this.o, 0, 0, this.s), f);1086    };1087    /**1088     * Pushes a chunk to be deflated1089     * @param chunk The chunk to push1090     * @param final Whether this is the last chunk1091     */1092    Deflate.prototype.push = function (chunk, final) {1093        if (!this.ondata)1094            err(5);1095        if (this.s.l)1096            err(4);1097        var endLen = chunk.length + this.s.z;1098        if (endLen > this.b.length) {1099            if (endLen > 2 * this.b.length - 32768) {1100                var newBuf = new u8(endLen & -32768);1101                newBuf.set(this.b.subarray(0, this.s.z));1102                this.b = newBuf;1103            }1104            var split = this.b.length - this.s.z;1105            this.b.set(chunk.subarray(0, split), this.s.z);1106            this.s.z = this.b.length;1107            this.p(this.b, false);1108            this.b.set(this.b.subarray(-32768));1109            this.b.set(chunk.subarray(split), 32768);1110            this.s.z = chunk.length - split + 32768;1111            this.s.i = 32766, this.s.w = 32768;1112        }1113        else {1114            this.b.set(chunk, this.s.z);1115            this.s.z += chunk.length;1116        }1117        this.s.l = final & 1;1118        if (this.s.z > this.s.w + 8191 || final) {1119            this.p(this.b, final || false);1120            this.s.w = this.s.i, this.s.i -= 2;1121        }1122        if (final) {1123            // cleanup unneeded buffers/state to reduce memory usage1124            this.s = this.o = {};1125            this.b = et;1126        }1127    };1128    /**1129     * Flushes buffered uncompressed data. Useful to immediately retrieve the1130     * deflated output for small inputs.1131     * @param sync Whether to flush to a byte boundary. A sync flush takes 4-51132     *             extra bytes, but guarantees all pushed data is immediately1133     *             decompressible. A separate DEFLATE stream may be concatenated1134     *             with the current output after a sync flush.1135     */1136    Deflate.prototype.flush = function (sync) {1137        if (!this.ondata)1138            err(5);1139        if (this.s.l)1140            err(4);1141        this.p(this.b, false);1142        this.s.w = this.s.i, this.s.i -= 2;1143        // could technically skip writing the type-0 block for (this.s.r & 7) == 0,1144        // but the deterministic trailer (00 00 FF FF) is useful in some situations1145        if (sync) {1146            var c = new u8(6);1147            c[0] = this.s.r >> 3;1148            // write empty, non-final type-0 block1149            var ep = wfblk(c, this.s.r, et);1150            this.s.r = 0;1151            this.ondata(c.subarray(0, ep >> 3), false);1152        }1153    };1154    return Deflate;1155}());1156exports.Deflate = Deflate;1157/**1158 * Asynchronous streaming DEFLATE compression1159 */1160var AsyncDeflate = /*#__PURE__*/ (function () {1161    function AsyncDeflate(opts, cb) {1162        astrmify([1163            bDflt,1164            function () { return [astrm, Deflate]; }1165        ], this, StrmOpt.call(this, opts, cb), function (ev) {1166            var strm = new Deflate(ev.data);1167            onmessage = astrm(strm);1168        }, 6, 1);1169    }1170    return AsyncDeflate;1171}());1172exports.AsyncDeflate = AsyncDeflate;1173function deflate(data, opts, cb) {1174    if (!cb)1175        cb = opts, opts = {};1176    if (typeof cb != 'function')1177        err(7);1178    return cbify(data, opts, [1179        bDflt,1180    ], function (ev) { return pbf(deflateSync(ev.data[0], ev.data[1])); }, 0, cb);1181}1182/**1183 * Compresses data with DEFLATE without any wrapper1184 * @param data The data to compress1185 * @param opts The compression options1186 * @returns The deflated version of the data1187 */1188function deflateSync(data, opts) {1189    return dopt(data, opts || {}, 0, 0);1190}1191/**1192 * Streaming DEFLATE decompression1193 */1194var Inflate = /*#__PURE__*/ (function () {1195    function Inflate(opts, cb) {1196        // no StrmOpt here to avoid adding to workerizer1197        if (typeof opts == 'function')1198            cb = opts, opts = {};1199        this.ondata = cb;1200        var dict = opts && opts.dictionary && opts.dictionary.subarray(-32768);

Showing the first 1,200 of 2734 lines. Download the file for the rest.

Brunobkr/llama.cpp_AlgMor24_github · Team Ai