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.
03.1k
1/** @import { Effect, Source, TemplateNode, } from '#client' */2import {3 BOUNDARY_EFFECT,4 DIRTY,5 EFFECT_PRESERVED,6 EFFECT_TRANSPARENT,7 MAYBE_DIRTY8} from '#client/constants';9import { HYDRATION_START_ELSE, HYDRATION_START_FAILED } from '../../../../constants.js';10import { component_context, set_component_context } from '../../context.js';11import { handle_error, invoke_error_boundary } from '../../error-handling.js';12import {13 block,14 branch,15 destroy_effect,16 move_effect,17 pause_effect18} from '../../reactivity/effects.js';19import {20 active_effect,21 active_reaction,22 get,23 set_active_effect,24 set_active_reaction25} from '../../runtime.js';26import {27 hydrate_next,28 hydrate_node,29 hydrating,30 next,31 skip_nodes,32 set_hydrate_node33} from '../hydration.js';34import { queue_micro_task } from '../task.js';35import * as e from '../../errors.js';36import * as w from '../../warnings.js';37import { DEV } from 'esm-env';38import { Batch, current_batch } from '../../reactivity/batch.js';39import { internal_set, source } from '../../reactivity/sources.js';40import { tag } from '../../dev/tracing.js';41import { createSubscriber } from '../../../../reactivity/create-subscriber.js';42import { create_text } from '../operations.js';43import { defer_effect } from '../../reactivity/utils.js';44 45/**46 * @typedef {{47 * onerror?: ((error: unknown, reset: () => void) => void) | null;48 * failed?: ((anchor: Node, error: () => unknown, reset: () => () => void) => void) | null;49 * pending?: ((anchor: Node) => void) | null;50 * }} BoundaryProps51 */52 53var flags = EFFECT_TRANSPARENT | EFFECT_PRESERVED;54 55/**56 * @param {TemplateNode} node57 * @param {BoundaryProps} props58 * @param {((anchor: Node) => void)} children59 * @param {((error: unknown) => unknown) | undefined} [transform_error]60 * @returns {void}61 */62export function boundary(node, props, children, transform_error) {63 new Boundary(node, props, children, transform_error);64}65 66export class Boundary {67 /** @type {Boundary | null} */68 parent;69 70 is_pending = false;71 72 /**73 * API-level transformError transform function. Transforms errors before they reach the `failed` snippet.74 * Inherited from parent boundary, or defaults to identity.75 * @type {(error: unknown) => unknown}76 */77 transform_error;78 79 /** @type {TemplateNode} */80 #anchor;81 82 /** @type {TemplateNode | null} */83 #hydrate_open = hydrating ? hydrate_node : null;84 85 /** @type {BoundaryProps} */86 #props;87 88 /** @type {((anchor: Node) => void)} */89 #children;90 91 /** @type {Effect} */92 #effect;93 94 /** @type {Effect | null} */95 #main_effect = null;96 97 /** @type {Effect | null} */98 #pending_effect = null;99 100 /** @type {Effect | null} */101 #failed_effect = null;102 103 /** @type {DocumentFragment | null} */104 #offscreen_fragment = null;105 106 #local_pending_count = 0;107 #pending_count = 0;108 #pending_count_update_queued = false;109 110 /** @type {Set<Effect>} */111 #dirty_effects = new Set();112 113 /** @type {Set<Effect>} */114 #maybe_dirty_effects = new Set();115 116 /**117 * A source containing the number of pending async deriveds/expressions.118 * Only created if `$effect.pending()` is used inside the boundary,119 * otherwise updating the source results in needless `Batch.ensure()`120 * calls followed by no-op flushes121 * @type {Source<number> | null}122 */123 #effect_pending = null;124 125 #effect_pending_subscriber = createSubscriber(() => {126 this.#effect_pending = source(this.#local_pending_count);127 128 if (DEV) {129 tag(this.#effect_pending, '$effect.pending()');130 }131 132 return () => {133 this.#effect_pending = null;134 };135 });136 137 /**138 * @param {TemplateNode} node139 * @param {BoundaryProps} props140 * @param {((anchor: Node) => void)} children141 * @param {((error: unknown) => unknown) | undefined} [transform_error]142 */143 constructor(node, props, children, transform_error) {144 this.#anchor = node;145 this.#props = props;146 147 this.#children = (anchor) => {148 var effect = /** @type {Effect} */ (active_effect);149 150 effect.b = this;151 effect.f |= BOUNDARY_EFFECT;152 153 children(anchor);154 };155 156 this.parent = /** @type {Effect} */ (active_effect).b;157 158 // Inherit transform_error from parent boundary, or use the provided one, or default to identity159 this.transform_error = transform_error ?? this.parent?.transform_error ?? ((e) => e);160 161 this.#effect = block(() => {162 if (hydrating) {163 const comment = /** @type {Comment} */ (this.#hydrate_open);164 hydrate_next();165 166 const server_rendered_pending = comment.data === HYDRATION_START_ELSE;167 const server_rendered_failed = comment.data.startsWith(HYDRATION_START_FAILED);168 169 if (server_rendered_failed) {170 // Server rendered the failed snippet - hydrate it.171 // The serialized error is embedded in the comment: <!--[?<json>-->172 const serialized_error = JSON.parse(comment.data.slice(HYDRATION_START_FAILED.length));173 this.#hydrate_failed_content(serialized_error);174 } else if (server_rendered_pending) {175 this.#hydrate_pending_content();176 } else {177 this.#hydrate_resolved_content();178 }179 } else {180 this.#render();181 }182 }, flags);183 184 if (hydrating) {185 this.#anchor = hydrate_node;186 }187 }188 189 #hydrate_resolved_content() {190 try {191 this.#main_effect = branch(() => this.#children(this.#anchor));192 } catch (error) {193 this.error(error);194 }195 }196 197 /**198 * @param {unknown} error The deserialized error from the server's hydration comment199 */200 #hydrate_failed_content(error) {201 const failed = this.#props.failed;202 if (!failed) return;203 204 this.#failed_effect = branch(() => {205 failed(206 this.#anchor,207 () => error,208 () => () => {}209 );210 });211 }212 213 #hydrate_pending_content() {214 const pending = this.#props.pending;215 if (!pending) return;216 217 this.is_pending = true;218 this.#pending_effect = branch(() => pending(this.#anchor));219 220 queue_micro_task(() => {221 var fragment = (this.#offscreen_fragment = document.createDocumentFragment());222 var anchor = create_text();223 224 fragment.append(anchor);225 226 this.#main_effect = this.#run(() => {227 return branch(() => this.#children(anchor));228 });229 230 if (this.#pending_count === 0) {231 this.#anchor.before(fragment);232 this.#offscreen_fragment = null;233 234 pause_effect(/** @type {Effect} */ (this.#pending_effect), () => {235 this.#pending_effect = null;236 });237 238 this.#resolve(/** @type {Batch} */ (current_batch));239 }240 });241 }242 243 #render() {244 try {245 this.is_pending = this.has_pending_snippet();246 this.#pending_count = 0;247 this.#local_pending_count = 0;248 249 this.#main_effect = branch(() => {250 this.#children(this.#anchor);251 });252 253 if (this.#pending_count > 0) {254 var fragment = (this.#offscreen_fragment = document.createDocumentFragment());255 move_effect(this.#main_effect, fragment);256 257 const pending = /** @type {(anchor: Node) => void} */ (this.#props.pending);258 this.#pending_effect = branch(() => pending(this.#anchor));259 } else {260 this.#resolve(/** @type {Batch} */ (current_batch));261 }262 } catch (error) {263 this.error(error);264 }265 }266 267 /**268 * @param {Batch} batch269 */270 #resolve(batch) {271 this.is_pending = false;272 273 // any effects that were previously deferred should be transferred274 // to the batch, which will flush in the next microtask275 batch.transfer_effects(this.#dirty_effects, this.#maybe_dirty_effects);276 }277 278 /**279 * Defer an effect inside a pending boundary until the boundary resolves280 * @param {Effect} effect281 */282 defer_effect(effect) {283 defer_effect(effect, this.#dirty_effects, this.#maybe_dirty_effects);284 }285 286 /**287 * Returns `false` if the effect exists inside a boundary whose pending snippet is shown288 * @returns {boolean}289 */290 is_rendered() {291 return !this.is_pending && (!this.parent || this.parent.is_rendered());292 }293 294 has_pending_snippet() {295 return !!this.#props.pending;296 }297 298 /**299 * @template T300 * @param {() => T} fn301 */302 #run(fn) {303 var previous_effect = active_effect;304 var previous_reaction = active_reaction;305 var previous_ctx = component_context;306 307 set_active_effect(this.#effect);308 set_active_reaction(this.#effect);309 set_component_context(this.#effect.ctx);310 311 try {312 Batch.ensure();313 return fn();314 } catch (e) {315 handle_error(e);316 return null;317 } finally {318 set_active_effect(previous_effect);319 set_active_reaction(previous_reaction);320 set_component_context(previous_ctx);321 }322 }323 324 /**325 * Updates the pending count associated with the currently visible pending snippet,326 * if any, such that we can replace the snippet with content once work is done327 * @param {1 | -1} d328 * @param {Batch} batch329 */330 #update_pending_count(d, batch) {331 if (!this.has_pending_snippet()) {332 if (this.parent) {333 this.parent.#update_pending_count(d, batch);334 }335 336 // if there's no parent, we're in a scope with no pending snippet337 return;338 }339 340 this.#pending_count += d;341 342 if (this.#pending_count === 0) {343 this.#resolve(batch);344 345 if (this.#pending_effect) {346 pause_effect(this.#pending_effect, () => {347 this.#pending_effect = null;348 });349 }350 351 if (this.#offscreen_fragment) {352 this.#anchor.before(this.#offscreen_fragment);353 this.#offscreen_fragment = null;354 }355 }356 }357 358 /**359 * Update the source that powers `$effect.pending()` inside this boundary,360 * and controls when the current `pending` snippet (if any) is removed.361 * Do not call from inside the class362 * @param {1 | -1} d363 * @param {Batch} batch364 */365 update_pending_count(d, batch) {366 this.#update_pending_count(d, batch);367 368 this.#local_pending_count += d;369 370 if (!this.#effect_pending || this.#pending_count_update_queued) return;371 this.#pending_count_update_queued = true;372 373 queue_micro_task(() => {374 this.#pending_count_update_queued = false;375 if (this.#effect_pending) {376 internal_set(this.#effect_pending, this.#local_pending_count);377 }378 });379 }380 381 get_effect_pending() {382 this.#effect_pending_subscriber();383 return get(/** @type {Source<number>} */ (this.#effect_pending));384 }385 386 /** @param {unknown} error */387 error(error) {388 // If we have nothing to capture the error, or if we hit an error while389 // rendering the fallback, re-throw for another boundary to handle390 if (!this.#props.onerror && !this.#props.failed) {391 throw error;392 }393 394 if (current_batch?.is_fork) {395 if (this.#main_effect) current_batch.skip_effect(this.#main_effect);396 if (this.#pending_effect) current_batch.skip_effect(this.#pending_effect);397 if (this.#failed_effect) current_batch.skip_effect(this.#failed_effect);398 399 current_batch.oncommit(() => {400 this.#handle_error(error);401 });402 } else {403 this.#handle_error(error);404 }405 }406 407 /**408 * @param {unknown} error409 */410 #handle_error(error) {411 if (this.#main_effect) {412 destroy_effect(this.#main_effect);413 this.#main_effect = null;414 }415 416 if (this.#pending_effect) {417 destroy_effect(this.#pending_effect);418 this.#pending_effect = null;419 }420 421 if (this.#failed_effect) {422 destroy_effect(this.#failed_effect);423 this.#failed_effect = null;424 }425 426 if (hydrating) {427 set_hydrate_node(/** @type {TemplateNode} */ (this.#hydrate_open));428 next();429 set_hydrate_node(skip_nodes());430 }431 432 var onerror = this.#props.onerror;433 let failed = this.#props.failed;434 var did_reset = false;435 var calling_on_error = false;436 437 const reset = () => {438 if (did_reset) {439 w.svelte_boundary_reset_noop();440 return;441 }442 443 did_reset = true;444 445 if (calling_on_error) {446 e.svelte_boundary_reset_onerror();447 }448 449 if (this.#failed_effect !== null) {450 pause_effect(this.#failed_effect, () => {451 this.#failed_effect = null;452 });453 }454 455 this.#run(() => {456 this.#render();457 });458 };459 460 /** @param {unknown} transformed_error */461 const handle_error_result = (transformed_error) => {462 try {463 calling_on_error = true;464 onerror?.(transformed_error, reset);465 calling_on_error = false;466 } catch (error) {467 invoke_error_boundary(error, this.#effect && this.#effect.parent);468 }469 470 if (failed) {471 this.#failed_effect = this.#run(() => {472 try {473 return branch(() => {474 // errors in `failed` snippets cause the boundary to error again475 // TODO Svelte 6: revisit this decision, most likely better to go to parent boundary instead476 var effect = /** @type {Effect} */ (active_effect);477 478 effect.b = this;479 effect.f |= BOUNDARY_EFFECT;480 481 failed(482 this.#anchor,483 () => transformed_error,484 () => reset485 );486 });487 } catch (error) {488 invoke_error_boundary(error, /** @type {Effect} */ (this.#effect.parent));489 return null;490 }491 });492 }493 };494 495 queue_micro_task(() => {496 // Run the error through the API-level transformError transform (e.g. SvelteKit's handleError)497 /** @type {unknown} */498 var result;499 try {500 result = this.transform_error(error);501 } catch (e) {502 invoke_error_boundary(e, this.#effect && this.#effect.parent);503 return;504 }505 506 if (507 result !== null &&508 typeof result === 'object' &&509 typeof (/** @type {any} */ (result).then) === 'function'510 ) {511 // transformError returned a Promise — wait for it512 /** @type {any} */ (result).then(513 handle_error_result,514 /** @param {unknown} e */515 (e) => invoke_error_boundary(e, this.#effect && this.#effect.parent)516 );517 } else {518 // Synchronous result — handle immediately519 handle_error_result(result);520 }521 });522 }523}524 525export function pending() {526 if (active_effect === null) {527 e.effect_pending_outside_reaction();528 }529 530 var boundary = active_effect.b;531 532 if (boundary === null) {533 return 0; // TODO eventually we will need this to be global534 }535 536 return boundary.get_effect_pending();537}538 