Skip to content

Random Search

Bases: MetaOptimizer

RandomSearch is a class that implements the Random Search algorithm for Neural Architecture Search (NAS). It is derived from the MetaOptimizer class. The random search is done by randomly sampling 'k' architectures and training them for 'n' epochs, then selecting the best architecture. In the DARTS paper, 'k' equals 24 and 'n' equals 100 for the CIFAR-10 dataset.

Attributes:

Name Type Description
using_step_function bool

Flag indicating the absence of a step function for this optimizer.

performance_metric Metric

The performance metric for evaluating the architectures.

dataset str

The dataset to be used for evaluation.

fidelity int

The number of epochs for each sampled architecture's training.

device torch.device

The device to be used for computations, either CUDA or CPU.

sampled_archs list

A list to store the sampled architectures.

history torch.nn.ModuleList

A list to store the history of architectures.

__init__(config)

Initializes the RandomSearch class with configuration settings.

Parameters:

Name Type Description Default
config CfgNode

Configuration settings for the search process.

required

adapt_search_space(search_space, scope=None, dataset_api=None)

Adapts the search space for the random search.

Parameters:

Name Type Description Default
search_space Graph

The search space to be adapted.

required
scope str

The scope for the search. Defaults to None.

None
dataset_api dict

API for the dataset. Defaults to None.

None

get_checkpointables()

Gets the models that can be checkpointed.

Returns:

Name Type Description
dict

A dictionary with "model" as the key and the history of architectures as the value.

get_final_architecture()

Gets the final (best) architecture from the search.

Returns:

Name Type Description
Graph

The best architecture found during the search.

get_op_optimizer()

Gets the optimizer for the operations. This method is not implemented in this class and raises an error when called.

Raises:

Type Description
NotImplementedError

Always, because this method is not implemented in this class.

new_epoch(epoch)

Starts a new epoch in the search process, sampling a new architecture to train.

Parameters:

Name Type Description Default
epoch int

The current epoch number.

required

test_statistics()

Reports the test statistics.

Returns:

Name Type Description
float

The raw performance metric for the best architecture.

train_statistics(report_incumbent=True)

Reports the statistics after training.

Parameters:

Name Type Description Default
report_incumbent bool

Whether to report the incumbent or the most recent architecture. Defaults to True.

True

Returns:

Name Type Description
tuple

A tuple containing the training accuracy, validation accuracy, test accuracy, and training time.