def test_import_wrong_date(): from returnn.import_ import import_ from returnn.import_.common import InvalidVersion try: import_("github.com/rwth-i6/returnn-experiments", "common/test.py", "20210301-01094bef2761") except InvalidVersion as exc: print("got expected exception:", exc) else: raise Exception( "We expected an invalid version exception but got nothing.")
def test_import_wrong_pkg_py_import(): from pprint import pprint from returnn.import_ import import_ from returnn.import_.common import _registered_modules, MissingExplicitImport # Use some other commit here which is not used by the other tests, to not mess up. mod = import_("github.com/rwth-i6/returnn-experiments", "common", "20210302-10beb9d1c57e") print("Loaded mod %s, name %s, file %s" % (mod, mod.__name__, mod.__file__)) print("Registered modules:") pprint(_registered_modules) # Mod name, without "common". mod_name = "returnn_import.github_com.rwth_i6.returnn_experiments.v20210302153450_10beb9d1c57e" assert mod_name in _registered_modules assert mod_name in sys.modules # Remove from both to force a reload. del _registered_modules[mod_name] del sys.modules[mod_name] try: import returnn_import.github_com.rwth_i6.returnn_experiments.v20210302153450_10beb9d1c57e except MissingExplicitImport as exc: # but *not* a normal ImportError print("Got expected exception:", exc) else: raise Exception( "We expected an import error exception but got nothing.")
def test_import_root_repo_sub_mod(): from returnn.import_ import import_ mod = import_("github.com/rwth-i6/returnn_common", "test/hello.py", "20210603-3752d77") print("Loaded mod %s, name %s, file %s" % (mod, mod.__name__, mod.__file__)) assert_equal(mod.hello(), "hello world")
def test_import_(): from returnn.import_ import import_ mod = import_("github.com/rwth-i6/returnn-experiments", "common/test.py", "20210302-01094bef2761") print("Loaded mod %s, name %s, file %s" % (mod, mod.__name__, mod.__file__)) assert_equal(mod.hello(), "hello world")
def test_import_root_repo_pkg(): from returnn.import_ import import_ mod = import_("github.com/rwth-i6/returnn_common", ".", "20210602-1bc6822") print("Loaded mod %s, name %s, file %s" % (mod, mod.__name__, mod.__file__)) from returnn_import.github_com.rwth_i6.returnn_common.v20210602162042_1bc6822b2fd1 import test assert_equal(test.hello(), "hello world")
def test_import_pkg_py_import(): from returnn.import_ import import_ mod = import_("github.com/rwth-i6/returnn-experiments", "common", "20210302-01094bef2761") print("Loaded mod %s, name %s, file %s" % (mod, mod.__name__, mod.__file__)) # noinspection PyUnresolvedReferences from returnn_import.github_com.rwth_i6.returnn_experiments.v20210302133012_01094bef2761 import common assert common is mod
#!crnn/rnn.py # kate: syntax python; # vim: ft=python sw=2: # based on Andre Merboldt rnnt-fs.bpe1k.readout.zoneout.lm-embed256.lr1e_3.no-curric.bs12k.mgpu.retrain1.config from returnn.import_ import import_ import_("github.com/rwth-i6/returnn-experiments", "common") from returnn_import.github_com.rwth_i6.returnn_experiments.dev.common.common_config import * from returnn_import.github_com.rwth_i6.returnn_experiments.dev.common.datasets.asr.librispeech import oggzip from returnn_import.github_com.rwth_i6.returnn_experiments.dev.common.models.transducer.transducer_fullsum import make_net from returnn_import.github_com.rwth_i6.returnn_experiments.dev.common.training.pretrain import Pretrain # data globals().update(oggzip.Librispeech().get_config_opts()) get_network = Pretrain(make_net, { "enc_lstm_dim": (512, 1024), "enc_num_layers": (3, 6) }, num_epochs=20).get_network # trainer batching = "random" batch_size = 1000 if debug_mode else 12000 max_seqs = 10 if debug_mode else 200 max_seq_length = {"classes": 75} num_epochs = 100 model = "net-model/network" cleanup_old_models = True
from typing import Union, Optional, Tuple, List, Dict, Any from returnn.import_ import import_ # common = import_("github.com/rwth-i6/returnn_common", "models/base", "20210805-a44e7fa4209663c4ea6f71a7406d6839ed699df2") # from returnn_import.github_com.rwth_i6.returnn_common.v20210805202428_a44e7fa42096.models.base import\ # LayerRef, LayerDictRaw, Module, get_root_extern_data # import returnn_import.github_com.rwth_i6.returnn_common.v20210805202428_a44e7fa42096.models._generated_layers as layers common = import_("github.com/rwth-i6/returnn_common", "models/base", "20210929-2243f105ba0befb2eba63f53a2350d4e26639532") from returnn_import.github_com.rwth_i6.returnn_common.v20210929142536_2243f105ba0b.models.base import \ LayerRef, LayerDictRaw, Module, get_root_extern_data import returnn_import.github_com.rwth_i6.returnn_common.v20210929142536_2243f105ba0b.models._generated_layers as layers from returnn.util.basic import NotSpecified from .specaugment_clean import SpecAugmentBlock, SpecAugmentSettings class Encoder2DConvBlock(Module): def __init__(self, l2=0.001, dropout=0.3, act='relu', filter_sizes=[(3, 3)], pool_sizes=[(1, 2)], channel_sizes=[32], padding='same'): super().__init__() self.split_feature_layer = layers.SplitDims(axis="F", dims=(-1, 1)) self.conv_layers = [] self.pool_layers = []
'tdp_scale': 0.0 }, 'n_out': 139, 'target': None }, #'source': {'class': 'eval', 'eval': "self.network.get_config().typed_value('_specaugment_eval_func')(source(0, as_data=True), network=self.network)"} 'source': { 'class': 'copy', 'from': ["data"] } } import time start = time.time() from returnn.import_ import import_ common = import_("github.com/rwth-i6/returnn_common", "nn", "20211202-c025fdeef1843ab06e9888b6a17d217463b961bc") from returnn_import.github_com.rwth_i6.returnn_common.v20211202164723_c025fdeef184 import nn from returnn_import.github_com.rwth_i6.returnn_common.v20211202164723_c025fdeef184.nn \ import Module, LayerRef, get_extern_data, get_root_extern_data, NameCtx, make_root_net_dict from .specaugment_clean_v2 import specaugment, SpecAugmentSettings print("old imports took %f" % (time.time() - start)) class BLSTMPoolModule(Module): def __init__(self, hidden_size, pool, dropout=None, l2=None): super().__init__() self.fw_rec = nn.LSTM(n_out=hidden_size, direction=1, l2=l2) self.bw_rec = nn.LSTM(n_out=hidden_size, direction=-1, l2=l2)
#!crnn/rnn.py # kate: syntax python; # vim: ft=python sw=2: # adapted for import_ & common recipes from returnn.tf.util.data import DimensionTag, Data from returnn.import_ import import_ import_("github.com/rwth-i6/returnn-experiments", "common", "20210324-75f7809") from returnn_import.github_com.rwth_i6.returnn_experiments.v20210324123103_75f78096518b.common.common_config import * from returnn_import.github_com.rwth_i6.returnn_experiments.v20210324123103_75f78096518b.common.datasets.asr.librispeech import oggzip, vocabs from returnn_import.github_com.rwth_i6.returnn_experiments.v20210324123103_75f78096518b.common.data import get_common_data_path # This config is mostly for testing. # Probably you want `--task eval`. # I get: dev: score 4.636750261205999 error None devtrain: score 1.5685920611769462 error None load = get_common_data_path( "librispeech/transducer/" "andre-rnnt-fs.bpe1k.readout.zoneout.lm-embed256.lr1e_3.no-curric.bs12k.mgpu.retrain1/" "net-model/network.160") if task == "search": _task = "search" else: # The config does not really expect anything else than task=="train"... # But this is what we want, also for task=="eval" etc. _task = "train" use_horovod = config.bool("use_horovod", False) horovod_dataset_distribution = "random_seed_offset" horovod_reduce_type = "param"