architecture/network/prune

Error raised when a sparsity-budget max-connection count cap is invalid.

architecture/network/prune/network.prune.budget.errors.ts

NetworkPruneBudgetGrowthGraceFractionError

Error raised when the sparsity-budget growth-grace fraction configuration is invalid.

NetworkPruneBudgetMaxConnectionsError

Error raised when a sparsity-budget max-connection count cap is invalid.

architecture/network/prune/network.prune.utils.types.ts

ActivePruningConfig

Normalized pruning-config shape consumed by internal helpers after boundary guards confirm that runtime options are present.

DEFAULT_PRUNE_FREQUENCY

Default prune cadence used when schedule frequency is absent or invalid.

MAX_EVOLUTIONARY_TARGET_SPARSITY

Safety cap below full sparsity to avoid degenerate zero-connection networks.

MAX_PROGRESS_FRACTION

Maximum normalized schedule progress value used by clamp logic before deriving sparsity targets inside schedule helpers.

MIN_PROGRESS_FRACTION

Minimum normalized schedule progress value used by clamp logic before deriving sparsity targets inside schedule helpers.

MIN_REMAINING_CONNECTION_COUNT

Lower bound that guarantees at least one connection remains after pruning.

PRUNING_METHOD_MAGNITUDE

Pruning method identifier for absolute-weight ranking (|w|) used by default scheduled and evolutionary pruning selection helpers.

PRUNING_METHOD_SNIP

Pruning method identifier for SNIP-like saliency ranking (|w * g| proxy).

REGROW_ATTEMPT_MULTIPLIER

Retry multiplier used to translate desired regrowth count into max attempts.

architecture/network/prune/network.prune.utils.ts

Structured and dynamic pruning utilities for networks.

Features:

Internal state fields (attached to Network through a loose internal bridge):

configureSparsityBudget

configureSparsityBudget(
  configuration: SparsityBudgetConfiguration,
): void

Configure a total-connection growth sparsity budget on one network.

The budget is expressed as an absolute cap across forward and self connections plus an optional grace fraction. Growth helpers can then prune before mutation or deny the request when the graph cannot stay within the allowed envelope.

Parameters:

Returns: Nothing.

getCurrentSparsity

getCurrentSparsity(): number

Return current sparsity relative to the captured pruning baseline connection count.

Returns: Current sparsity in the [0,1] range when baseline is available.

getSparsityBudgetSnapshot

getSparsityBudgetSnapshot(
  currentNetwork: default,
): NetworkSparsityBudgetSnapshot | undefined

Return the latest recorded sparsity-budget decision snapshot for diagnostics and telemetry.

Parameters:

Returns: Snapshot clone when one exists; otherwise undefined.

maybePrune

maybePrune(
  iteration: number,
): void

Perform scheduled pruning at a given training iteration if conditions are met.

Uses schedule fields from _pruningConfig (start, end, frequency, targetSparsity, method, and optional regrowFraction) to decide whether this iteration should prune, then removes low-ranked connections and can optionally regrow a bounded subset.

Parameters:

Returns: Nothing.

pruneToSparsity

pruneToSparsity(
  targetSparsity: number,
  method: PruningMethod,
): void

Evolutionary (generation-based) pruning toward a target sparsity baseline. Unlike maybePrune this operates immediately relative to the first invocation's connection count (stored separately as _evoInitialConnCount) and does not implement scheduling or regrowth.

Parameters:

Returns: Nothing.

architecture/network/prune/network.prune.budget.utils.ts

asSparsityBudgetProps

asSparsityBudgetProps(
  currentNetwork: default,
): NetworkSparsityBudgetProps

Interpret one network as a sparsity-budget host.

Parameters:

Returns: Runtime budget props bridge.

asSparsityBudgetRuntimeProps

asSparsityBudgetRuntimeProps(
  currentNetwork: default,
): NetworkSparsityBudgetRuntimeProps

Interpret one network as a sparsity-budget host with internal retry state.

Parameters:

Returns: Runtime budget props bridge including deny-backoff state.

clearDeniedGrowthBackoffState

clearDeniedGrowthBackoffState(
  currentNetwork: default,
): void

Reset any deny-backoff state after growth becomes viable again.

Parameters:

Returns: Nothing.

collectBudgetedConnections

collectBudgetedConnections(
  currentNetwork: default,
): default[]

Collect all live connection objects that may be pruned to free budget.

Parameters:

Returns: Forward and self connections.

configureSparsityBudget

configureSparsityBudget(
  configuration: SparsityBudgetConfiguration,
): void

Configure a total-connection growth sparsity budget on one network.

The budget is expressed as an absolute cap across forward and self connections plus an optional grace fraction. Growth helpers can then prune before mutation or deny the request when the graph cannot stay within the allowed envelope.

Parameters:

Returns: Nothing.

convertMegabytesToBytes

convertMegabytesToBytes(
  megabytes: number,
): number

Convert megabytes to bytes for runtime-heap comparisons.

Parameters:

Returns: Equivalent byte count.

countBudgetedConnections

countBudgetedConnections(
  currentNetwork: default,
): number

Count all connection objects that contribute to structural sparsity.

Parameters:

Returns: Total number of forward and self connections.

createDeniedGrowthBackoffFingerprint

createDeniedGrowthBackoffFingerprint(
  input: { allowedConnectionLimit: number; budgetConfig: { maxConnections: number; growthGraceFraction: number; method: PruningMethod; }; connectionCountBeforeDecision: number; requiredAdditionalConnections: number; triggeredSoftBudgetState: TriggeredSoftBudgetState | undefined; },
): DeniedGrowthBackoffFingerprint

Build the fingerprint used to decide whether one deny state still matches.

Parameters:

Returns: Stable fingerprint for deny-backoff reuse.

ensureGrowthBudget

ensureGrowthBudget(
  currentNetwork: default,
  requiredAdditionalConnections: number,
): boolean

Ensure enough total-connection budget remains before a growth mutation writes.

Behavior:

Parameters:

Returns: True when growth may proceed.

getSparsityBudgetSnapshot

getSparsityBudgetSnapshot(
  currentNetwork: default,
): NetworkSparsityBudgetSnapshot | undefined

Return the latest recorded sparsity-budget decision snapshot for diagnostics and telemetry.

Parameters:

Returns: Snapshot clone when one exists; otherwise undefined.

isSameDeniedGrowthFingerprint

isSameDeniedGrowthFingerprint(
  deniedGrowthBackoffState: DeniedGrowthBackoffState,
  fingerprint: DeniedGrowthBackoffFingerprint,
): boolean

Compare the current deny fingerprint against the stored backoff state.

Parameters:

Returns: True when the deny state is unchanged.

isSoftBudgetExceeded

isSoftBudgetExceeded(
  measuredBytes: number | undefined,
  configuredLimitMegabytes: number | undefined,
): boolean

Compare one runtime memory reading against a configured soft target.

Parameters:

Returns: True when the runtime is already over the configured soft target.

normalizeGrowthGraceFraction

normalizeGrowthGraceFraction(
  growthGraceFraction: number | undefined,
): number

Validate and normalize the configured growth-grace fraction.

Parameters:

Returns: Safe non-negative fraction.

normalizeMaxConnections

normalizeMaxConnections(
  maxConnections: number,
): number

Validate and normalize the configured max-connection cap.

Parameters:

Returns: Safe integer cap.

recordSparsityBudgetSnapshot

recordSparsityBudgetSnapshot(
  currentNetwork: default,
  snapshot: NetworkSparsityBudgetSnapshot,
): void

Persist the latest read-only decision snapshot.

Parameters:

Returns: Nothing.

registerDeniedGrowthBackoff

registerDeniedGrowthBackoff(
  currentNetwork: default,
  fingerprint: DeniedGrowthBackoffFingerprint,
): void

Record one evaluated deny and expand the retry window for unchanged future attempts.

Parameters:

Returns: Nothing.

resolveAllowedConnectionLimit

resolveAllowedConnectionLimit(
  budgetConfig: { maxConnections: number; growthGraceFraction: number; method: PruningMethod; },
): number

Resolve the effective connection budget including grace headroom.

Parameters:

Returns: Effective allowed connection limit.

resolveDeniedGrowthBackoffWindow

resolveDeniedGrowthBackoffWindow(
  consecutiveEvaluatedDenials: number,
): number

Resolve how many repeated requests to skip after one evaluated deny.

Parameters:

Returns: Remaining retry slots to skip before the next reevaluation.

resolveEffectiveAllowedConnectionLimit

resolveEffectiveAllowedConnectionLimit(
  allowedConnectionLimit: number,
  connectionCountBeforeDecision: number,
  triggeredSoftBudgetState: TriggeredSoftBudgetState | undefined,
): number

Tighten the effective connection cap when the runtime is already over a soft heap target.

Parameters:

Returns: Effective cap for this growth decision.

resolveTriggeredSoftBudgetState

resolveTriggeredSoftBudgetState(): TriggeredSoftBudgetState | undefined

Detect whether the current runtime heap already exceeds one active soft-memory target.

Returns: Triggered soft-budget details when one environment is over budget.

shouldSkipDeniedGrowthAttempt

shouldSkipDeniedGrowthAttempt(
  currentNetwork: default,
  fingerprint: DeniedGrowthBackoffFingerprint,
): boolean

Skip one repeated growth attempt when the network is still in the same dead-end state.

Parameters:

Returns: True when the retry should be denied without reevaluating prune work.

architecture/network/prune/network.prune.regrowth.utils.ts

buildRegrowthCandidatePair

buildRegrowthCandidatePair(
  currentNetwork: default,
): { sourceNode: default; targetNode: default; } | null

Build one random regrowth candidate pair if valid.

Parameters:

Returns: Candidate node pair or null when invalid.

buildRegrowthPlan

buildRegrowthPlan(
  context: RegrowthPlanContext,
): RegrowthPlan | null

Convert regrowth intent into a bounded execution plan.

Parameters:

Returns: A plan when regrowth is meaningful; otherwise null.

connectionAlreadyExists

connectionAlreadyExists(
  currentNetwork: default,
  sourceNode: default,
  targetNode: default,
): boolean

Check whether a connection already exists.

Parameters:

Returns: True when the edge already exists.

executeRegrowthAttempts

executeRegrowthAttempts(
  context: RegrowthExecutionContext,
): void

Execute bounded stochastic regrowth attempts.

Parameters:

Returns: Nothing.

isInvalidRegrowthPair

isInvalidRegrowthPair(
  currentNetwork: default,
  sourceNode: default,
  targetNode: default,
): boolean

Validate whether a candidate regrowth pair is acceptable.

Parameters:

Returns: True when the pair must be rejected.

maybeRunRegrowth

maybeRunRegrowth(
  currentNetwork: default,
  context: RegrowthPlanContext,
): void

Build and execute a bounded connection-regrowth plan when regrowth is enabled.

Parameters:

Returns: Nothing.

pickRandomNode

pickRandomNode(
  currentNetwork: default,
): default | undefined

Pick a random node using the network RNG.

Parameters:

Returns: Random node or undefined when the node list is empty.

shouldContinueRegrowth

shouldContinueRegrowth(
  currentNetwork: default,
  desiredRemainingConnections: number,
  attemptedRegrowthCount: number,
  maxAttempts: number,
): boolean

Decide whether another regrowth attempt is allowed.

Parameters:

Returns: True when another attempt should run.

tryRegrowConnection

tryRegrowConnection(
  currentNetwork: default,
): void

Attempt one random valid connection addition.

Parameters:

Returns: Nothing.

violatesAcyclicConstraint

violatesAcyclicConstraint(
  currentNetwork: default,
  sourceNode: default,
  targetNode: default,
): boolean

Check whether a pair violates forward-only acyclic ordering.

Parameters:

Returns: True when acyclic ordering would be violated.

architecture/network/prune/network.prune.schedule.utils.ts

alreadyPrunedThisIteration

alreadyPrunedThisIteration(
  currentIteration: number,
  currentPruningConfig: { start: number; end: number; frequency: number; targetSparsity: number; method: PruningMethod; regrowFraction: number; lastPruneIter?: number | undefined; },
): boolean

Check whether this iteration was already pruned.

Parameters:

Returns: True when pruning already happened for this iteration.

buildPruneSelection

buildPruneSelection(
  context: PruneSelectionContext,
): PruneSelectionResult

Build a connection removal selection from ranking context so pruning removes the lowest-priority edges first. This helper isolates ordering and slicing rules from orchestration code that manages structural side effects.

Parameters:

Returns: Connections selected for pruning.

buildScheduledTarget

buildScheduledTarget(
  context: ScheduledTargetContext,
  currentConnectionCount: number,
): ScheduledTargetResult

Build current scheduled pruning targets from schedule context and current connection totals for this iteration. The output combines desired remaining edges and immediate excess so callers can prune deterministically.

Parameters:

Returns: Desired remaining connections and current excess.

calculateProgressFraction

calculateProgressFraction(
  currentIteration: number,
  scheduleStart: number,
  scheduleEnd: number,
): number

Compute clamped schedule progress in the [0,1] range.

Parameters:

Returns: Clamped normalized progress.

calculateSnipSaliency

calculateSnipSaliency(
  connection: default,
): number

Compute saliency for SNIP-like ranking.

Parameters:

Returns: Saliency value used for sorting.

clamp

clamp(
  value: number,
  minimum: number,
  maximum: number,
): number

Clamp a number into an inclusive range.

Parameters:

Returns: Clamped value.

disconnectConnections

disconnectConnections(
  currentNetwork: default,
  connectionsToDisconnect: default[],
): void

Disconnect all selected connections from the network and schedule post-prune activation-pool compaction when needed. Grouping removal side effects here keeps pruning orchestration compact and consistent across pruning strategies.

Parameters:

Returns: Nothing.

getInitialConnectionBaseline

getInitialConnectionBaseline(
  currentNetwork: default,
): number | undefined

Read the scheduled-pruning baseline connection count used to compute progressive sparsity targets over time. Keeping this baseline explicit prevents schedule drift when connection totals fluctuate across pruning iterations.

Parameters:

Returns: Baseline count when captured; otherwise undefined.

getPruningConfig

getPruningConfig(
  currentNetwork: default,
): { start: number; end: number; frequency: number; targetSparsity: number; method: PruningMethod; regrowFraction: number; lastPruneIter?: number | undefined; } | undefined

Read the active pruning schedule from network internals so scheduled pruning logic can run against current runtime policy. Returning the optional config directly keeps orchestration code declarative and avoids repeated unsafe internal casts.

Parameters:

Returns: Pruning configuration when enabled; otherwise undefined.

isOutsidePruningWindow

isOutsidePruningWindow(
  currentIteration: number,
  currentPruningConfig: { start: number; end: number; frequency: number; targetSparsity: number; method: PruningMethod; regrowFraction: number; lastPruneIter?: number | undefined; },
): boolean

Check whether an iteration is outside the pruning window.

Parameters:

Returns: True when the iteration is out of range.

isScheduledPruningIteration

isScheduledPruningIteration(
  currentIteration: number,
  currentPruningConfig: { start: number; end: number; frequency: number; targetSparsity: number; method: PruningMethod; regrowFraction: number; lastPruneIter?: number | undefined; },
): boolean

Check frequency cadence for scheduled pruning.

Parameters:

Returns: True when this iteration matches the schedule cadence.

markPruneIteration

markPruneIteration(
  currentPruningConfig: { start: number; end: number; frequency: number; targetSparsity: number; method: PruningMethod; regrowFraction: number; lastPruneIter?: number | undefined; },
  currentIteration: number,
): void

Persist the iteration that last performed pruning so duplicate schedule triggers within the same step are ignored. This marker is essential for idempotent training loops that may re-enter pruning checks.

Parameters:

Returns: Nothing.

markTopologyDirty

markTopologyDirty(
  currentNetwork: default,
): void

Mark the topology cache as dirty after scheduled pruning structural updates.

Parameters:

Returns: Nothing.

rankConnectionsByMagnitude

rankConnectionsByMagnitude(
  connections: default[],
): default[]

Rank connections by absolute weight magnitude.

Parameters:

Returns: Connections sorted by ascending absolute weight.

rankConnectionsByRemovalPriority

rankConnectionsByRemovalPriority(
  connections: default[],
  method: PruningMethod,
): default[]

Route ranking to the configured pruning heuristic.

Parameters:

Returns: Connections sorted by ascending removal priority.

rankConnectionsBySnipSaliency

rankConnectionsBySnipSaliency(
  connections: default[],
): default[]

Rank connections by SNIP-like saliency approximation.

Parameters:

Returns: Connections sorted by ascending saliency.

resolveGradientMagnitude

resolveGradientMagnitude(
  connection: default,
): number

Resolve a stable gradient-magnitude proxy from connection delta statistics.

Parameters:

Returns: Absolute gradient magnitude proxy.

resolvePruningMethod

resolvePruningMethod(
  method: PruningMethod | undefined,
): PruningMethod

Normalize an optional pruning method to a concrete default value.

Parameters:

Returns: Concrete pruning method.

shouldRunScheduledPrune

shouldRunScheduledPrune(
  currentIteration: number,
  currentPruningConfig: { start: number; end: number; frequency: number; targetSparsity: number; method: PruningMethod; regrowFraction: number; lastPruneIter?: number | undefined; },
): boolean

Determine whether scheduled pruning should run at this iteration using configured window bounds and cadence guards. The decision also prevents duplicate pruning passes within the same iteration when callers retry training steps.

Parameters:

Returns: True when pruning should execute now.

architecture/network/prune/network.prune.sparsity.utils.ts

calculateSparsityFromBaseline

calculateSparsityFromBaseline(
  currentConnectionCount: number,
  baselineConnectionCount: number,
): number

Convert current connection density into a normalized sparsity ratio value.

Parameters:

Returns: Sparsity ratio in [0,1] for valid baselines.

readInitialSparsityBaseline

readInitialSparsityBaseline(
  currentNetwork: default,
): number | undefined

Read the initial connection-count baseline value used for sparsity ratio reporting.

Parameters:

Returns: Baseline connection count when available.

architecture/network/prune/network.prune.evolutionary.utils.ts

buildEvolutionaryPruneSelection

buildEvolutionaryPruneSelection(
  context: PruneSelectionContext,
): PruneSelectionResult

Build evolutionary pruning connection selection. Ranking and slicing happen in one deterministic pass so stochastic training variance does not reorder equal-score candidates across repeated pruning runs.

Parameters:

Returns: Connections selected for removal.

buildEvolutionaryTarget

buildEvolutionaryTarget(
  context: EvolutionaryTargetContext,
  currentConnectionCount: number,
): EvolutionaryTargetResult

Compute evolutionary pruning target counts. This conversion translates a normalized sparsity objective into concrete connection counts while enforcing the minimum remaining edge safety floor.

Parameters:

Returns: Desired remaining and excess connection counts.

calculateEvolutionarySnipSaliency

calculateEvolutionarySnipSaliency(
  connection: default,
): number

Compute evolutionary SNIP-like saliency for one connection.

Parameters:

Returns: Saliency score.

disconnectEvolutionaryConnections

disconnectEvolutionaryConnections(
  currentNetwork: default,
  connectionsToDisconnect: default[],
): void

Disconnect selected evolutionary pruning edges. Removal is followed by deferred activation-pool compaction scheduling so large structural contractions can reclaim memory without forcing immediate synchronous pool reshaping.

Parameters:

Returns: Nothing.

getOrCaptureEvolutionaryBaseline

getOrCaptureEvolutionaryBaseline(
  currentNetwork: default,
): number

Capture evolutionary baseline once and reuse it for subsequent pruning calls. The baseline anchors target sparsity to the original connection budget so repeated prune cycles converge predictably instead of drifting with the current graph size.

Parameters:

Returns: Evolutionary baseline connection count.

markEvolutionaryTopologyDirty

markEvolutionaryTopologyDirty(
  currentNetwork: default,
): void

Mark the topology cache as dirty after evolutionary pruning removes connections.

Parameters:

Returns: Nothing.

normalizeEvolutionaryTargetSparsity

normalizeEvolutionaryTargetSparsity(
  rawTargetSparsity: number,
): number

Clamp evolutionary target sparsity to safe operational bounds for pruning.

Parameters:

Returns: Normalized target sparsity.

rankEvolutionaryConnections

rankEvolutionaryConnections(
  connections: default[],
  pruningMethod: PruningMethod,
): default[]

Route evolutionary ranking to selected heuristic.

Parameters:

Returns: Connections sorted by ascending removal priority.

rankEvolutionaryConnectionsByMagnitude

rankEvolutionaryConnectionsByMagnitude(
  connections: default[],
): default[]

Rank connections by magnitude for evolutionary pruning.

Parameters:

Returns: Connections sorted by ascending absolute weight.

rankEvolutionaryConnectionsBySnip

rankEvolutionaryConnectionsBySnip(
  connections: default[],
): default[]

Rank connections by SNIP-like saliency for evolutionary pruning.

Parameters:

Returns: Connections sorted by ascending saliency.

resolveEvolutionaryGradientMagnitude

resolveEvolutionaryGradientMagnitude(
  connection: default,
): number

Resolve gradient proxy for evolutionary SNIP ranking.

Parameters:

Returns: Absolute gradient magnitude proxy.

Generated from source JSDoc • GitHub