Class NASOptions<T>
Configuration options for Neural Architecture Search (NAS).
public class NASOptions<T>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
NASOptions<T>
- Inherited Members
Remarks
For Beginners: NAS automatically discovers optimal neural network architectures. Instead of manually designing layers and connections, NAS explores the design space to find architectures that maximize accuracy while meeting hardware constraints.
Quick Start Example:
var options = new NASOptions<double>
{
Strategy = AutoMLSearchStrategy.DARTS,
TargetPlatform = HardwarePlatform.Mobile,
MaxSearchTime = TimeSpan.FromHours(2),
HardwareConstraints = new HardwareConstraints<double>
{
MaxLatency = 10.0, // 10ms max inference time
MaxMemory = 50.0 // 50MB max model size
}
};
Available Strategies:
- DARTS: Fast gradient-based search (~1-2 GPU days)
- GDAS: Improved DARTS with better discretization
- OnceForAll: Train once, deploy anywhere with elastic networks
- NeuralArchitectureSearch: Auto-selects best algorithm
Properties
ArchitectureLearningRate
Gets or sets the learning rate for architecture parameters.
public double ArchitectureLearningRate { get; set; }
Property Value
Remarks
For Advanced Users: Controls how fast the architecture search converges. Lower values are more stable but slower.
CheckpointDirectory
Gets or sets the checkpoint directory path.
public string? CheckpointDirectory { get; set; }
Property Value
ElasticDepths
Gets or sets the elastic depth values for OFA networks.
public List<int>? ElasticDepths { get; set; }
Property Value
Remarks
For OFA: List of possible layer counts that the network can use. Example: [2, 3, 4] means network can have 2, 3, or 4 layers per block.
ElasticExpansionRatios
Gets or sets the elastic expansion ratios for OFA inverted residuals.
public List<int>? ElasticExpansionRatios { get; set; }
Property Value
Remarks
For OFA: List of expansion ratios for inverted residual blocks. Example: [3, 4, 6] for MobileNetV2-style blocks.
ElasticKernelSizes
Gets or sets the elastic kernel sizes for OFA networks.
public List<int>? ElasticKernelSizes { get; set; }
Property Value
Remarks
For OFA: List of possible kernel sizes. Example: [3, 5, 7] means 3x3, 5x5, or 7x7 kernels.
ElasticWidths
Gets or sets the elastic width multipliers for OFA networks.
public List<double>? ElasticWidths { get; set; }
Property Value
Remarks
For OFA: List of channel width multipliers. Example: [0.75, 1.0, 1.25] means 75%, 100%, or 125% of base channels.
Generations
Gets or sets the number of generations for evolutionary search.
public int Generations { get; set; }
Property Value
Remarks
For Evolutionary/OFA Specialization: Number of evolution cycles. More generations allow better convergence.
HardwareConstraints
Gets or sets the hardware constraints for the architecture search.
public HardwareConstraints<T>? HardwareConstraints { get; set; }
Property Value
Remarks
For Beginners: Set limits that your target device can handle:
HardwareConstraints = new HardwareConstraints<double>
{
MaxLatency = 10.0, // Max inference time in milliseconds
MaxMemory = 50.0, // Max model size in MB
MaxEnergy = 100.0 // Max energy per inference in mJ
};
InputChannels
Gets or sets the number of input channels.
public int InputChannels { get; set; }
Property Value
Remarks
For Beginners: Number of channels in input data:
- 1: Grayscale images
- 3: RGB images
- 4: RGBA images
MaxEpochs
Gets or sets the maximum number of search epochs.
public int MaxEpochs { get; set; }
Property Value
Remarks
For Beginners: Number of training iterations for the architecture search. Higher values explore more thoroughly but take longer.
MaxSearchTime
Gets or sets the maximum time for the architecture search.
public TimeSpan MaxSearchTime { get; set; }
Property Value
Remarks
For Beginners: Longer search times generally find better architectures. Typical values:
- Quick test: 30 minutes - 1 hour
- Standard: 2-8 hours
- Production: 24-48 hours
MutationProbability
Gets or sets the mutation probability for evolutionary search.
public double MutationProbability { get; set; }
Property Value
Remarks
For Evolutionary: Probability of mutating each gene in offspring. Typical values: 0.05-0.2
NumClasses
Gets or sets the number of output classes.
public int NumClasses { get; set; }
Property Value
Remarks
For Classification: Number of classes to predict. Example: 10 for CIFAR-10, 1000 for ImageNet.
OnEpochComplete
Gets or sets the callback invoked after each search epoch.
public Action<int, T>? OnEpochComplete { get; set; }
Property Value
Remarks
For Monitoring: Use to log progress or save checkpoints. Parameters are (epoch, current best score).
PopulationSize
Gets or sets the population size for evolutionary search.
public int PopulationSize { get; set; }
Property Value
Remarks
For Evolutionary/OFA Specialization: Number of candidate architectures to maintain in each generation. Larger populations explore more diversity.
QuantizationAware
Gets or sets whether to use quantization-aware training during NAS.
public bool QuantizationAware { get; set; }
Property Value
Remarks
For Beginners: When enabled, architectures are searched with quantization in mind, resulting in models that maintain accuracy after quantization.
QuantizationMode
Gets or sets the quantization mode for quantization-aware NAS.
public QuantizationMode QuantizationMode { get; set; }
Property Value
Remarks
For Quantization-Aware NAS: The type of quantization to simulate:
- Int8: Most common for mobile/edge deployment
- Float16: Good balance of speed and accuracy
- Dynamic: Quantize weights, compute in float
- Mixed: Different precision for different layers
RandomSeed
Gets or sets the random seed for reproducibility.
public int? RandomSeed { get; set; }
Property Value
- int?
Remarks
For Reproducibility: Set a seed to get repeatable results.
SaveCheckpoints
Gets or sets whether to save architecture checkpoints during search.
public bool SaveCheckpoints { get; set; }
Property Value
SearchSpace
Gets or sets the search space configuration.
public SearchSpaceBase<T>? SearchSpace { get; set; }
Property Value
Remarks
For Advanced Users: Customize the operations and structure that NAS can explore. If null, a default search space with standard operations is used.
SpatialSize
Gets or sets the spatial size of the input (assuming square inputs).
public int SpatialSize { get; set; }
Property Value
Remarks
For Beginners: Width/height of input images. Common values: 32 (CIFAR), 224 (ImageNet), 299 (Inception).
Strategy
Gets or sets the NAS strategy to use.
public AutoMLSearchStrategy Strategy { get; set; }
Property Value
Remarks
For Beginners: Different strategies have different trade-offs:
- DARTS: Fast but may produce suboptimal architectures
- GDAS: More stable than DARTS, slightly slower
- OnceForAll: Best for multi-device deployment
TargetPlatform
Gets or sets the target hardware platform for optimization.
public HardwarePlatform TargetPlatform { get; set; }
Property Value
Remarks
For Beginners: Choose where your model will run:
- CPU: Standard desktop/server deployment
- GPU: High-performance with CUDA/OpenCL
- Mobile: Smartphones and tablets
- EdgeTPU: Google Edge TPU accelerators
Verbose
Gets or sets whether to enable verbose logging during search.
public bool Verbose { get; set; }
Property Value
WeightLearningRate
Gets or sets the learning rate for network weights.
public double WeightLearningRate { get; set; }
Property Value
Remarks
For Advanced Users: Controls how fast the network weights update. Typically higher than architecture learning rate.
Methods
Validate()
Validates the options and throws if any are invalid.
public void Validate()
Exceptions
- ArgumentException
Thrown when options are invalid.
With(Action<NASOptions<T>>)
Creates a copy of these options with the specified modifications.
public NASOptions<T> With(Action<NASOptions<T>> configure)
Parameters
configureAction<NASOptions<T>>Action to configure the copy.
Returns
- NASOptions<T>
A new NASOptions instance with modifications applied.