architecture/network/prune

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

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

NetworkPruneBudgetGrowthGraceFractionError

Error raised when sparsity-budget grace configuration is invalid.

NetworkPruneBudgetMaxConnectionsError

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

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

ActivePruningConfig

Non-nullable pruning schedule configuration shape used by helpers.

DEFAULT_PRUNE_FREQUENCY

Fallback prune cadence when schedule frequency is omitted 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.

MIN_PROGRESS_FRACTION

Minimum normalized schedule progress value.

MIN_REMAINING_CONNECTION_COUNT

Lower bound to ensure at least one connection remains after pruning.

PRUNING_METHOD_MAGNITUDE

Pruning method identifier for absolute-weight ranking.

PRUNING_METHOD_SNIP

Pruning method identifier for SNIP-like saliency ranking.

REGROW_ATTEMPT_MULTIPLIER

Retry multiplier to convert intended 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):

Opportunistically perform scheduled pruning during gradient-based training.

Scheduling model:

SNIP heuristic:

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

Current sparsity fraction relative to the training-time pruning baseline.

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

getSparsityBudgetSnapshot

getSparsityBudgetSnapshot(
  currentNetwork: default,
): NetworkSparsityBudgetSnapshot | undefined

Read the last recorded sparsity-budget decision snapshot.

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.

Scheduling fields (cfg): start, end, frequency, targetSparsity, method ('magnitude' | 'snip'), regrowFraction. The target sparsity ramps linearly from 0 at start to cfg.targetSparsity at end.

Parameters:

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

Read the last recorded sparsity-budget decision snapshot.

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 regrowth plan when 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 current ranking context.

Parameters:

Returns: Connections selected for pruning.

buildScheduledTarget

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

Build current scheduled pruning targets from schedule context.

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.

Parameters:

Returns: Nothing.

getInitialConnectionBaseline

getInitialConnectionBaseline(
  currentNetwork: default,
): number | undefined

Read the scheduled-pruning baseline connection count.

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.

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.

Parameters:

Returns: Nothing.

markTopologyDirty

markTopologyDirty(
  currentNetwork: default,
): void

Mark topology cache as dirty after 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 optional pruning method to a concrete 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.

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 density into sparsity ratio.

Parameters:

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

readInitialSparsityBaseline

readInitialSparsityBaseline(
  currentNetwork: default,
): number | undefined

Read baseline used for sparsity 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.

Parameters:

Returns: Connections selected for removal.

buildEvolutionaryTarget

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

Compute evolutionary pruning target counts.

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.

Parameters:

Returns: Nothing.

getOrCaptureEvolutionaryBaseline

getOrCaptureEvolutionaryBaseline(
  currentNetwork: default,
): number

Capture evolutionary baseline once and reuse it for subsequent pruning calls.

Parameters:

Returns: Evolutionary baseline connection count.

markEvolutionaryTopologyDirty

markEvolutionaryTopologyDirty(
  currentNetwork: default,
): void

Mark topology cache as dirty after evolutionary pruning.

Parameters:

Returns: Nothing.

normalizeEvolutionaryTargetSparsity

normalizeEvolutionaryTargetSparsity(
  rawTargetSparsity: number,
): number

Clamp evolutionary target sparsity to safe operational bounds.

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