CloneOptions

Options & Configuration · AiDotNet.Models

Controls what a Clone carries across from the original.

Implements: IEquatable<CloneOptions>

For Beginners

Cloning a model gives you a second, separate copy. This class lets you say how much of the original the copy should bring with it. You almost never need to set any of this — model.Clone() already does the sensible thing, giving you a complete independent copy that behaves exactly like the original.

How It Works

The default is deliberately stronger than the equivalent in other libraries. In PyTorch, copy.deepcopy(model) cannot carry optimizer state, because the optimizer is a separate object that merely holds references to the model’s parameters — so a copy taken mid-training restarts its optimizer from scratch. That is a structural limitation rather than a considered choice, so this library does not reproduce it: Full carries optimizer state, and a clone taken mid-training resumes as the original would.

The one thing the default does not share is the random number stream. Two models drawing from the same stream produce identical dropout masks and identical shuffles forever, so their training silently correlates and nothing in the results reveals it. The clone instead gets a fresh stream derived from the original’s seed, which stays reproducible without the coupling. Set ShareRandomState when you genuinely want a bit-identical twin.

The contract in one line: a clone trains as if it were the original, but its randomness does not track it.

Constructors

Constructor Summary
CloneOptions()

Properties

Property Summary
CloneMode Mode { get; set; } Gets how much of the original’s storage the copy is allowed to share.
CloneOptions Architecture { get; } Gets a configuration-only copy: same architecture and settings, nothing learned.
CloneOptions CopyOnWrite { get; } Gets a copy that shares each weight tensor’s storage until either side writes to it.
CloneOptions Full { get; } Gets the default: a complete, independent copy with a freshly derived random stream.
CloneOptions Shared { get; } Gets an ALIAS: the copy points at the same parameters as the original.
bool IncludeBuffers { get; set; } Gets a value indicating whether non-gradient learned state is carried.
bool IncludeConfiguration { get; } Gets a value indicating whether configuration is carried.
bool IncludeOptimizerState { get; set; } Gets a value indicating whether optimizer state is carried.
bool IncludeParameters { get; set; } Gets a value indicating whether learned parameters are carried.
bool ShareRandomState { get; set; } Gets a value indicating whether the clone shares the original’s random stream rather than deriving its own.

Methods

Method Summary
CloneOptions <Clone>$()
bool Equals(CloneOptions other)
bool Equals(object obj)
bool op_Equality(CloneOptions left, CloneOptions right)
bool op_Inequality(CloneOptions left, CloneOptions right)
int GetHashCode()
string ToString()