DeepWok / mase

Machine-Learning Accelerator System Exploration Tools
Other
117 stars 52 forks source link

Group 1 - Porting Zero-Cost NAS Proxies to MASE #74

Closed JaredJoss closed 6 months ago

JaredJoss commented 6 months ago

Group 1 - Porting Zero-Cost NAS Proxies to MASE

This pull request outlines how the Zero-Cost proxy for NAS search was integrated into the chop workflow. The results found in the accompanying report can be replicated using the zero_cost_report.ipynb notebook found in mase/machop/chop/actions/search/search_space/zero_cost_proxy/zero_cost_report.ipynb

Functionality

Basic Elements

Extensions

Implementation Details

TOML Configuration File

search_space

 [search.search_space.zc] 

seed = 2 

benchmark = 'nasbench201' 

dataset = 'cifar10' 

calculate_proxy = false 

ensemble_model = 'nonlinear' 

loss_fn = 'mae' 

optimizer = 'adam' 

batch_size = 4 

learning_rate = 0.02 

epochs = 30 

num_archs_train = 2000 

num_archs_test = 2000 

zc_proxies = ['epe_nas', 'fisher', 'grad_norm', 'grasp', 'jacov', 'l2_norm', 'nwot', 'plain', 'snip', 'synflow', 'zen', 'flops', 'params'] 

strategy


[search.strategy.setup] 

n_jobs = 4 

n_trials = 100 

timeout = 20000 

sampler = "tpe" 

direction = "minimize" 

weight_lower_limit = 0 

weight_upper_limit = 30 

Graph.py

  1. Calculates the individual zero cost proxies metrics and their Spearman/ and Kensal Tau scores: For every chosen proxy, the calculate_zc function calculates the zero cost score for every architecture. It then calculates the KendallTau and Spearman correlation scores using evaluate_predictions.
  2. Creates an ensemble using a neural network (either linear or non-linear, as designed by the user): This involves the training of the network and the testing of the network. train_zc_ensemble_model is responsible for model training, using the parameters chosen in the TOML file (linear/non linear mode, loss function, optimizer, learning rate, number of epochs), this function will train the ensemble model. Additionally, to reduce overfitting, the best model during the training will be saved. After training a model, the test_zc_ensemble_model function is responsible for testing the model and calculating the KendallTau and Spearman correlation scores.
  3. Creates an ensemble using XGBoost: This involves training an XGBoost regressor with default hyperparameters, and then using this trained model to predict the test accuracies of the sampled architectures. Again, the KendallTau and Spearman correlation scores are evaluated

zero_cost.py

How to Run

To execute the search from the command line, follow these steps:

  1. This PR makes use of a submodule, there fore it must be initialised with;

    git submodule init NASLib 
  2. It must then be updated with;

    git submodule update NASLib
  3. Navigate to NASLib and install all dependencies;

    pip install -e . 
  4. Navigate to the machop directory.

  5. Run the following command, specifying the path to the TOML configuration file:

 ./ch search --config configs/examples/zero_cost_proxy.toml 

Where a search space configuration TOML file must be pointed to, after the ‘—config’ flag.

If prompted, put the data into NASLib/naslib/data

Output

After completing a search, the following is output on the command line;

|    | spearman                          | kendaltau                         | Global Parameters            |
|----+-----------------------------------+-----------------------------------+------------------------------|
|  0 | {'xgboost': 0.928}                | {'xgboost': 0.789}                | {'num_training_archs': 2000} |
|  1 | {'nonlinear': 0.82}               | {'nonlinear': 0.632}              | {'num_testing_archs': 2000}  |
|  2 | {'optuna_ensemble_metric': 0.779} | {'optuna_ensemble_metric': 0.594} | {'dataset': 'cifar10'}       |
|  3 | {'synflow': 0.774}                | {'synflow': 0.581}                | {'benchmark': 'nasbench201'} |
|  4 | {'nwot': 0.756}                   | {'nwot': 0.57}                    | {'num_zc_proxies': 13}       |

This shows the top five best performing ZC proxies/ensemble based on both the Spearman and Kendall Tau correlations as well as important settings set in the TOML file including the number of training and testing architectures, the dataset used, benchmark used and number of ZC proxies evaluated.

Checklist