Disable file output of hydra
Asked Answered
J

2

5

I'm using hydra to log hyperparameters of experiments.

@hydra.main(config_name="config", config_path="../conf")
def evaluate_experiment(cfg: DictConfig) -> None:
    print(OmegaConf.to_yaml(cfg))
    ...

Sometimes I want to do a dry run to check something. For this I don't need any saved parameters, so I'm wondering how I can disable the savings to the filesystem completely in this case?

Joesphjoete answered 2/12, 2020 at 7:54 Comment(0)
D
11

There is an enhancement request aimed at Hydra 1.1 to support disabling working directory management. Working directory management is doing many things:

  • Creating a working directory for the run
  • Changing the working directory to the created dir.

There are other related features:

  • Saving log files
  • Saving files like config.yaml and hydra.yaml into .hydra in the working directory.

Different features has different ways to disable them:

  1. To prevent the creation of a working directory, you can override hydra.run.dir to ..
  2. To prevent saving the files into .hydra, override hydra.output_subdir to null.
  3. To prevent the creation of logging files, you can disable logging output of hydra/hydra_logging and hydra/job_logging, see this.

A complete example might look like:

$ python foo.py hydra.run.dir=. hydra.output_subdir=null hydra/job_logging=disabled hydra/hydra_logging=disabled

Note that as always you can also override those config values through your config file.

Dispersive answered 6/12, 2020 at 19:13 Comment(2)
I there a way to add this to DictConfig?Shelleyshellfire
Latest Hydra is no longer changing working directory by default. If you want to change logging behavior check this link: hydra.cc/docs/configure_hydra/loggingDispersive
E
19

The answer from Omry Yadan works well if you want to solve this using the CLI. However, you can also add these flags to your config file such that you don't have to type them every time you run your script. If you want to go this route, make sure you add the following items in your root config file:

defaults:  
  - _self_  
  - override hydra/hydra_logging: disabled  
  - override hydra/job_logging: disabled  
  
hydra:  
  output_subdir: null  
  run:  
    dir: .
Eastlake answered 19/1, 2022 at 20:28 Comment(3)
Hello, thank you very much for the clarification. In my particular case, I would like the logging to appear in the terminal but not to create the files. Also, I would like the log to be coloured. The hydra field would be tha same but the defaults will be set as colorlog. Is that correct?Matthei
@J smit , can you explain the meaning of this config?Kaenel
_self_ indicates the order of this config when merging multiple configurations. Normaly it is at the end. Putting _self_ at first position allows that this config can be overwritten by others. output_subdir: null disables the creation of the .hydra directory. override hydra/... states that the config named hydra... should be overwritten.Corruptible
D
11

There is an enhancement request aimed at Hydra 1.1 to support disabling working directory management. Working directory management is doing many things:

  • Creating a working directory for the run
  • Changing the working directory to the created dir.

There are other related features:

  • Saving log files
  • Saving files like config.yaml and hydra.yaml into .hydra in the working directory.

Different features has different ways to disable them:

  1. To prevent the creation of a working directory, you can override hydra.run.dir to ..
  2. To prevent saving the files into .hydra, override hydra.output_subdir to null.
  3. To prevent the creation of logging files, you can disable logging output of hydra/hydra_logging and hydra/job_logging, see this.

A complete example might look like:

$ python foo.py hydra.run.dir=. hydra.output_subdir=null hydra/job_logging=disabled hydra/hydra_logging=disabled

Note that as always you can also override those config values through your config file.

Dispersive answered 6/12, 2020 at 19:13 Comment(2)
I there a way to add this to DictConfig?Shelleyshellfire
Latest Hydra is no longer changing working directory by default. If you want to change logging behavior check this link: hydra.cc/docs/configure_hydra/loggingDispersive

© 2022 - 2024 — McMap. All rights reserved.