Skip to content

[Feature Request] Add option to replace "/" in hydra.job.override_dirname #3018

Closed

Description

@stefangstark

If overrides contain a / then a subdirectory is created when using hydra.job.override_dirname. The referenced discussion suggests to write a custom function that replaces instances of /. However, it would be convenient if this was done using a mechanism similar to e.g. hydra.job.config.override_dirname.kv_sep.

Discussed in #2409

Originally posted by Aceticia October 9, 2022
I'm using the override_dirname as the folder to store checkpoints and logs. This does store the logs, but since my configs contain overrides with /, hydra ended up not treating them as part of the subdir but as a directory under the subdir, creating one redundant level of folder each time I override something. This is a pretty small inconvenience, and it would probably be very difficult to fix (how to differentiate where user actually want a subdirectory but not override?), but I imagine it's not the intended behavior?

For more details, here is how I'm overriding some configs. If there is an alternative where I can just not use / overrides I guess that would solve the issue too.

models
- default.yaml
- temporal_nets
    - net1.yaml
    - net2.yaml

In net1.yaml and net2.yaml, there are configurations for neural networks including __target__ instantiations and their hyperparameters. In default.yaml I simply have a default list of using net1.yaml. When I do need to run an experiment with net2, I just override with models/temporal_nets=net2. What are alternative ways to organize the configs, so that I can override the choice of temporal_nets? Any suggestions would be appreciated. Thank you.

Activity

  1. changed the title [-]Add option to replace "/" in hydra.job.override_dirname[/-] [+][Feature Request] Add option to replace "/" in hydra.job.override_dirname[/+] on Feb 1, 2025
  2. omry commented on Jun 25, 2026

    @omry
    Collaborator

    Thanks for the report. This is addressed in #3241 for Hydra 1.4 by moving override_dirname toward a resolver-based API.

    Instead of adding more special-case options to hydra.job.override_dirname, Hydra 1.4 adds ${hydra_override_dirname:...}. It supports the existing formatting options, and also lets users provide an optional per-element resolver. That makes cases like replacing path separators configurable without baking one behavior into Hydra.

    Example:

    from omegaconf import OmegaConf
    
    OmegaConf.register_new_resolver(
        "pathsafe",
        lambda s: s.replace("/", "_").replace("\\", "_"),
    )
    hydra:
      sweep:
        subdir: '${hydra_override_dirname:{element_resolver: pathsafe}}'

    The element resolver needs to be registered before Hydra starts composing/running the app.

    The old hydra.job.override_dirname behavior is preserved for compatibility in 1.4, but it is deprecated in favor of the resolver form because the resolver can be configured at the use site or replaced entirely by user-defined behavior.

  3. added 2 commits that reference this issue on Jun 25, 2026
    de5e122
    c0e3dc3
  4. added a commit that references this issue on Jun 25, 2026
    feca259
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions