Hi,
I am trying to use the pytorch bottleneck profiler (python -m torch.utils.bottleneck train.py) which apparently has to run the hydra-decorated main() function twice and results in the error
AssertionError: GlobalHydra is already initialized
Is there a way to reset the state of the GlobalHydra singleton manually or another workaround to make the profiler work with hydra?
Thanks
You can try calling the clear function at the end of your hydra.main function:
Ah cool. Had some trouble finding how to actually call this; in the end, hydra._internal.hydra.GlobalHydra.get_state().clear() worked.
Yup.
Note that GlobalHydra is being promoted out of _internal in the next version and will be here.
Ah, you are using it wrong (I suspect you are clearing all signletons which may have incidentally been what you want but not what you asked for).
try, in 0.11, try:
hydra._internal.hydra.GlobalHydra().clear()
In the next version it will be (I think):
hydra.core.global_hydra.GlobalHydra.instance().clear()
Okay, I also tried those two (I'm on version 0.11.3):
hydra._internal.hydra.GlobalHydra().clear() gave me TypeError: clear() missing 1 required positional argument: 'self' (which makes sense I guess) and hydra._internal.hydra.GlobalHydra.instance().clear() raises AttributeError: type object 'GlobalHydra' has no attribute 'instance'Ah sorry, hydra._internal.hydra.GlobalHydra.clear() doesn't work, hydra._internal.hydra.GlobalHydra().clear() does.
Thanks again!
The above PR will fix this the next major version of Hydra.