Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Hydra Configuration file in Google Collab #2

Open
Elappnano opened this issue Jan 2, 2024 · 0 comments
Open

Issues with Hydra Configuration file in Google Collab #2

Elappnano opened this issue Jan 2, 2024 · 0 comments

Comments

@Elappnano
Copy link

Hi, to implement the app in the google colab I used

from hydra import initialize, compose
if __name__ == "__main__":
    with initialize(version_base=None, config_path="configs"):
        cfg = compose(config_name="config.yaml")
        main(cfg)

but the following error is raised.

---------------------------------------------------------------------------
InterpolationResolutionError              Traceback (most recent call last)
[<ipython-input-28-7740892df83b>](https://localhost:8080/#) in <cell line: 2>()
      3     with initialize(version_base=None, config_path="configs"):
      4         cfg = compose(config_name="config.yaml")
----> 5         main(cfg)

28 frames
[<ipython-input-2-39423ea7b27c>](https://localhost:8080/#) in main(cfg)
     75     # apply extra utilities
     76     # (e.g. ask for tags if none are provided in cfg, print cfg tree, etc.)
---> 77     pinnstf2.utils.extras(cfg)
     78 
     79     # train the model

[/usr/local/lib/python3.10/dist-packages/pinnstf2/utils/utils.py](https://localhost:8080/#) in extras(cfg)
     36     if cfg.extras.get("enforce_tags"):
     37         log.info("Enforcing tags! <cfg.extras.enforce_tags=True>")
---> 38         rich_utils.enforce_tags(cfg, save_to_file=True)
     39 
     40     # pretty print config tree using Rich library

[/usr/local/lib/python3.10/dist-packages/pinnstf2/utils/rich_utils.py](https://localhost:8080/#) in enforce_tags(cfg, save_to_file)
     93 
     94     if save_to_file:
---> 95         with open(Path(cfg.paths.output_dir, "tags.log"), "w") as file:
     96             rich.print(cfg.tags, file=file)

[/usr/local/lib/python3.10/dist-packages/omegaconf/dictconfig.py](https://localhost:8080/#) in __getattr__(self, key)
    357             )
    358         except Exception as e:
--> 359             self._format_and_raise(key=key, value=None, cause=e)
    360 
    361     def __getitem__(self, key: DictKeyType) -> Any:

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in _format_and_raise(self, key, value, cause, msg, type_override)
    229         type_override: Any = None,
    230     ) -> None:
--> 231         format_and_raise(
    232             node=self,
    233             key=key,

[/usr/local/lib/python3.10/dist-packages/omegaconf/_utils.py](https://localhost:8080/#) in format_and_raise(node, key, value, msg, cause, type_override)
    897         ex.ref_type_str = ref_type_str
    898 
--> 899     _raise(ex, cause)
    900 
    901 

[/usr/local/lib/python3.10/dist-packages/omegaconf/_utils.py](https://localhost:8080/#) in _raise(ex, cause)
    795     else:
    796         ex.__cause__ = None
--> 797     raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
    798 
    799 

[/usr/local/lib/python3.10/dist-packages/omegaconf/dictconfig.py](https://localhost:8080/#) in __getattr__(self, key)
    349 
    350         try:
--> 351             return self._get_impl(
    352                 key=key, default_value=_DEFAULT_MARKER_, validate_key=False
    353             )

[/usr/local/lib/python3.10/dist-packages/omegaconf/dictconfig.py](https://localhost:8080/#) in _get_impl(self, key, default_value, validate_key)
    449                 raise
    450         assert isinstance(node, Node)
--> 451         return self._resolve_with_default(
    452             key=key, value=node, default_value=default_value
    453         )

[/usr/local/lib/python3.10/dist-packages/omegaconf/basecontainer.py](https://localhost:8080/#) in _resolve_with_default(self, key, value, default_value)
     96             raise MissingMandatoryValue("Missing mandatory value: $FULL_KEY")
     97 
---> 98         resolved_node = self._maybe_resolve_interpolation(
     99             parent=self,
    100             key=key,

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in _maybe_resolve_interpolation(self, parent, key, value, throw_on_resolution_failure, memo)
    717 
    718         parse_tree = parse(_get_value(value))
--> 719         return self._resolve_interpolation_from_parse_tree(
    720             parent=parent,
    721             value=value,

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in _resolve_interpolation_from_parse_tree(self, parent, value, key, parse_tree, throw_on_resolution_failure, memo)
    582 
    583         try:
--> 584             resolved = self.resolve_parse_tree(
    585                 parse_tree=parse_tree, node=value, key=key, memo=memo
    586             )

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in resolve_parse_tree(self, parse_tree, node, memo, key)
    767         except Exception as exc:
    768             # Other kinds of exceptions are wrapped in an `InterpolationResolutionError`.
--> 769             raise InterpolationResolutionError(
    770                 f"{type(exc).__name__} raised while resolving interpolation: {exc}"
    771             ).with_traceback(sys.exc_info()[2])

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in resolve_parse_tree(self, parse_tree, node, memo, key)
    762         )
    763         try:
--> 764             return visitor.visit(parse_tree)
    765         except InterpolationResolutionError:
    766             raise

[/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py](https://localhost:8080/#) in visit(self, tree)
     32 class ParseTreeVisitor(object):
     33     def visit(self, tree):
---> 34         return tree.accept(self)
     35 
     36     def visitChildren(self, node):

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar/gen/OmegaConfGrammarParser.py](https://localhost:8080/#) in accept(self, visitor)
    204         def accept(self, visitor:ParseTreeVisitor):
    205             if hasattr( visitor, "visitConfigValue" ):
--> 206                 return visitor.visitConfigValue(self)
    207             else:
    208                 return visitor.visitChildren(self)

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar_visitor.py](https://localhost:8080/#) in visitConfigValue(self, ctx)
     99         # text EOF
    100         assert ctx.getChildCount() == 2
--> 101         return self.visit(ctx.getChild(0))
    102 
    103     def visitDictKey(self, ctx: OmegaConfGrammarParser.DictKeyContext) -> Any:

[/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py](https://localhost:8080/#) in visit(self, tree)
     32 class ParseTreeVisitor(object):
     33     def visit(self, tree):
---> 34         return tree.accept(self)
     35 
     36     def visitChildren(self, node):

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar/gen/OmegaConfGrammarParser.py](https://localhost:8080/#) in accept(self, visitor)
    340         def accept(self, visitor:ParseTreeVisitor):
    341             if hasattr( visitor, "visitText" ):
--> 342                 return visitor.visitText(self)
    343             else:
    344                 return visitor.visitChildren(self)

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar_visitor.py](https://localhost:8080/#) in visitText(self, ctx)
    296             c = ctx.getChild(0)
    297             if isinstance(c, OmegaConfGrammarParser.InterpolationContext):
--> 298                 return self.visitInterpolation(c)
    299 
    300         # Otherwise, concatenate string representations together.

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar_visitor.py](https://localhost:8080/#) in visitInterpolation(self, ctx)
    123     ) -> Any:
    124         assert ctx.getChildCount() == 1  # interpolationNode | interpolationResolver
--> 125         return self.visit(ctx.getChild(0))
    126 
    127     def visitInterpolationNode(

[/usr/local/lib/python3.10/dist-packages/antlr4/tree/Tree.py](https://localhost:8080/#) in visit(self, tree)
     32 class ParseTreeVisitor(object):
     33     def visit(self, tree):
---> 34         return tree.accept(self)
     35 
     36     def visitChildren(self, node):

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar/gen/OmegaConfGrammarParser.py](https://localhost:8080/#) in accept(self, visitor)
   1039         def accept(self, visitor:ParseTreeVisitor):
   1040             if hasattr( visitor, "visitInterpolationResolver" ):
-> 1041                 return visitor.visitInterpolationResolver(self)
   1042             else:
   1043                 return visitor.visitChildren(self)

[/usr/local/lib/python3.10/dist-packages/omegaconf/grammar_visitor.py](https://localhost:8080/#) in visitInterpolationResolver(self, ctx)
    177                 args_str.append(txt)
    178 
--> 179         return self.resolver_interpolation_callback(
    180             name=resolver_name,
    181             args=tuple(args),

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in resolver_interpolation_callback(name, args, args_str)
    748             name: str, args: Tuple[Any, ...], args_str: Tuple[str, ...]
    749         ) -> Any:
--> 750             return self._evaluate_custom_resolver(
    751                 key=key,
    752                 node=node,

[/usr/local/lib/python3.10/dist-packages/omegaconf/base.py](https://localhost:8080/#) in _evaluate_custom_resolver(self, key, node, inter_type, inter_args, inter_args_str)
    692         if resolver is not None:
    693             root_node = self._get_root()
--> 694             return resolver(
    695                 root_node,
    696                 self,

[/usr/local/lib/python3.10/dist-packages/omegaconf/omegaconf.py](https://localhost:8080/#) in resolver_wrapper(config, parent, node, args, args_str)
    443                 kwargs["_root_"] = config
    444 
--> 445             ret = resolver(*args, **kwargs)
    446 
    447             if use_cache:

[/usr/local/lib/python3.10/dist-packages/hydra/core/utils.py](https://localhost:8080/#) in <lambda>(path)
    218     OmegaConf.register_new_resolver(
    219         "hydra",
--> 220         lambda path: OmegaConf.select(cast(DictConfig, HydraConfig.get()), path),
    221         replace=True,
    222     )

[/usr/local/lib/python3.10/dist-packages/hydra/core/hydra_config.py](https://localhost:8080/#) in get()
     29         instance = HydraConfig.instance()
     30         if instance.cfg is None:
---> 31             raise ValueError("HydraConfig was not set")
     32         return instance.cfg.hydra  # type: ignore
     33 
InterpolationResolutionError: ValueError raised while resolving interpolation: HydraConfig was not set
    full_key: paths.output_dir
    object_type=dict

I'm not sure what's going wrong with hydra setup that raises this problem, and I'd very much appreciate any help on this. Thanks!

@rezaakb rezaakb assigned rezaakb and unassigned rezaakb Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants