Log_code not working with hydra

Hello to all,

I am new here. I would like to save my files to the wandb experiment .
This was also working before I used hydra. Since Hydra is changing the run dir.
I also adapted the wandb.run.log_code(root=) to the where files are.
Still not working.
Has someone an Idea How to fix it

Thank you very much
Best regards
Chris

Hi Chris,

Thanks for writing in! I was wondering if you could send me a code snippet and so I can see how are you trying to save your files. Also, here is our documentation on how to integrate Hydra with wandb, may it help you?

Best,
Luis

Blockquote
run_name = cfg.details.run_name + f"{cfg.name}_{cfg.details.job_type}seed{cfg.seed}"
import wandb
wandb.init(
project=“master_lab_irl”,
name=run_name,
sync_tensorboard=True,
monitor_gym=True,
save_code=True,
settings=wandb.Settings(code_dir=“/home/l-oktober/lab_master/src/inverse_rl/”),
job_type=cfg.details.job_type,
)

    wandb.run.log_code(root= "/home/l-/oktober/lab_master/src/inverse_rl/")

Without Hydra I did wandb.run.log_code((“.”) and it worked
I had a look at the documentation but havent found something

Thank you for your help

Do you need more Information ?

Hi Chris,

Sorry for my late response! I am having some troubles trying to reproduce this issue. I have found a more detail guide here and a complete hydra example here. Please let me know if this would be useful. I will keep trying to reproduce this issue. Thanks!

Best,
Luis

Hi Luis,

where can I find this example ?

I found some but all are without saving the code (all .py files)

Hi Chris,

Thanks for your patience! I’ve been able to investigate this in depth and reproduce the issue. Just to confirm that you are having the same behaviour:

  • First I have run a simple code and run.log_code() is saving the .py file in the desired folder and uploading an artifact
  • When I have integrated hydra, the .py file is not saved in the root argument directory and the artifact is not uploaded to W&B.
    Could you confirm me if you are experiencing the same issue and so I will report this?

Best,
Luis

yes it seems that wandb save the files in the wandb.root or similar
and this is by hydra a different dir then the dir the .py is run .
if I do wandb.run.log_code(root= ) and change it to the orginal dir where the .py files are its still not working.
It seems that is because wandb gets the wandb.root with os current dir and this false.
And I tried to change it but its not working
Maybe you can help me ( and are able to follow me)
thanks

yes so its not possible to make a quick fix ?

Hi Chris,

Thanks for answering back! I have gone through our entire conversation again and I think I have been able to solve this issue. I am running a code like this in main.py file:

import hydraimport omegaconfimport wandb@hydra.main(config_path="configs/", config_name="defaults")def run_experiment(cfg: omegaconf.DictConfig) -> None: with wandb.init(entity=cfg.wandb.entity, project=cfg.wandb.project) as run: for i in range(5): run.log({'accuracy':i}) run.log_code(root=cfg.wandb.dir)run_experiment()

And my defaults.yaml config file is like:

---wandb: project: project_name entity: entity_name dir: <folder where main.py is>

And I can see inside my artifacts tab, in the files page, the main.py file. Could you share is there is something different in your workflow? Also, if this is still not working for you, a workaround may be creating a new artifact and adding your .py files with add_file (docs here). Please let me know if this would be useful. Thanks!

Best,
Luis

Hi Chris,

We wanted to follow up with you regarding your support request as we have not heard back from you. Please let us know if we can be of further assistance or if your issue has been resolved.

Best,
Luis

sorry I did somehow did not see that you answered me
Thank you very much for your answer and yes it works
The code its not where it was used to be but it a qiuck fix

THank you very much and
Please keep up your great work

Hi Chris,

No worries at all! Great to know that this code is working for you snd thank you very much for the kind words. May I help you in any other way?

Best,
Luis