NPenas
Bases: MetaOptimizer
Implements the Npenas optimizer.
Npenas is a Neural Predictor Guided Evolution for Neural Architecture Search optimization algorithm which uses machine learning to guide the search process of neural architecture search (NAS). This algorithm employs predictive models, acquisition functions, and zero-cost proxies to speed up the search process.
Attributes:
Name | Type | Description |
---|---|---|
config |
obj
|
Configuration object containing setup parameters. |
zc_api |
obj
|
Zero cost API object to query zero-cost proxies. |
__init__(config, zc_api=None)
Constructor of Npenas optimizer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config |
obj
|
Configuration object containing setup parameters. |
required |
zc_api |
obj
|
Zero cost API object to query zero-cost proxies. |
None
|
adapt_search_space(search_space, scope=None, dataset_api=None)
Adapts the search space for optimization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search_space |
obj
|
The search space object that contains all possible architectures. |
required |
scope |
str
|
Defines the scope of the search space for the optimizer. |
None
|
dataset_api |
obj
|
API for querying dataset specific metrics. |
None
|
Raises:
Type | Description |
---|---|
AssertionError
|
If search_space is not queryable. |
get_arch_as_string(arch)
Returns a string representation of the given architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch |
obj
|
The architecture to convert to string. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
The string representation of the architecture. |
get_checkpointables()
Returns the models that should be checkpointed.
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary with 'model' as the key and the history of models as the value. |
get_final_architecture()
Returns the final/best architecture from the history.
Returns:
Name | Type | Description |
---|---|---|
obj |
The final/best architecture. |
get_model_size()
Returns the size of the model.
Returns:
Name | Type | Description |
---|---|---|
float |
The size of the model in MB. |
get_op_optimizer()
Method to get the optimizer of the operation. Not implemented in this class.
Raises:
Type | Description |
---|---|
NotImplementedError
|
Always, as this method is not implemented. |
get_zero_cost_predictors()
Creates and returns a dictionary of zero cost predictors based on the zc_names
configuration.
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary where keys are zero cost predictor names and values are the predictor objects. |
new_epoch(epoch)
Conducts one epoch of the optimization process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
epoch |
int
|
The current epoch number. |
required |
query_zc_scores(arch)
Queries and returns the zero-cost scores for a given architecture.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
arch |
obj
|
The architecture to query. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary where keys are zero cost predictor names and values are the corresponding scores. |
test_statistics()
Returns the test statistics of the final architecture.
Returns:
Name | Type | Description |
---|---|---|
int |
The raw test metric of the final architecture. |
train_statistics(report_incumbent=True)
Returns the training statistics of the best architecture or the last trained one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
report_incumbent |
bool
|
Whether to return the statistics of the best architecture. Defaults to True. |
True
|
Returns:
Name | Type | Description |
---|---|---|
tuple |
A tuple containing the training accuracy, validation accuracy, test accuracy, and training time of the architecture. |