Esempio n. 1
0
def returnn_greeting(config_filename=None, command_line_options=None):
    """
  Prints some RETURNN greeting to the log.

  :param str|None config_filename:
  :param list[str]|None command_line_options:
  """
    print(
        "RETURNN starting up, version %s, date/time %s, pid %i, cwd %s, Python %s"
        % (describe_returnn_version(),
           time.strftime("%Y-%m-%d-%H-%M-%S (UTC%z)"), os.getpid(),
           os.getcwd(), sys.executable),
        file=log.v3)
    if config_filename:
        print("RETURNN config: %s" % config_filename, file=log.v4)
        if os.path.islink(config_filename):
            print("RETURNN config is symlink to: %s" %
                  os.readlink(config_filename),
                  file=log.v4)
    if command_line_options is not None:
        print("RETURNN command line options: %s" % (command_line_options, ),
              file=log.v4)
    import socket
    print("Hostname:", socket.gethostname(), file=log.v4)
Esempio n. 2
0
def main():
    """
  Main entry.
  """
    global LstmCellTypes
    print("Benchmarking LSTMs.")
    better_exchook.install()
    print("Args:", " ".join(sys.argv))
    arg_parser = ArgumentParser()
    arg_parser.add_argument("cfg",
                            nargs="*",
                            help="opt=value, opt in %r" %
                            sorted(base_settings.keys()))
    arg_parser.add_argument("--no-cpu", action="store_true")
    arg_parser.add_argument("--no-gpu", action="store_true")
    arg_parser.add_argument("--selected",
                            help="comma-separated list from %r" %
                            LstmCellTypes)
    arg_parser.add_argument("--no-setup-tf-thread-pools", action="store_true")
    args = arg_parser.parse_args()
    for opt in args.cfg:
        key, value = opt.split("=", 1)
        assert key in base_settings
        value_type = type(base_settings[key])
        base_settings[key] = value_type(value)
    print("Settings:")
    pprint(base_settings)

    log.initialize(verbosity=[4])
    print("Returnn:", describe_returnn_version(), file=log.v3)
    print("TensorFlow:", describe_tensorflow_version(), file=log.v3)
    print("Python:", sys.version.replace("\n", ""), sys.platform)
    if not args.no_setup_tf_thread_pools:
        setup_tf_thread_pools(log_file=log.v2)
    else:
        print(
            "Not setting up the TF thread pools. Will be done automatically by TF to number of CPU cores."
        )
    if args.no_gpu:
        print("GPU will not be used.")
    else:
        print("GPU available: %r" % is_gpu_available())
    print_available_devices()

    if args.selected:
        LstmCellTypes = args.selected.split(",")
    benchmarks = {}
    if not args.no_gpu and is_gpu_available():
        for lstm_unit in LstmCellTypes:
            benchmarks["GPU:" + lstm_unit] = benchmark(lstm_unit=lstm_unit,
                                                       use_gpu=True)
    if not args.no_cpu:
        for lstm_unit in LstmCellTypes:
            if lstm_unit in GpuOnlyCellTypes:
                continue
            benchmarks["CPU:" + lstm_unit] = benchmark(lstm_unit=lstm_unit,
                                                       use_gpu=False)

    print("-" * 20)
    print("Settings:")
    pprint(base_settings)
    print("Final results:")
    for t, lstm_unit in sorted([
        (t, lstm_unit) for (lstm_unit, t) in sorted(benchmarks.items())
    ]):
        print("  %s: %s" % (lstm_unit, hms_fraction(t)))
    print("Done.")