Skip to content

Instantiating a class with Union-typed fields doesn't work if it's a recursive instantiation #1236

@Zirunis

Description

@Zirunis

Describe the bug
I'm aware of #144 but not sure if this is the same use-case. In my use-case at the time of instantiation values are provided. I don't need OmegaConf to do any magic, it just needs to plug the int into the function.
It seems to me that this use-case is smaller in scope than what #144 is asking for and should be supported? Or am I misunderstanding something there?
Is there some workaround I'm not aware of?

To Reproduce
Signature of equinox..nn.Linear for context:

def __init__(
    self,
    in_features: int | Literal["scalar"],  # This is the problem
    out_features: int | Literal["scalar"],  # This is the problem
    use_bias: bool = True,
    dtype=None,
    *,
    key: PRNGKeyArray,
):

Instantiating this model works:

d_model: 256
model:
  _target_: equinox.nn.Linear
  in_features: ${d_model}
  out_features: 1000
  key: ${runtime:"key_splitter()"}  # runtime is a custom resolver, not relevant to this report

Instantiating this model doesn't work:

d_model: 256
model:
  _target_: equinox.nn.Sequential
  _args_:
    - _target_: equinox.nn.Linear
      in_features: ${d_model}
      out_features: 1000
      key: ${runtime:"key_splitter()"}  # runtime is a custom resolver, not relevant to this report

It throws:

omegaconf.errors.ConfigValueError: Unions of containers are not supported:
in_features: Union[int, Literal[scalar]]
    full_key:
    object_type=None

Expected behavior
I don't see a reason why these two would behave differently. Manually instantiating the inner class first and then the outer would work, so there is clearly no additional information required.

Additional context

  • OmegaConf version: 2.4.0.dev4
  • Python version: 3.13
  • Operating system: Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions