Why Exceptions will become warning in hydra? #2832
-
For example: # callback.py
class InitCallback(Callback):
def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:
# fix random seed for reproducibility
prnt(config.seed) # main.py
import hydra
import numpy as np
from omegaconf import DictConfig
@hydra.main(version_base=None, config_path="./", config_name="config.yaml")
def main(cfg: DictConfig):
print("==Enter main==")
if __name__ == "__main__":
main() now if we dont define /lib/python3.9/site-packages/hydra/_internal/callbacks.py:28: UserWarning: Callback InitCallback.on_job_start raised ConfigAttributeError: Key 'seed' is not in struct
full_key: seed
object_type=dict
warnings.warn(
==Enter main== So how can I disable the warning and change the exception back to a real Exception but not warning, because I want raise an exception to stop program rather than just a warning which will not stop program |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
I had a quick look at the code and it looks like there's currently no built-in way to raise the exception, as it's automatically converted into a warning. What I believe you could do (untested) is to use |
Beta Was this translation helpful? Give feedback.
-
I found this could work, hydra can not change exit to warnings: # callback.py
class InitCallback(Callback):
def on_job_start(self, config: DictConfig, **kwargs: Any) -> None:
# fix random seed for reproducibility
+ try:
print(config.seed)
+ except Exception as e:
+ print(e)
+ sys.exit(0)
|
Beta Was this translation helpful? Give feedback.
I agree it's probably not such a good idea as default behavior -- I don't know what was the original motivation behind it. Note though that the callback feature is still in "experimental" mode and thus subject to change.