issue-tracking icon indicating copy to clipboard operation
issue-tracking copied to clipboard

Code is not logged when using also using Facebook Hydra framework

Open bradenkinard opened this issue 4 years ago • 4 comments

Hydra is a popular framework for composing configuration files. Its typical usage involves using a decorator that points to your configuration yaml file on your main function. However, when this is done, Comet will fail to log the script's code.

The following is a minimal example in which the code is properly logged, as the Hydra configuration is not used:

from comet_ml import Experiment


def main():
    experiment = Experiment(project_name="my_project", workspace="my_workspace", log_code=True)
    print("Hello, world")


if __name__ == "__main__":
    main()

Once the hydra is used to implement a configuration (here it is an arbitrary YAML file at configs/config.yaml), the code will now fail to log to Comet:

import hydra
from comet_ml import Experiment


@hydra.main(config_path="configs", config_name="config")
def main(cfg):
    experiment = Experiment(project_name="my_project", workspace="my_workspace", log_code=True)
    print("Hello, world")


if __name__ == "__main__":
    main()

bradenkinard avatar Sep 22 '20 15:09 bradenkinard

@bradenkinard Thanks for the easily-reproducible report! We're taking a look at this.

dsblank avatar Sep 22 '20 15:09 dsblank

Yes, we can reproduce the bug. Seems to be related to hydra changing the working directory away from the source code. We're working on both a workaround, and a solution.

dsblank avatar Sep 22 '20 19:09 dsblank

Here is a workaround:

import hydra
from comet_ml import Experiment


@hydra.main(config_path="configs", config_name="config")
def main(cfg):
    experiment = Experiment(project_name="my_project", log_code=False)
    experiment.set_code(filename=hydra.utils.to_absolute_path(__file__))
    print("Hello, world")


if __name__ == "__main__":
    main()

Working on a solution. Stay tuned...

dsblank avatar Sep 23 '20 15:09 dsblank

Thanks. The workaround is very helpful. And thanks for the quick response on this!

bradenkinard avatar Sep 23 '20 17:09 bradenkinard

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 06 '23 21:11 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Nov 11 '23 21:11 github-actions[bot]