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
0likes3kdownloads
parse.js284 linesDownload Raw Back to src
1import { decode64 } from './base64.js';2import {3	HOLE,4	MAX_ARRAY_INDEX,5	NAN,6	NEGATIVE_INFINITY,7	NEGATIVE_ZERO,8	POSITIVE_INFINITY,9	SPARSE,10	UNDEFINED11} from './constants.js';12import { is_valid_array_index, is_valid_array_len } from './utils.js';13 14/**15 * Revive a value serialized with `devalue.stringify`16 * @param {string} serialized17 * @param {Record<string, (value: any) => any>} [revivers]18 */19export function parse(serialized, revivers) {20	return unflatten(JSON.parse(serialized), revivers);21}22 23/**24 * Revive a value flattened with `devalue.stringify`25 * @param {number | any[]} parsed26 * @param {Record<string, (value: any) => any>} [revivers]27 */28export function unflatten(parsed, revivers) {29	if (typeof parsed === 'number') return hydrate(parsed, true);30 31	if (!Array.isArray(parsed) || parsed.length === 0) {32		throw new Error('Invalid input');33	}34 35	const values = /** @type {any[]} */ (parsed);36 37	const hydrated = Array(values.length);38 39	/**40	 * A set of values currently being hydrated with custom revivers,41	 * used to detect invalid cyclical dependencies42	 * @type {Set<number> | null}43	 */44	let hydrating = null;45 46	/**47	 * @param {number} index48	 * @returns {any}49	 */50	function hydrate(index, standalone = false) {51		if (index === UNDEFINED) return undefined;52		if (index === NAN) return NaN;53		if (index === POSITIVE_INFINITY) return Infinity;54		if (index === NEGATIVE_INFINITY) return -Infinity;55		if (index === NEGATIVE_ZERO) return -0;56 57		if (standalone || typeof index !== 'number') {58			throw new Error(`Invalid input`);59		}60 61		if (index in hydrated) return hydrated[index];62 63		const value = values[index];64 65		if (!value || typeof value !== 'object') {66			hydrated[index] = value;67		} else if (Array.isArray(value)) {68			if (typeof value[0] === 'string') {69				const type = value[0];70 71				const reviver = revivers && Object.hasOwn(revivers, type) ? revivers[type] : undefined;72 73				if (reviver) {74					let i = value[1];75					if (typeof i !== 'number') {76						// if it's not a number, it was serialized by a builtin reviver77						// so we need to munge it into the format expected by a custom reviver78						i = values.push(value[1]) - 1;79					}80 81					hydrating ??= new Set();82 83					if (hydrating.has(i)) {84						throw new Error('Invalid circular reference');85					}86 87					hydrating.add(i);88					hydrated[index] = reviver(hydrate(i));89					hydrating.delete(i);90 91					return hydrated[index];92				}93 94				switch (type) {95					case 'Date':96						hydrated[index] = new Date(value[1]);97						break;98 99					case 'Set':100						const set = new Set();101						hydrated[index] = set;102						for (let i = 1; i < value.length; i += 1) {103							set.add(hydrate(value[i]));104						}105						break;106 107					case 'Map':108						const map = new Map();109						hydrated[index] = map;110						for (let i = 1; i < value.length; i += 2) {111							map.set(hydrate(value[i]), hydrate(value[i + 1]));112						}113						break;114 115					case 'RegExp':116						hydrated[index] = new RegExp(value[1], value[2]);117						break;118 119					case 'Object': {120						const wrapped_index = value[1];121 122						if (123							typeof values[wrapped_index] === 'object' &&124							values[wrapped_index][0] !== 'BigInt'125						) {126							// avoid infinite recusion in case of malformed input127							throw new Error('Invalid input');128						}129 130						hydrated[index] = Object(hydrate(wrapped_index));131						break;132					}133 134					case 'BigInt':135						hydrated[index] = BigInt(value[1]);136						break;137 138					case 'null':139						const obj = Object.create(null);140						hydrated[index] = obj;141						for (let i = 1; i < value.length; i += 2) {142							if (value[i] === '__proto__') {143								throw new Error('Cannot parse an object with a `__proto__` property');144							}145 146							obj[value[i]] = hydrate(value[i + 1]);147						}148						break;149 150					case 'Int8Array':151					case 'Uint8Array':152					case 'Uint8ClampedArray':153					case 'Int16Array':154					case 'Uint16Array':155					case 'Float16Array':156					case 'Int32Array':157					case 'Uint32Array':158					case 'Float32Array':159					case 'Float64Array':160					case 'BigInt64Array':161					case 'BigUint64Array':162					case 'DataView': {163						if (values[value[1]][0] !== 'ArrayBuffer') {164							// without this, if we receive malformed input we could165							// end up trying to hydrate in a circle or allocate166							// huge amounts of memory when we call `new TypedArrayConstructor(buffer)`167							throw new Error('Invalid data');168						}169 170						const TypedArrayConstructor = globalThis[type];171						const buffer = hydrate(value[1]);172 173						hydrated[index] =174							value[2] !== undefined175								? new TypedArrayConstructor(buffer, value[2], value[3])176								: new TypedArrayConstructor(buffer);177 178						break;179					}180 181					case 'ArrayBuffer': {182						const base64 = value[1];183						if (typeof base64 !== 'string') {184							throw new Error('Invalid ArrayBuffer encoding');185						}186						const arraybuffer = decode64(base64);187						hydrated[index] = arraybuffer;188						break;189					}190 191					case 'Temporal.Duration':192					case 'Temporal.Instant':193					case 'Temporal.PlainDate':194					case 'Temporal.PlainTime':195					case 'Temporal.PlainDateTime':196					case 'Temporal.PlainMonthDay':197					case 'Temporal.PlainYearMonth':198					case 'Temporal.ZonedDateTime': {199						const temporalName = type.slice(9);200						// @ts-expect-error TS doesn't know about Temporal yet201						hydrated[index] = Temporal[temporalName].from(value[1]);202						break;203					}204 205					case 'URL': {206						const url = new URL(value[1]);207						hydrated[index] = url;208						break;209					}210 211					case 'URLSearchParams': {212						const url = new URLSearchParams(value[1]);213						hydrated[index] = url;214						break;215					}216 217					default:218						throw new Error(`Unknown type ${type}`);219				}220			} else if (value[0] === SPARSE) {221				// Sparse array encoding: [SPARSE, length, idx, val, idx, val, ...]222				const len = value[1];223 224				if (!is_valid_array_len(len)) {225					throw new Error('Invalid input');226				}227 228				/** @type {any[]} */229				const array = [];230				hydrated[index] = array;231 232				// Setting `array.length = len` (or equivalently calling `new Array(len)`)233				// on an untrusted `len` is a DoS vector: V8 eagerly allocates a234				// contiguous backing store for array lengths below ~10^8, so a235				// small payload with a huge declared length can force arbitrary236				// memory allocation. Touching the largest-possible index first237				// forces V8 into dictionary-elements mode, where `length` is238				// just a number and no contiguous allocation occurs.239				array[MAX_ARRAY_INDEX] = undefined;240				delete array[MAX_ARRAY_INDEX];241 242				for (let i = 2; i < value.length; i += 2) {243					const idx = value[i];244 245					if (!is_valid_array_index(idx) || idx >= len) {246						throw new Error('Invalid input');247					}248 249					array[idx] = hydrate(value[i + 1]);250				}251 252				array.length = len;253			} else {254				const array = new Array(value.length);255				hydrated[index] = array;256 257				for (let i = 0; i < value.length; i += 1) {258					const n = value[i];259					if (n === HOLE) continue;260 261					array[i] = hydrate(n);262				}263			}264		} else {265			/** @type {Record<string, any>} */266			const object = {};267			hydrated[index] = object;268 269			for (const key of Object.keys(value)) {270				if (key === '__proto__') {271					throw new Error('Cannot parse an object with a `__proto__` property');272				}273 274				const n = value[key];275				object[key] = hydrate(n);276			}277		}278 279		return hydrated[index];280	}281 282	return hydrate(0);283}284