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 { Derived, Effect, Reaction, Source, Value } from '#client' */2import { DEV } from 'esm-env';3import { get_descriptors, get_prototype_of, includes, index_of } from '../shared/utils.js';4import {5 destroy_block_effect_children,6 destroy_effect_children,7 effect_tracking,8 execute_effect_teardown9} from './reactivity/effects.js';10import {11 DIRTY,12 MAYBE_DIRTY,13 CLEAN,14 DERIVED,15 DESTROYED,16 BRANCH_EFFECT,17 STATE_SYMBOL,18 BLOCK_EFFECT,19 ROOT_EFFECT,20 CONNECTED,21 REACTION_IS_UPDATING,22 STALE_REACTION,23 ERROR_VALUE,24 WAS_MARKED,25 MANAGED_EFFECT,26 REACTION_RAN27} from './constants.js';28import { old_values } from './reactivity/sources.js';29import {30 reactivity_loss_tracker,31 execute_derived,32 freeze_derived_effects,33 recent_async_deriveds,34 unfreeze_derived_effects,35 update_derived36} from './reactivity/deriveds.js';37import { async_mode_flag, tracing_mode_flag } from '../flags/index.js';38import { tracing_expressions } from './dev/tracing.js';39import { get_error } from '../shared/dev.js';40import {41 component_context,42 dev_current_component_function,43 dev_stack,44 is_runes,45 set_component_context,46 set_dev_current_component_function,47 set_dev_stack48} from './context.js';49import {50 Batch,51 batch_values,52 current_batch,53 flushSync,54 schedule_effect55} from './reactivity/batch.js';56import { handle_error } from './error-handling.js';57import { UNINITIALIZED } from '../../constants.js';58import { captured_signals } from './legacy.js';59import { without_reactive_context } from './dom/elements/bindings/shared.js';60import { set_signal_status, update_derived_status } from './reactivity/status.js';61import * as w from './warnings.js';62 63let is_updating_effect = false;64 65export let is_destroying_effect = false;66 67/** @param {boolean} value */68export function set_is_destroying_effect(value) {69 is_destroying_effect = value;70}71 72/** @type {null | Reaction} */73export let active_reaction = null;74 75export let untracking = false;76 77/** @param {null | Reaction} reaction */78export function set_active_reaction(reaction) {79 active_reaction = reaction;80}81 82/** @type {null | Effect} */83export let active_effect = null;84 85/** @param {null | Effect} effect */86export function set_active_effect(effect) {87 active_effect = effect;88}89 90/**91 * When sources are created within a reaction, reading and writing92 * them within that reaction should not cause a re-run93 * @type {null | Set<Source>}94 */95export let current_sources = null;96 97/** @param {Value} value */98export function push_reaction_value(value) {99 if (active_reaction !== null && (!async_mode_flag || (active_reaction.f & DERIVED) !== 0)) {100 (current_sources ??= new Set()).add(value);101 }102}103 104/**105 * The dependencies of the reaction that is currently being executed. In many cases,106 * the dependencies are unchanged between runs, and so this will be `null` unless107 * and until a new dependency is accessed — we track this via `skipped_deps`108 * @type {null | Value[]}109 */110export let new_deps = null;111 112export let skipped_deps = 0;113 114/**115 * Tracks writes that the effect it's executed in doesn't listen to yet,116 * so that the dependency can be added to the effect later on if it then reads it117 * @type {null | Source[]}118 */119export let untracked_writes = null;120 121/** @param {null | Source[]} value */122export function set_untracked_writes(value) {123 untracked_writes = value;124}125 126/**127 * @type {number} Used by sources and deriveds for handling updates.128 * Version starts from 1 so that unowned deriveds differentiate between a created effect and a run one for tracing129 **/130export let write_version = 1;131 132/** @type {number} Used to version each read of a source of derived to avoid duplicating depedencies inside a reaction */133let read_version = 0;134 135export let update_version = read_version;136 137/** @param {number} value */138export function set_update_version(value) {139 update_version = value;140}141 142export function increment_write_version() {143 return ++write_version;144}145 146/**147 * Determines whether a derived or effect is dirty.148 * If it is MAYBE_DIRTY, will set the status to CLEAN149 * @param {Reaction} reaction150 * @returns {boolean}151 */152export function is_dirty(reaction) {153 var flags = reaction.f;154 155 if ((flags & DIRTY) !== 0) {156 return true;157 }158 159 if (flags & DERIVED) {160 reaction.f &= ~WAS_MARKED;161 }162 163 if ((flags & MAYBE_DIRTY) !== 0) {164 var dependencies = /** @type {Value[]} */ (reaction.deps);165 var length = dependencies.length;166 167 for (var i = 0; i < length; i++) {168 var dependency = dependencies[i];169 170 if (is_dirty(/** @type {Derived} */ (dependency))) {171 update_derived(/** @type {Derived} */ (dependency));172 }173 174 if (dependency.wv > reaction.wv) {175 return true;176 }177 }178 179 if (180 (flags & CONNECTED) !== 0 &&181 // During time traveling we don't want to reset the status so that182 // traversal of the graph in the other batches still happens183 batch_values === null184 ) {185 set_signal_status(reaction, CLEAN);186 }187 }188 189 return false;190}191 192/**193 * @param {Value} signal194 * @param {Effect} effect195 * @param {boolean} [root]196 */197function schedule_possible_effect_self_invalidation(signal, effect, root = true) {198 var reactions = signal.reactions;199 if (reactions === null) return;200 201 if (!async_mode_flag && current_sources !== null && current_sources.has(signal)) {202 return;203 }204 205 for (var i = 0; i < reactions.length; i++) {206 var reaction = reactions[i];207 208 if ((reaction.f & DERIVED) !== 0) {209 schedule_possible_effect_self_invalidation(/** @type {Derived} */ (reaction), effect, false);210 } else if (effect === reaction) {211 if (root) {212 set_signal_status(reaction, DIRTY);213 } else if ((reaction.f & CLEAN) !== 0) {214 set_signal_status(reaction, MAYBE_DIRTY);215 }216 schedule_effect(/** @type {Effect} */ (reaction));217 }218 }219}220 221/** @param {Reaction} reaction */222export function update_reaction(reaction) {223 var previous_deps = new_deps;224 var previous_skipped_deps = skipped_deps;225 var previous_untracked_writes = untracked_writes;226 var previous_reaction = active_reaction;227 var previous_sources = current_sources;228 var previous_component_context = component_context;229 var previous_untracking = untracking;230 var previous_update_version = update_version;231 232 var flags = reaction.f;233 234 new_deps = /** @type {null | Value[]} */ (null);235 skipped_deps = 0;236 untracked_writes = null;237 active_reaction = (flags & (BRANCH_EFFECT | ROOT_EFFECT)) === 0 ? reaction : null;238 239 current_sources = null;240 set_component_context(reaction.ctx);241 untracking = false;242 update_version = ++read_version;243 244 if (reaction.ac !== null) {245 without_reactive_context(() => {246 /** @type {AbortController} */ (reaction.ac).abort(STALE_REACTION);247 });248 249 reaction.ac = null;250 }251 252 try {253 reaction.f |= REACTION_IS_UPDATING;254 var fn = /** @type {Function} */ (reaction.fn);255 var result = fn();256 reaction.f |= REACTION_RAN;257 var deps = reaction.deps;258 259 // Don't remove reactions during fork;260 // they must remain for when fork is discarded261 var is_fork = current_batch?.is_fork;262 263 if (new_deps !== null) {264 var i;265 266 if (!is_fork) {267 remove_reactions(reaction, skipped_deps);268 }269 270 if (deps !== null && skipped_deps > 0) {271 deps.length = skipped_deps + new_deps.length;272 for (i = 0; i < new_deps.length; i++) {273 deps[skipped_deps + i] = new_deps[i];274 }275 } else {276 reaction.deps = deps = new_deps;277 }278 279 if (effect_tracking() && (reaction.f & CONNECTED) !== 0) {280 for (i = skipped_deps; i < deps.length; i++) {281 (deps[i].reactions ??= []).push(reaction);282 }283 }284 } else if (!is_fork && deps !== null && skipped_deps < deps.length) {285 remove_reactions(reaction, skipped_deps);286 deps.length = skipped_deps;287 }288 289 // If we're inside an effect and we have untracked writes, then we need to290 // ensure that if any of those untracked writes result in re-invalidation291 // of the current effect, then that happens accordingly292 if (293 is_runes() &&294 untracked_writes !== null &&295 !untracking &&296 deps !== null &&297 (reaction.f & (DERIVED | MAYBE_DIRTY | DIRTY)) === 0298 ) {299 for (i = 0; i < /** @type {Source[]} */ (untracked_writes).length; i++) {300 schedule_possible_effect_self_invalidation(301 untracked_writes[i],302 /** @type {Effect} */ (reaction)303 );304 }305 }306 307 // If we are returning to an previous reaction then308 // we need to increment the read version to ensure that309 // any dependencies in this reaction aren't marked with310 // the same version311 if (previous_reaction !== null && previous_reaction !== reaction) {312 read_version++;313 314 // update the `rv` of the previous reaction's deps — both existing and new —315 // so that they are not added again316 if (previous_reaction.deps !== null) {317 for (let i = 0; i < previous_skipped_deps; i += 1) {318 previous_reaction.deps[i].rv = read_version;319 }320 }321 322 if (previous_deps !== null) {323 for (const dep of previous_deps) {324 dep.rv = read_version;325 }326 }327 328 if (untracked_writes !== null) {329 if (previous_untracked_writes === null) {330 previous_untracked_writes = untracked_writes;331 } else {332 previous_untracked_writes.push(.../** @type {Source[]} */ (untracked_writes));333 }334 }335 }336 337 if ((reaction.f & ERROR_VALUE) !== 0) {338 reaction.f ^= ERROR_VALUE;339 }340 341 return result;342 } catch (error) {343 return handle_error(error);344 } finally {345 reaction.f ^= REACTION_IS_UPDATING;346 new_deps = previous_deps;347 skipped_deps = previous_skipped_deps;348 untracked_writes = previous_untracked_writes;349 active_reaction = previous_reaction;350 current_sources = previous_sources;351 set_component_context(previous_component_context);352 untracking = previous_untracking;353 update_version = previous_update_version;354 }355}356 357/**358 * @template V359 * @param {Reaction} signal360 * @param {Value<V>} dependency361 * @returns {void}362 */363function remove_reaction(signal, dependency) {364 let reactions = dependency.reactions;365 if (reactions !== null) {366 var index = index_of.call(reactions, signal);367 if (index !== -1) {368 var new_length = reactions.length - 1;369 if (new_length === 0) {370 reactions = dependency.reactions = null;371 } else {372 // Swap with last element and then remove.373 reactions[index] = reactions[new_length];374 reactions.pop();375 }376 }377 }378 379 // If the derived has no reactions, then we can disconnect it from the graph,380 // allowing it to either reconnect in the future, or be GC'd by the VM.381 if (382 reactions === null &&383 (dependency.f & DERIVED) !== 0 &&384 // Destroying a child effect while updating a parent effect can cause a dependency to appear385 // to be unused, when in fact it is used by the currently-updating parent. Checking `new_deps`386 // allows us to skip the expensive work of disconnecting and immediately reconnecting it387 (new_deps === null || !includes.call(new_deps, dependency))388 ) {389 var derived = /** @type {Derived} */ (dependency);390 391 // If we are working with a derived that is owned by an effect, then mark it as being392 // disconnected and remove the mark flag, as it cannot be reliably removed otherwise393 if ((derived.f & CONNECTED) !== 0) {394 derived.f ^= CONNECTED;395 derived.f &= ~WAS_MARKED;396 }397 398 // In a fork it's possible that a derived is executed and gets reactions, then commits, but is399 // never re-executed. This is possible when the derived is only executed once in the context400 // of a new branch which happens before fork.commit() runs. In this case, the derived still has401 // UNINITIALIZED as its value, and then when it's loosing its reactions we need to ensure it stays402 // DIRTY so it is reexecuted once someone wants its value again.403 if (derived.v !== UNINITIALIZED) {404 update_derived_status(derived);405 }406 407 // freeze any effects inside this derived408 freeze_derived_effects(derived);409 410 // Disconnect any reactions owned by this reaction411 remove_reactions(derived, 0);412 }413}414 415/**416 * @param {Reaction} signal417 * @param {number} start_index418 * @returns {void}419 */420export function remove_reactions(signal, start_index) {421 var dependencies = signal.deps;422 if (dependencies === null) return;423 424 for (var i = start_index; i < dependencies.length; i++) {425 remove_reaction(signal, dependencies[i]);426 }427}428 429/**430 * @param {Effect} effect431 * @returns {void}432 */433export function update_effect(effect) {434 var flags = effect.f;435 436 if ((flags & DESTROYED) !== 0) {437 return;438 }439 440 set_signal_status(effect, CLEAN);441 442 var previous_effect = active_effect;443 var was_updating_effect = is_updating_effect;444 445 active_effect = effect;446 is_updating_effect = true;447 448 if (DEV) {449 var previous_component_fn = dev_current_component_function;450 set_dev_current_component_function(effect.component_function);451 var previous_stack = /** @type {any} */ (dev_stack);452 // only block effects have a dev stack, keep the current one otherwise453 set_dev_stack(effect.dev_stack ?? dev_stack);454 }455 456 try {457 if ((flags & (BLOCK_EFFECT | MANAGED_EFFECT)) !== 0) {458 destroy_block_effect_children(effect);459 } else {460 destroy_effect_children(effect);461 }462 463 execute_effect_teardown(effect);464 var teardown = update_reaction(effect);465 effect.teardown = typeof teardown === 'function' ? teardown : null;466 effect.wv = write_version;467 468 // In DEV, increment versions of any sources that were written to during the effect,469 // so that they are correctly marked as dirty when the effect re-runs470 if (DEV && tracing_mode_flag && (effect.f & DIRTY) !== 0 && effect.deps !== null) {471 for (var dep of effect.deps) {472 if (dep.set_during_effect) {473 dep.wv = increment_write_version();474 dep.set_during_effect = false;475 }476 }477 }478 } finally {479 is_updating_effect = was_updating_effect;480 active_effect = previous_effect;481 482 if (DEV) {483 set_dev_current_component_function(previous_component_fn);484 set_dev_stack(previous_stack);485 }486 }487}488 489/**490 * Returns a promise that resolves once any pending state changes have been applied.491 * @returns {Promise<void>}492 */493export async function tick() {494 if (async_mode_flag) {495 return new Promise((f) => {496 // Race them against each other - in almost all cases requestAnimationFrame will fire first,497 // but e.g. in case the window is not focused or a view transition happens, requestAnimationFrame498 // will be delayed and setTimeout helps us resolve fast enough in that case499 requestAnimationFrame(() => f());500 setTimeout(() => f());501 });502 }503 504 await Promise.resolve();505 506 // By calling flushSync we guarantee that any pending state changes are applied after one tick.507 // TODO look into whether we can make flushing subsequent updates synchronously in the future.508 flushSync();509}510 511/**512 * Returns a promise that resolves once any state changes, and asynchronous work resulting from them,513 * have resolved and the DOM has been updated514 * @returns {Promise<void>}515 * @since 5.36516 */517export function settled() {518 return Batch.ensure().settled();519}520 521/**522 * @template V523 * @param {Value<V>} signal524 * @returns {V}525 */526export function get(signal) {527 var flags = signal.f;528 var is_derived = (flags & DERIVED) !== 0;529 530 captured_signals?.add(signal);531 532 // Register the dependency on the current reaction signal.533 if (active_reaction !== null && !untracking) {534 // if we're in a derived that is being read inside an _async_ derived,535 // it's possible that the effect was already destroyed. In this case,536 // we don't add the dependency, because that would create a memory leak537 var destroyed = active_effect !== null && (active_effect.f & DESTROYED) !== 0;538 539 if (!destroyed && (current_sources === null || !current_sources.has(signal))) {540 var deps = active_reaction.deps;541 542 if ((active_reaction.f & REACTION_IS_UPDATING) !== 0) {543 // we're in the effect init/update cycle544 if (signal.rv < read_version) {545 signal.rv = read_version;546 547 // If the signal is accessing the same dependencies in the same548 // order as it did last time, increment `skipped_deps`549 // rather than updating `new_deps`, which creates GC cost550 if (new_deps === null && deps !== null && deps[skipped_deps] === signal) {551 skipped_deps++;552 } else if (new_deps === null) {553 new_deps = [signal];554 } else {555 new_deps.push(signal);556 }557 }558 } else {559 // We're adding a dependency outside the init/update cycle (i.e. after an `await`).560 // We have to deduplicate deps/reactions in this case or remove_reactions could561 // disconnect deps/reactions that are actually still in use (if skip_deps says562 // "disconnect all after this index" and some of the signals are also present in563 // list prior to the cutoff index, i.e. that should be kept).564 active_reaction.deps ??= [];565 if (!includes.call(active_reaction.deps, signal)) {566 active_reaction.deps.push(signal);567 }568 569 var reactions = signal.reactions;570 571 if (reactions === null) {572 signal.reactions = [active_reaction];573 } else if (!includes.call(reactions, active_reaction)) {574 reactions.push(active_reaction);575 }576 }577 }578 }579 580 if (DEV) {581 if (582 !untracking &&583 reactivity_loss_tracker &&584 !reactivity_loss_tracker.warned &&585 (reactivity_loss_tracker.effect.f & REACTION_IS_UPDATING) === 0 &&586 !reactivity_loss_tracker.effect_deps.has(signal)587 ) {588 reactivity_loss_tracker.warned = true;589 590 w.await_reactivity_loss(/** @type {string} */ (signal.label));591 592 var trace = get_error('traced at');593 // eslint-disable-next-line no-console594 if (trace) console.warn(trace);595 }596 597 recent_async_deriveds.delete(signal);598 599 if (600 tracing_mode_flag &&601 !untracking &&602 tracing_expressions !== null &&603 active_reaction !== null &&604 tracing_expressions.reaction === active_reaction605 ) {606 // Used when mapping state between special blocks like `each`607 if (signal.trace) {608 signal.trace();609 } else {610 trace = get_error('traced at');611 612 if (trace) {613 var entry = tracing_expressions.entries.get(signal);614 615 if (entry === undefined) {616 entry = { traces: [] };617 tracing_expressions.entries.set(signal, entry);618 }619 620 var last = entry.traces[entry.traces.length - 1];621 622 // traces can be duplicated, e.g. by `snapshot` invoking both623 // both `getOwnPropertyDescriptor` and `get` traps at once624 if (trace.stack !== last?.stack) {625 entry.traces.push(trace);626 }627 }628 }629 }630 }631 632 if (is_destroying_effect && old_values.has(signal)) {633 return old_values.get(signal);634 }635 636 if (is_derived) {637 var derived = /** @type {Derived} */ (signal);638 639 if (is_destroying_effect) {640 var value = derived.v;641 642 // if the derived is dirty and has reactions, or depends on the values that just changed, re-execute643 // (a derived can be maybe_dirty due to the effect destroy removing its last reaction)644 if (645 ((derived.f & CLEAN) === 0 && derived.reactions !== null) ||646 depends_on_old_values(derived)647 ) {648 value = execute_derived(derived);649 }650 651 old_values.set(derived, value);652 653 return value;654 }655 656 // connect disconnected deriveds if we are reading them inside an effect,657 // or inside another derived that is already connected658 var should_connect =659 (derived.f & CONNECTED) === 0 &&660 !untracking &&661 active_reaction !== null &&662 (is_updating_effect || (active_reaction.f & CONNECTED) !== 0);663 664 var is_new = (derived.f & REACTION_RAN) === 0;665 666 if (is_dirty(derived)) {667 if (should_connect) {668 // set the flag before `update_derived`, so that the derived669 // is added as a reaction to its dependencies670 derived.f |= CONNECTED;671 }672 673 update_derived(derived);674 }675 676 if (should_connect && !is_new) {677 unfreeze_derived_effects(derived);678 reconnect(derived);679 }680 }681 682 if (batch_values?.has(signal)) {683 return batch_values.get(signal);684 }685 686 if ((signal.f & ERROR_VALUE) !== 0) {687 throw signal.v;688 }689 690 return signal.v;691}692 693/**694 * (Re)connect a disconnected derived, so that it is notified695 * of changes in `mark_reactions`696 * @param {Derived} derived697 */698function reconnect(derived) {699 derived.f |= CONNECTED;700 701 if (derived.deps === null) return;702 703 for (const dep of derived.deps) {704 (dep.reactions ??= []).push(derived);705 706 if ((dep.f & DERIVED) !== 0 && (dep.f & CONNECTED) === 0) {707 unfreeze_derived_effects(/** @type {Derived} */ (dep));708 reconnect(/** @type {Derived} */ (dep));709 }710 }711}712 713/** @param {Derived} derived */714function depends_on_old_values(derived) {715 if (derived.v === UNINITIALIZED) return true; // we don't know, so assume the worst716 if (derived.deps === null) return false;717 718 for (const dep of derived.deps) {719 if (old_values.has(dep)) {720 return true;721 }722 723 if ((dep.f & DERIVED) !== 0 && depends_on_old_values(/** @type {Derived} */ (dep))) {724 return true;725 }726 }727 728 return false;729}730 731/**732 * Like `get`, but checks for `undefined`. Used for `var` declarations because they can be accessed before being declared733 * @template V734 * @param {Value<V> | undefined} signal735 * @returns {V | undefined}736 */737export function safe_get(signal) {738 return signal && get(signal);739}740 741/**742 * When used inside a [`$derived`](https://svelte.dev/docs/svelte/$derived) or [`$effect`](https://svelte.dev/docs/svelte/$effect),743 * any state read inside `fn` will not be treated as a dependency.744 *745 * ```ts746 * $effect(() => {747 * // this will run when `data` changes, but not when `time` changes748 * save(data, {749 * timestamp: untrack(() => time)750 * });751 * });752 * ```753 * @template T754 * @param {() => T} fn755 * @returns {T}756 */757export function untrack(fn) {758 var previous_untracking = untracking;759 try {760 untracking = true;761 return fn();762 } finally {763 untracking = previous_untracking;764 }765}766 767/**768 * Possibly traverse an object and read all its properties so that they're all reactive in case this is `$state`.769 * Does only check first level of an object for performance reasons (heuristic should be good for 99% of all cases).770 * @param {any} value771 * @returns {void}772 */773export function deep_read_state(value) {774 if (typeof value !== 'object' || !value || value instanceof EventTarget) {775 return;776 }777 778 if (STATE_SYMBOL in value) {779 deep_read(value);780 } else if (!Array.isArray(value)) {781 for (let key in value) {782 const prop = value[key];783 if (typeof prop === 'object' && prop && STATE_SYMBOL in prop) {784 deep_read(prop);785 }786 }787 }788}789 790/**791 * Deeply traverse an object and read all its properties792 * so that they're all reactive in case this is `$state`793 * @param {any} value794 * @param {Set<any>} visited795 * @returns {void}796 */797export function deep_read(value, visited = new Set()) {798 if (799 typeof value === 'object' &&800 value !== null &&801 // We don't want to traverse DOM elements802 !(value instanceof EventTarget) &&803 !visited.has(value)804 ) {805 visited.add(value);806 // When working with a possible SvelteDate, this807 // will ensure we capture changes to it.808 if (value instanceof Date) {809 value.getTime();810 }811 for (let key in value) {812 try {813 deep_read(value[key], visited);814 } catch (e) {815 // continue816 }817 }818 const proto = get_prototype_of(value);819 if (820 proto !== Object.prototype &&821 proto !== Array.prototype &&822 proto !== Map.prototype &&823 proto !== Set.prototype &&824 proto !== Date.prototype825 ) {826 const descriptors = get_descriptors(proto);827 for (let key in descriptors) {828 const get = descriptors[key].get;829 if (get) {830 try {831 get.call(value);832 } catch (e) {833 // continue834 }835 }836 }837 }838 }839}840 