Update Warmup
This commit is contained in:
		| @@ -7,7 +7,6 @@ | ||||
| # [2020.08.31] NATS-sss-v1_0-50262.pickle.pbz2                                      # | ||||
| ##################################################################################### | ||||
| import os, copy, random, numpy as np | ||||
| from pathlib import Path | ||||
| from typing import List, Text, Union, Dict, Optional | ||||
| from collections import OrderedDict, defaultdict | ||||
| from .api_utils import time_string | ||||
| @@ -15,6 +14,8 @@ from .api_utils import pickle_load | ||||
| from .api_utils import ArchResults | ||||
| from .api_utils import NASBenchMetaAPI | ||||
| from .api_utils import remap_dataset_set_names | ||||
| from .api_utils import nats_is_dir | ||||
| from .api_utils import nats_is_file | ||||
| from .api_utils import PICKLE_EXT | ||||
|  | ||||
|  | ||||
| @@ -70,20 +71,20 @@ class NATSsize(NASBenchMetaAPI): | ||||
|       else: | ||||
|         file_path_or_dict = os.path.join(os.environ['TORCH_HOME'], '{:}.{:}'.format(ALL_BASE_NAMES[-1], PICKLE_EXT)) | ||||
|       print ('{:} Try to use the default NATS-Bench (size) path from fast_mode={:} and path={:}.'.format(time_string(), self._fast_mode, file_path_or_dict)) | ||||
|     if isinstance(file_path_or_dict, str) or isinstance(file_path_or_dict, Path): | ||||
|     if isinstance(file_path_or_dict, str): | ||||
|       file_path_or_dict = str(file_path_or_dict) | ||||
|       if verbose: | ||||
|         print('{:} Try to create the NATS-Bench (size) api from {:} with fast_mode={:}'.format(time_string(), file_path_or_dict, fast_mode)) | ||||
|       if not os.path.isfile(file_path_or_dict) and not os.path.isdir(file_path_or_dict): | ||||
|       if not nats_is_file(file_path_or_dict) and not nats_is_dir(file_path_or_dict): | ||||
|         raise ValueError('{:} is neither a file or a dir.'.format(file_path_or_dict)) | ||||
|       self.filename = Path(file_path_or_dict).name | ||||
|       self.filename = os.path.basename(file_path_or_dict) | ||||
|       if fast_mode: | ||||
|         if os.path.isfile(file_path_or_dict): | ||||
|         if nats_is_file(file_path_or_dict): | ||||
|           raise ValueError('fast_mode={:} must feed the path for directory : {:}'.format(fast_mode, file_path_or_dict)) | ||||
|         else: | ||||
|           self._archive_dir = file_path_or_dict | ||||
|       else: | ||||
|         if os.path.isdir(file_path_or_dict): | ||||
|         if nats_is_dir(file_path_or_dict): | ||||
|           raise ValueError('fast_mode={:} must feed the path for file : {:}'.format(fast_mode, file_path_or_dict)) | ||||
|         else: | ||||
|           file_path_or_dict = pickle_load(file_path_or_dict) | ||||
|   | ||||
| @@ -7,7 +7,6 @@ | ||||
| # [2020.08.31] NATS-tss-v1_0-3ffb9.pickle.pbz2                                      # | ||||
| ##################################################################################### | ||||
| import os, copy, random, numpy as np | ||||
| from pathlib import Path | ||||
| from typing import List, Text, Union, Dict, Optional | ||||
| from collections import OrderedDict, defaultdict | ||||
| import warnings | ||||
| @@ -16,6 +15,8 @@ from .api_utils import pickle_load | ||||
| from .api_utils import ArchResults | ||||
| from .api_utils import NASBenchMetaAPI | ||||
| from .api_utils import remap_dataset_set_names | ||||
| from .api_utils import nats_is_dir | ||||
| from .api_utils import nats_is_file | ||||
| from .api_utils import PICKLE_EXT | ||||
|  | ||||
|  | ||||
| @@ -67,20 +68,20 @@ class NATStopology(NASBenchMetaAPI): | ||||
|       else: | ||||
|         file_path_or_dict = os.path.join(os.environ['TORCH_HOME'], '{:}.{:}'.format(ALL_BASE_NAMES[-1], PICKLE_EXT)) | ||||
|       print ('{:} Try to use the default NATS-Bench (topology) path from {:}.'.format(time_string(), file_path_or_dict)) | ||||
|     if isinstance(file_path_or_dict, str) or isinstance(file_path_or_dict, Path): | ||||
|     if isinstance(file_path_or_dict, str): | ||||
|       file_path_or_dict = str(file_path_or_dict) | ||||
|       if verbose: | ||||
|         print('{:} Try to create the NATS-Bench (topology) api from {:} with fast_mode={:}'.format(time_string(), file_path_or_dict, fast_mode)) | ||||
|       if not os.path.isfile(file_path_or_dict) and not os.path.isdir(file_path_or_dict): | ||||
|       if not nats_is_file(file_path_or_dict) and not nats_is_dir(file_path_or_dict): | ||||
|         raise ValueError('{:} is neither a file or a dir.'.format(file_path_or_dict)) | ||||
|       self.filename = Path(file_path_or_dict).name | ||||
|       self.filename = os.path.basename(file_path_or_dict) | ||||
|       if fast_mode: | ||||
|         if os.path.isfile(file_path_or_dict): | ||||
|         if nats_is_file(file_path_or_dict): | ||||
|           raise ValueError('fast_mode={:} must feed the path for directory : {:}'.format(fast_mode, file_path_or_dict)) | ||||
|         else: | ||||
|           self._archive_dir = file_path_or_dict | ||||
|       else: | ||||
|         if os.path.isdir(file_path_or_dict): | ||||
|         if nats_is_dir(file_path_or_dict): | ||||
|           raise ValueError('fast_mode={:} must feed the path for file : {:}'.format(fast_mode, file_path_or_dict)) | ||||
|         else: | ||||
|           file_path_or_dict = pickle_load(file_path_or_dict) | ||||
|   | ||||
| @@ -17,6 +17,7 @@ from typing import List, Text, Union, Dict, Optional | ||||
| from collections import OrderedDict, defaultdict | ||||
|  | ||||
|  | ||||
| _FILE_SYSTEM = 'default' | ||||
| PICKLE_EXT = 'pickle.pbz2' | ||||
|  | ||||
|  | ||||
| @@ -45,6 +46,34 @@ def time_string(): | ||||
|   return string | ||||
|  | ||||
|  | ||||
| def reset_file_system(lib: Text='default'): | ||||
|   _FILE_SYSTEM = lib | ||||
|  | ||||
|  | ||||
| def get_file_system(lib: Text='default'): | ||||
|   return _FILE_SYSTEM | ||||
|  | ||||
|  | ||||
| def nats_is_dir(file_path): | ||||
|   if _FILE_SYSTEM == 'default': | ||||
|     return os.path.isdir(file_path) | ||||
|   elif _FILE_SYSTEM == 'google': | ||||
|     import tensorflow as tf | ||||
|     return tf.gfile.isdir(file_path) | ||||
|   else: | ||||
|     raise ValueError('Unknown file system lib: {:}'.format(_FILE_SYSTEM)) | ||||
|  | ||||
|  | ||||
| def nats_is_file(file_path): | ||||
|   if _FILE_SYSTEM == 'default': | ||||
|     return os.path.isfile(file_path) | ||||
|   elif _FILE_SYSTEM == 'google': | ||||
|     import tensorflow as tf | ||||
|     return tf.gfile.exists(file_path) and not tf.gfile.isdir(file_path) | ||||
|   else: | ||||
|     raise ValueError('Unknown file system lib: {:}'.format(_FILE_SYSTEM)) | ||||
|  | ||||
|  | ||||
| def remap_dataset_set_names(dataset, metric_on_set, verbose=False): | ||||
|   """re-map the metric_on_set to internal keys""" | ||||
|   if verbose: | ||||
| @@ -146,10 +175,10 @@ class NASBenchMetaAPI(metaclass=abc.ABCMeta): | ||||
|             time_string(), archive_root, index)) | ||||
|     if archive_root is None: | ||||
|       archive_root = os.path.join(os.environ['TORCH_HOME'], '{:}-full'.format(self.ALL_BASE_NAMES[-1])) | ||||
|       if not os.path.isdir(archive_root): | ||||
|       if not nats_is_dir(archive_root): | ||||
|         warnings.warn('The input archive_root is None and the default archive_root path ({:}) does not exist, try to use self.archive_dir.'.format(archive_root)) | ||||
|         archive_root = self.archive_dir | ||||
|     if archive_root is None or not os.path.isdir(archive_root): | ||||
|     if archive_root is None or not nats_is_dir(archive_root): | ||||
|       raise ValueError('Invalid archive_root : {:}'.format(archive_root)) | ||||
|     if index is None: | ||||
|       indexes = list(range(len(self))) | ||||
| @@ -158,9 +187,9 @@ class NASBenchMetaAPI(metaclass=abc.ABCMeta): | ||||
|     for idx in indexes: | ||||
|       assert 0 <= idx < len(self.meta_archs), 'invalid index of {:}'.format(idx) | ||||
|       xfile_path = os.path.join(archive_root, '{:06d}.{:}'.format(idx, PICKLE_EXT)) | ||||
|       if not os.path.isfile(xfile_path): | ||||
|       if not nats_is_file(xfile_path): | ||||
|         xfile_path = os.path.join(archive_root, '{:d}.{:}'.format(idx, PICKLE_EXT)) | ||||
|       assert os.path.isfile(xfile_path), 'invalid data path : {:}'.format(xfile_path) | ||||
|       assert nats_is_file(xfile_path), 'invalid data path : {:}'.format(xfile_path) | ||||
|       xdata = pickle_load(xfile_path) | ||||
|       assert isinstance(xdata, dict), 'invalid format of data in {:}'.format(xfile_path) | ||||
|       self.evaluated_indexes.add(idx) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user