Exemple #1
0
def main():
    print()
    TorchConfig.init()
    logging.basicConfig(level=logging.WARN)
    logging.getLogger('zensols.deeplearn.model').setLevel(logging.WARN)
    #logging.getLogger('zensols.config.meta').setLevel(logging.DEBUG)
    logger.setLevel(logging.INFO)
    run = [3, 4, 5, 6, 7, 8]
    res = None
    if run == [0]:
        res = find_leaks()
    elif run is None:
        load()
        res = end()
    else:
        fac = create_facade()
        fac.progress_bar = False
        fac.epochs = 50
        for r in run:
            res = {
                0: fac.dataset,
                1: lambda: fac.write(include_object_graph=True),
                2: fac.debug,
                3: fac.train,
                4: fac.test,
                5: fac.persist_result,
                6: fac.write_result,
                7: load,
                8: fac.deallocate,
                9: end
            }[r]()
    return res
Exemple #2
0
    def create_facade(self, *args) -> ModelFacade:
        """Create and return a facade.  This deallocates and cleans up state from any
        previous facade creation as a side effect.

        :param args: given to the :obj:`cli_args_fn` function to create
                     arguments passed to the CLI

        """
        if len(self.config_overwrites) > 0:
            dconf = DictionaryConfig(self.config_overwrites)
            app_args = {'config_overwrites': dconf}
        else:
            app_args = None
        self.deallocate()
        # reclaim memory running GC and GPU cache clear
        self.cleanup()
        try:
            # reset random state for consistency of each new test
            if self.reset_torch:
                TorchConfig.init()
            # create a factory that instantiates Python objects
            cli_args_fn = self.cli_args_fn(*args)
            # create the facade used for this instance
            self._facade: ModelFacade = self._create_facade(
                cli_args_fn, app_args)
            return self._facade
        except Exception as e:
            try:
                # recover the best we can
                self.cleanup(quiet=True)
                self._facade = None
            except Exception:
                pass
            raise DeepLearnError(f'Could not create facade: {e}') from e
Exemple #3
0
def init():
    from zensols.deeplearn import TorchConfig
    # reset random state for consistency before any other packages are
    # imported
    TorchConfig.init()
    from zensols import deepnlp
    # initialize the NLP system
    deepnlp.init()
Exemple #4
0
def main():
    print()
    TorchConfig.init()
    logging.basicConfig(level=logging.WARN)
    logger.setLevel(logging.INFO)
    run = [2, 3, 4]
    res = None
    for r in run:
        res = {1: dataset, 2: train_model, 3: test_model, 4: load_results}[r]()
    return res
Exemple #5
0
def main():
    print()
    TorchConfig.init()
    logging.basicConfig(level=logging.WARN)
    logging.getLogger('zensols.deeplearn.model').setLevel(logging.WARN)
    run = 5
    {
        0: dataset,
        1: dataframe,
        2: metadata,
        3: stash_info,
        4: batch,
        5: model,
        6: tmp
    }[run]()
Exemple #6
0
    def __init__(self, app_root_dir: str = '..', deepnlp_path: str = '..'):
        """Set up the interpreter environment so we can import local packages.

        :param app_root_dir: the application root directory
        :param deepnlp_path: the path to the DeepNLP source code
        """
        import sys
        from pathlib import Path
        self.app_root_dir = Path(app_root_dir)
        # add the example to the Python library path
        sys.path.append(str(self.app_root_dir / 'cb'))
        # add the deepnlp path
        sys.path.append(deepnlp_path)
        # reset random state for consistency before any other packages are
        # imported
        from zensols.deeplearn import TorchConfig
        TorchConfig.init()
        # initialize the NLP system
        from zensols.deepnlp import init
        init()
Exemple #7
0
#!/usr/bin/env python

from typing import List
import sys
from pathlib import Path
import logging
from zensols.deeplearn import TorchConfig
from zensols import deepnlp

# reset random state for consistency before any other packages are
# imported
TorchConfig.init()
# initialize the NLP system
deepnlp.init()


class CliHarness(object):
    """A utility class to automate the creation of execution of the model from
    either the command line or a Python REPL.

    """
    def __init__(self, args: List[str] = sys.argv, src_dir_name: str = 'src'):
        """Configure the Python interpreter and this run class.

        :param args: the command line arguments

        :param src_dir_name: the directory add the Python path containing the
                             source for the application

        """
        self.args = args[1:]
Exemple #8
0
 def setUp(self):
     TorchConfig.init()
     self.recreate_factory()
     targ = Path('target')
     if targ.exists() and targ.is_dir():
         shutil.rmtree(targ)
Exemple #9
0
 def setUp(self):
     TorchConfig.init()
     config = AppConfig('test-resources/iris/iris.conf',
                        env={'app_root': '.'})
     self.config = config
     self.fac = ImportConfigFactory(config, shared=True, reload=False)