architecture/network/prune

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:

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

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.

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.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