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
module-evaluator.js361 linesDownload Raw Back to dist
1import { isBuiltin, createRequire } from 'node:module';2import { pathToFileURL, fileURLToPath } from 'node:url';3import vm from 'node:vm';4import { ssrModuleExportsKey, ssrImportMetaKey, ssrImportKey, ssrDynamicImportKey, ssrExportAllKey } from 'vite/module-runner';5import { T as Traces } from './chunks/traces.DT5aQ62U.js';6 7const performanceNow = performance.now.bind(performance);8class ModuleDebug {9	executionStack = [];10	startCalculateModuleExecutionInfo(filename, options) {11		const startTime = performanceNow();12		this.executionStack.push({13			filename,14			startTime,15			subImportTime: 016		});17		return () => {18			const duration = performanceNow() - startTime;19			const currentExecution = this.executionStack.pop();20			if (currentExecution == null) throw new Error("Execution stack is empty, this should never happen");21			const selfTime = duration - currentExecution.subImportTime;22			if (this.executionStack.length > 0) this.executionStack.at(-1).subImportTime += duration;23			return {24				startOffset: options.startOffset,25				external: options.external,26				importer: options.importer,27				duration,28				selfTime29			};30		};31	}32}33 34const isWindows = process.platform === "win32";35class VitestModuleEvaluator {36	stubs = {};37	env = createImportMetaEnvProxy();38	vm;39	compiledFunctionArgumentsNames;40	compiledFunctionArgumentsValues = [];41	primitives;42	debug = new ModuleDebug();43	_otel;44	_evaluatedModules;45	constructor(vmOptions, options = {}) {46		this.options = options;47		this._otel = options.traces || new Traces({ enabled: false });48		this.vm = vmOptions;49		this.stubs = getDefaultRequestStubs(vmOptions?.context);50		this._evaluatedModules = options.evaluatedModules;51		if (options.compiledFunctionArgumentsNames) this.compiledFunctionArgumentsNames = options.compiledFunctionArgumentsNames;52		if (options.compiledFunctionArgumentsValues) this.compiledFunctionArgumentsValues = options.compiledFunctionArgumentsValues;53		if (vmOptions) this.primitives = vm.runInContext("({ Object, Proxy, Reflect })", vmOptions.context);54		else this.primitives = {55			Object,56			Proxy,57			Reflect58		};59	}60	convertIdToImportUrl(id) {61		// TODO: vitest returns paths for external modules, but Vite returns file://62		// REMOVE WHEN VITE 6 SUPPORT IS OVER63		// unfortunately, there is a bug in Vite where ID is resolved incorrectly, so we can't return files until the fix is merged64		// https://github.com/vitejs/vite/pull/2044965		if (!isWindows || isBuiltin(id) || /^(?:node:|data:|http:|https:|file:)/.test(id)) return id;66		const [filepath, query] = id.split("?");67		if (query) return `${pathToFileURL(filepath).toString()}?${query}`;68		return pathToFileURL(filepath).toString();69	}70	async runExternalModule(id) {71		if (id in this.stubs) return this.stubs[id];72		const file = this.convertIdToImportUrl(id);73		const importer = (this._evaluatedModules?.getModuleById(id)?.importers)?.values().next().value;74		const filename = id.startsWith("file://") ? fileURLToPath(id) : id;75		const finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(filename, {76			startOffset: 0,77			external: true,78			importer79		});80		const namespace = await this._otel.$("vitest.module.external", { attributes: { "code.file.path": file } }, () => this.vm ? this.vm.externalModulesExecutor.import(file) : import(file)).finally(() => {81			this.options.moduleExecutionInfo?.set(filename, finishModuleExecutionInfo());82		});83		if (!this.shouldInterop(file, namespace)) return namespace;84		const { mod, defaultExport } = interopModule(namespace);85		const { Proxy, Reflect } = this.primitives;86		return new Proxy(mod, {87			get(mod, prop) {88				if (prop === "default") return defaultExport;89				return mod[prop] ?? defaultExport?.[prop];90			},91			has(mod, prop) {92				if (prop === "default") return defaultExport !== void 0;93				return prop in mod || defaultExport && prop in defaultExport;94			},95			getOwnPropertyDescriptor(mod, prop) {96				const descriptor = Reflect.getOwnPropertyDescriptor(mod, prop);97				if (descriptor) return descriptor;98				if (prop === "default" && defaultExport !== void 0) return {99					value: defaultExport,100					enumerable: true,101					configurable: true102				};103			}104		});105	}106	async runInlinedModule(context, code, module) {107		return this._otel.$("vitest.module.inline", (span) => this._runInlinedModule(context, code, module, span));108	}109	_createCJSGlobals(context, module, span) {110		const { Reflect, Proxy, Object } = this.primitives;111		const exportsObject = context[ssrModuleExportsKey];112		const SYMBOL_NOT_DEFINED = Symbol("not defined");113		let moduleExports = SYMBOL_NOT_DEFINED;114		// this proxy is triggered only on exports.{name} and module.exports access115		// inside the module itself. imported module is always "exports"116		const cjsExports = new Proxy(exportsObject, {117			get: (target, p, receiver) => {118				if (Reflect.has(target, p)) return Reflect.get(target, p, receiver);119				return Reflect.get(Object.prototype, p, receiver);120			},121			getPrototypeOf: () => Object.prototype,122			set: (_, p, value) => {123				span.addEvent(`cjs export proxy is triggered for ${String(p)}`);124				// treat "module.exports =" the same as "exports.default =" to not have nested "default.default",125				// so "exports.default" becomes the actual module126				if (p === "default" && this.shouldInterop(module.file, { default: value }) && cjsExports !== value) {127					span.addEvent("`exports.default` is assigned, copying values");128					exportAll(cjsExports, value);129					exportsObject.default = value;130					return true;131				}132				if (!Reflect.has(exportsObject, "default")) exportsObject.default = {};133				// returns undefined, when accessing named exports, if default is not an object134				// but is still present inside hasOwnKeys, this is Node behaviour for CJS135				if (moduleExports !== SYMBOL_NOT_DEFINED && isPrimitive(moduleExports)) {136					span.addEvent(`\`exports.${String(p)}\` is assigned, but module.exports is a primitive. assigning "undefined" values instead to comply with ESM`);137					defineExport(exportsObject, p, () => void 0);138					return true;139				}140				if (!isPrimitive(exportsObject.default)) exportsObject.default[p] = value;141				if (p !== "default") defineExport(exportsObject, p, () => value);142				return true;143			}144		});145		return {146			exports: cjsExports,147			module: {148				set exports(value) {149					span.addEvent("`module.exports` is assigned directly, copying all properties to `exports`");150					exportAll(cjsExports, value);151					exportsObject.default = value;152					moduleExports = value;153				},154				get exports() {155					return cjsExports;156				}157			},158			require: this.createRequire(context[ssrImportMetaKey].url),159			__filename: context[ssrImportMetaKey].filename,160			__dirname: context[ssrImportMetaKey].dirname161		};162	}163	async _runInlinedModule(context, code, module, span) {164		const meta = context[ssrImportMetaKey];165		meta.env = this.env;166		if (this.options.getCurrentTestFilepath?.() === module.file) {167			const globalNamespace = this.vm?.context || globalThis;168			Object.defineProperty(meta, "vitest", { get: () => globalNamespace.__vitest_index__ });169		}170		span.setAttribute("code.file.path", meta.filename);171		const argumentsList = [172			ssrModuleExportsKey,173			ssrImportMetaKey,174			ssrImportKey,175			ssrDynamicImportKey,176			ssrExportAllKey,177			"__vite_ssr_exportName__"178		];179		const cjsGlobals = this._createCJSGlobals(context, module, span);180		argumentsList.push(181			// TODO@discuss deprecate in Vitest 5, remove in Vitest 6(?)182			// backwards compat for vite-node183			"__filename",184			"__dirname",185			"module",186			"exports",187			"require"188		);189		if (this.compiledFunctionArgumentsNames) argumentsList.push(...this.compiledFunctionArgumentsNames);190		span.setAttribute("vitest.module.arguments", argumentsList);191		// add 'use strict' since ESM enables it by default192		const codeDefinition = `'use strict';async (${argumentsList.join(",")})=>{{`;193		const wrappedCode = `${codeDefinition}${code}\n}}`;194		const options = {195			filename: module.id.startsWith("mock:") ? module.id.slice(5) : module.id,196			lineOffset: 0,197			columnOffset: -codeDefinition.length198		};199		// this will always be 1 element because it's cached after load200		const importer = module.importers.values().next().value;201		const finishModuleExecutionInfo = this.debug.startCalculateModuleExecutionInfo(options.filename, {202			startOffset: codeDefinition.length,203			importer204		});205		try {206			await (this.vm ? vm.runInContext(wrappedCode, this.vm.context, options) : vm.runInThisContext(wrappedCode, options))(207				context[ssrModuleExportsKey],208				context[ssrImportMetaKey],209				context[ssrImportKey],210				context[ssrDynamicImportKey],211				context[ssrExportAllKey],212				// vite 7 support, remove when vite 7+ is supported213				context.__vite_ssr_exportName__ || ((name, getter) => Object.defineProperty(context[ssrModuleExportsKey], name, {214					enumerable: true,215					configurable: true,216					get: getter217				})),218				cjsGlobals.__filename,219				cjsGlobals.__dirname,220				cjsGlobals.module,221				cjsGlobals.exports,222				cjsGlobals.require,223				...this.compiledFunctionArgumentsValues224			);225		} finally {226			// moduleExecutionInfo needs to use Node filename instead of the normalized one227			// because we rely on this behaviour in coverage-v8, for example228			this.options.moduleExecutionInfo?.set(options.filename, finishModuleExecutionInfo());229		}230	}231	createRequire(url) {232		if (url.startsWith("data:")) {233			const _require = (id) => {234				throw new SyntaxError(`require() is not supported in virtual modules. Trying to call require("${id}") in ${url}`);235			};236			_require.resolve = _require;237			return _require;238		}239		return this.vm ? this.vm.externalModulesExecutor.createRequire(url) : createRequire(url);240	}241	shouldInterop(path, mod) {242		if (this.options.interopDefault === false) return false;243		// never interop ESM modules244		// TODO: should also skip for `.js` with `type="module"`245		return !path.endsWith(".mjs") && "default" in mod;246	}247}248function createImportMetaEnvProxy() {249	// packages/vitest/src/node/plugins/index.ts:146250	const booleanKeys = [251		"DEV",252		"PROD",253		"SSR"254	];255	return new Proxy(process.env, {256		get(_, key) {257			if (typeof key !== "string") return;258			if (booleanKeys.includes(key)) return !!process.env[key];259			return process.env[key];260		},261		set(_, key, value) {262			if (typeof key !== "string") return true;263			if (booleanKeys.includes(key)) process.env[key] = value ? "1" : "";264			else process.env[key] = value;265			return true;266		}267	});268}269function updateStyle(id, css) {270	if (typeof document === "undefined") return;271	const element = document.querySelector(`[data-vite-dev-id="${id}"]`);272	if (element) {273		element.textContent = css;274		return;275	}276	const head = document.querySelector("head");277	const style = document.createElement("style");278	style.setAttribute("type", "text/css");279	style.setAttribute("data-vite-dev-id", id);280	style.textContent = css;281	head?.appendChild(style);282}283function removeStyle(id) {284	if (typeof document === "undefined") return;285	const sheet = document.querySelector(`[data-vite-dev-id="${id}"]`);286	if (sheet) document.head.removeChild(sheet);287}288const defaultClientStub = {289	injectQuery: (id) => id,290	createHotContext: () => {291		return {292			accept: () => {},293			prune: () => {},294			dispose: () => {},295			decline: () => {},296			invalidate: () => {},297			on: () => {},298			send: () => {}299		};300	},301	updateStyle: () => {},302	removeStyle: () => {}303};304function getDefaultRequestStubs(context) {305	if (!context) {306		const clientStub = {307			...defaultClientStub,308			updateStyle,309			removeStyle310		};311		return { "/@vite/client": clientStub };312	}313	const clientStub = vm.runInContext(`(defaultClient) => ({ ...defaultClient, updateStyle: ${updateStyle.toString()}, removeStyle: ${removeStyle.toString()} })`, context)(defaultClientStub);314	return { "/@vite/client": clientStub };315}316function exportAll(exports$1, sourceModule) {317	// #1120 when a module exports itself it causes318	// call stack error319	if (exports$1 === sourceModule) return;320	if (isPrimitive(sourceModule) || Array.isArray(sourceModule) || sourceModule instanceof Promise) return;321	for (const key in sourceModule) if (key !== "default" && !(key in exports$1)) try {322		defineExport(exports$1, key, () => sourceModule[key]);323	} catch {}324}325// keep consistency with Vite on how exports are defined326function defineExport(exports$1, key, value) {327	Object.defineProperty(exports$1, key, {328		enumerable: true,329		configurable: true,330		get: value331	});332}333function isPrimitive(v) {334	return !(typeof v === "object" || typeof v === "function") || v == null;335}336function interopModule(mod) {337	if (isPrimitive(mod)) return {338		mod: { default: mod },339		defaultExport: mod340	};341	let defaultExport = "default" in mod ? mod.default : mod;342	if (!isPrimitive(defaultExport) && "__esModule" in defaultExport) {343		mod = defaultExport;344		if ("default" in defaultExport) defaultExport = defaultExport.default;345	}346	return {347		mod,348		defaultExport349	};350}351const VALID_ID_PREFIX = `/@id/`;352const NULL_BYTE_PLACEHOLDER = `__x00__`;353function wrapId(id) {354	return id.startsWith(VALID_ID_PREFIX) ? id : VALID_ID_PREFIX + id.replace("\0", NULL_BYTE_PLACEHOLDER);355}356function unwrapId(id) {357	return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, "\0") : id;358}359 360export { VitestModuleEvaluator, createImportMetaEnvProxy, getDefaultRequestStubs, isPrimitive, unwrapId, wrapId };361 
Brunobkr/llama.cpp_AlgMor24_github · Team Ai