comet-ml / issue-tracking

Questions, Help, and Issues for Comet ML
https://www.comet.ml
85 stars 7 forks source link

Code is not logged when using also using Facebook Hydra framework #379

Closed bradenkinard closed 1 year ago

bradenkinard commented 4 years ago

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()
dsblank commented 4 years ago

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

dsblank commented 4 years ago

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 commented 4 years ago

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...

bradenkinard commented 4 years ago

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

github-actions[bot] commented 1 year ago

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] commented 1 year ago

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