i6_core.returnn.config

class i6_core.returnn.config.CodeWrapper(code)

Can be used to insert direct “code” (not as quoted string) into the config dict

class i6_core.returnn.config.ReturnnConfig(config, post_config=None, staged_network_dict=None, *, python_prolog=None, python_prolog_hash=None, python_epilog='', python_epilog_hash=None, hash_full_python_code=False, sort_config=True, pprint_kwargs=None, black_formatting=True)

An object that manages a RETURNN config.

It can be used to serialize python functions and class definitions directly from Sisyphus code and paste them into the RETURNN config file.

Parameters:
  • config (dict) – dictionary of the RETURNN config variables that are hashed

  • post_config (dict) – dictionary of the RETURNN config variables that are not hashed

  • staged_network_dict (None|dict[int, str|dict[str, Any]]) – dictionary of network dictionaries or any string that defines a network with network = … (e.g. the return variable of get_ext_net_dict_py_code_str() from returnn_common), indexed by the desired starting epoch of the network stage. By enabling this, an additional “networks” folder will be created next to the config location.

  • python_prolog (None|str|Callable|Class|tuple|list|dict) – str or structure containing str/callables/classes that should be pasted as code at the beginning of the config file

  • python_prolog_hash (None|Any) – set a specific hash (str) or any type of hashable objects to overwrite the default hashing for python_prolog

  • python_epilog (None|str|Callable|Class|tuple|list|dict) – str or structure containing str/callables/classes that should be pasted as code at the end of the config file

  • python_epilog_hash (None|Any) – set a specific hash (str) or any type of hashable objects to overwrite the default hashing for python_epilog

  • hash_full_python_code (bool) – By default, function bodies are not hashed. If set to True, the full content of python pro-/epilog is parsed and hashed.

  • sort_config (bool) – If set to True, the dictionary part of the config is sorted by key

  • pprint_kwargs (dict|None) – kwargs for pprint, e.g. {“sort_dicts”: False} to print dicts in given order for python >= 3.8

  • black_formatting (bool) – if true, the written config will be formatted with black

GET_NETWORK_CODE = 'import os\nimport sys\nsys.path.insert(0, os.path.dirname(__file__))\n\ndef get_network(epoch, **kwargs):\n  from networks import networks_dict\n  for epoch_ in sorted(networks_dict.keys(), reverse=True):\n    if epoch_ <= epoch:\n      return networks_dict[epoch_]\n  assert False, "Error, no networks found"\n\n'
PYTHON_CODE = '#!rnn.py\n\n${SUPPORT_CODE}\n\n${PROLOG}\n\n${REGULAR_CONFIG}\n\nlocals().update(**config)\n\n${EPILOG}\n'
check_consistency()

Check that there is no config key overwritten by post_config. Also check for parameters that should never be hashed.

get(key, default=None)
update(other)
updates a ReturnnConfig with an other ReturnnConfig:
  • config, post_config, and pprint_kwargs use dict.update

  • prolog, epilog, and hashes are concatenated

  • staged_network_dict, sort_config, and black_formatting are overwritten

Parameters:

other (ReturnnConfig) –

write(path)
Parameters:

path (str) –

class i6_core.returnn.config.WriteReturnnConfigJob(*args, **kwargs)

Writes a ReturnnConfig into a .config file

Parameters:

returnn_config (ReturnnConfig) –

run()
tasks()
Returns:

yields Task’s

Return type:

list[sisyphus.task.Task]