I know that I can change the working dir in config by setting hydra.run.dir=XXX
from the command line.
But how to do it properly from script w/o using CLI arguments in a way that even the logs are saved in the dir which I set?
This code won't work because:
- the hydra and its loggers are already initialized when I try to change the dir and
- there is no such attribute
cfg.hydra
.
UPD: I got a pointer in the comments. I could change the hydra parameters in the block if __name__ == 'main':
before hydra is called. But how to get access and modify hydra.run.dir
from the script?
@hydra.main(config_path="conf", config_name="config")
def main(cfg):
cfg.hydra.run.dir = "./c_out/cached_loss" # no such attribute
logger.info('I log something')
My hydra config looks like this:
defaults:
- hydra/job_logging: custom_logging
# hydra/custom_logging.yaml
# python logging configuration for tasks
version: 1
formatters:
simple:
format: '[%(asctime)s][%(name)s][%(levelname)s] - %(message)s'
handlers:
console:
class: logging.StreamHandler
formatter: simple
stream: ext://sys.stdout
file:
class: logging.FileHandler
formatter: simple
# relative to the job log directory
filename: ${hydra.job.name}.log
root:
level: INFO
handlers: [console, file]
disable_existing_loggers: false
if __name__ == 'main':
block, I assume it is called before hydra. I could try to change the parameters there, however there is no obvious way since hydra hides its internal config from the user after the script is launched. – Bedwarmer