Download lib/python3.12/site-packages/hydra/core/singleton.py from parallel-reasoner/env-full: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/parallel-reasoner/env-full/resolve/7db01aa111f155a37446aa51b2e050c094ac72ab/lib/python3.12/site-packages/hydra/core/singleton.py
- Command line
-
hf download hf://parallel-reasoner/env-full@7db01aa111f155a37446aa51b2e050c094ac72ab/lib/python3.12/site-packages/hydra/core/singleton.py
-
curl -L -o singleton.py https://huggingface.co/parallel-reasoner/env-full/resolve/7db01aa111f155a37446aa51b2e050c094ac72ab/lib/python3.12/site-packages/hydra/core/singleton.py
1.34 kB
| # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved | |
| from copy import deepcopy | |
| from typing import Any, Dict | |
| from omegaconf.basecontainer import BaseContainer | |
| class Singleton(type): | |
| _instances: Dict[type, "Singleton"] = {} | |
| def __call__(cls, *args: Any, **kwargs: Any) -> Any: | |
| if cls not in cls._instances: | |
| cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) | |
| return cls._instances[cls] | |
| def instance(cls: Any, *args: Any, **kwargs: Any) -> Any: | |
| return cls(*args, **kwargs) | |
| def get_state() -> Any: | |
| instances = deepcopy(Singleton._instances) | |
| # Plugins can cause issues for pickling the singleton state | |
| # Exclude them and re-initialize them on set_state() | |
| from hydra.core.plugins import Plugins | |
| instances.pop(Plugins, None) | |
| return { | |
| "instances": instances, | |
| "omegaconf_resolvers": deepcopy(BaseContainer._resolvers), | |
| } | |
| def set_state(state: Any) -> None: | |
| Singleton._instances = state["instances"] | |
| # Reinitialize the the Plugin singleton (discover all plugins etc). | |
| from hydra.core.plugins import Plugins | |
| Plugins.instance() | |
| BaseContainer._resolvers = deepcopy(state["omegaconf_resolvers"]) | |