def apply(self, method: Method, config: Config = None) -> ClassIncrementalResults: """Apply the given method on this setting to producing some results.""" # TODO: It still isn't super clear what should be in charge of creating # the config, and how to create it, when it isn't passed explicitly. self.config: Config if config is not None: self.config = config logger.debug(f"Using Config {self.config}") elif isinstance(getattr(method, "config", None), Config): # If the Method has a `config` attribute that is a Config, use that. self.config = method.config logger.debug(f"Using Config from the Method: {self.config}") else: logger.debug("Parsing the Config from the command-line.") self.config = Config.from_args(self._argv, strict=False) logger.debug(f"Resulting Config: {self.config}") method.configure(setting=self) # Run the main loop (which is defined in IncrementalSetting). results: ClassIncrementalResults = super().main_loop(method) logger.info(results.summary()) method.receive_results(self, results=results) return results
def prepare_data(self, data_dir: Path = None, **kwargs): self.config = self.config or Config.from_args(self._argv, strict=False) # if self.batch_size is None: # logger.warning(UserWarning( # f"Using the default batch size of 32. (You can set the " # f"batch size by passing a value to the Setting constructor, or " # f"by setting the attribute inside your 'configure' method) " # )) # self.batch_size = 32 # data_dir = data_dir or self.data_dir or self.config.data_dir # self.make_dataset(data_dir, download=True) # self.data_dir = data_dir return super().prepare_data(data_dir=data_dir, **kwargs)
def apply_all(self, argv: Union[str, List[str]] = None) -> Dict[Type["Method"], Results]: applicable_methods = self.get_applicable_methods() from sequoia.methods import Method all_results: Dict[Type[Method], Results] = {} config = Config.from_args(argv) for method_type in applicable_methods: method = method_type.from_args(argv) results = self.apply(method, config) all_results[method_type] = results logger.info(f"All results for setting of type {type(self)}:") logger.info({ method.get_name(): (results.get_metric() if results else "crashed") for method, results in all_results.items() }) return all_results
def _setup_config(self, method: Method) -> Config: config: Config if isinstance(getattr(method, "config", None), Config): config = method.config logger.debug(f"Using Config from the Method: {self.config}") else: argv = self._argv if argv: logger.debug( f"Parsing the Config from the command-line arguments ({argv})" ) else: logger.debug( f"Parsing the config from the current command-line arguments." ) config = Config.from_args(argv, strict=False) return config