Hydra: [Bug] hydra breaks relative paths in config file

Created on 26 Aug 2020  路  6Comments  路  Source: facebookresearch/hydra

馃悰 Bug

Description

In my config file, test_config.yaml I have:

DATA:
  BGR: true
  COCO_ANNOTATIONS: null
  CROP_HEIGHT: 64
  CROP_WIDTH: 256
  DATA_DIR: ../datasets/train

Checklist

  • [x] I checked on the latest version of Hydra
  • [x] I created a minimal repro

To reproduce

* Minimal Code/Config snippet to reproduce *

import hydra

@hydra.main(config_name="test_config.yaml")
def run(cfg):
    print(os.getcwd())

* Stack trace/error message *

normal_work_dir/outputs/2020-08-26/12-40-31

Expected Behavior

The normal working directory should not change.

System information

  • Hydra Version : hydra-core==1.0.0rc4
  • Python version : Python 3.6.9
  • Virtual environment type and version : Custom TF2.3 docker version
  • Operating system : Linux

Additional context

/

bug

Most helpful comment

This is the default Hydra behavior. More info can be found on this doc https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory

If you want the path to work in the you original working dir, you can do
hydra.utils.get_original_cwd()

All 6 comments

This is the default Hydra behavior. More info can be found on this doc https://hydra.cc/docs/next/tutorials/basic/running_your_app/working_directory

If you want the path to work in the you original working dir, you can do
hydra.utils.get_original_cwd()

We do have an open issue to support disabling this behavior :) https://github.com/facebookresearch/hydra/issues/910

@jieru-hu : Thanks for linking to the docs. I tried searching for it, but I didn't find it. My bad!
To me, it's a bit counter-intuitive that the whole cwd changes inside the decorated function.
Anyway, nice to hear we might be able to disable it in the future.

Hi, how exactly should one use hydra.utils.get_original_cwd() ? I tried adding os.chdir(the_correct_dir) before my function call in hydra, however the relative imports are still not working.

hydra.utils.get_original_cwd()

Did you try ?

os.chdir(hydra.utils.get_original_cwd())

Pls provide a mini repro so its easier for us to help you.

Relative imports (Python imports) has nothing to do with the cwd.
Please file a different issue with a minimal repro.

Was this page helpful?
0 / 5 - 0 ratings