Skip to content

Support filesystem paths for config_file in build_sam2 / build_sam2_video_predictor - #771

Open
Sanjays2402 wants to merge 1 commit into
facebookresearch:mainfrom
Sanjays2402:fix-build-sam2-config-path
Open

Sanjays2402 wants to merge 1 commit into
facebookresearch:mainfrom
Sanjays2402:fix-build-sam2-config-path

Conversation

@Sanjays2402

Copy link
Copy Markdown

build_sam2() and build_sam2_video_predictor() pass config_file straight to Hydra as compose(config_name=...), so a filesystem path (e.g. an absolute path to a user-provided config) fails with MissingConfigException -- Hydra resolves config names against its config search path, not arbitrary paths. Reported in #758 (also #531, #701).

This PR adds a small _compose_config() helper used by both builders: if config_file is an existing filesystem path, its containing directory is temporarily added to Hydra's config search path (via a short-lived ConfigStore wrapper primary config, following the approach @omry outlined in #758), and the config is composed from there. That keeps the config's own defaults list and relative subconfigs resolving, and the wrapper entry is always removed from the ConfigStore afterwards, even on failure. Plain config names (e.g. "configs/sam2.1/sam2.1_hiera_l.yaml") behave exactly as before, as do nonexistent names (still MissingConfigException).

Also documented the config_file contract in both builders' docstrings.

Fixes #758.

Test evidence (local, hydra-core 1.3.6 / omegaconf 2.3.1, with a stub sam2 package mirroring initialize_config_module("sam2", version_base="1.2") since torch isn't installed here):

  • bundled config name configs/sam2.1/sam2.1_hiera_t.yaml composes as before
  • absolute path to an external config whose defaults list references sibling subconfigs now resolves (previously raised MissingConfigException -- bug reproduced before the fix)
  • relative paths and pathlib.Path inputs work; hydra_overrides_extra overrides still apply to externally composed configs
  • nonexistent config names still raise MissingConfigException (unchanged behavior)
  • no _sam2_external_config_* leftovers in ConfigStore after success or failure
  • black==24.2.0 and usort==1.0.2 checks pass (the ufmt toolchain from CONTRIBUTING)

@meta-cla meta-cla Bot added the cla signed label Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clarify build_sam2 config_file contract and support external config dirs

1 participant