Stability-AI/generative-models · error · ValueError
unknown merge strategy {merge_strategy}
Error message
unknown merge strategy {merge_strategy} What it means
The merge-strategy constructor in video_model.py (VideoResBlock path) accepts merge_strategy values including 'fixed_with_images'; anything else raises ValueError('unknown merge strategy {merge_strategy}'). The strategy determines how spatial and temporal features are blended via the mix_factor parameter.
Source
Thrown at sgm/modules/diffusionmodules/video_model.py:561
time_embed_dim = self.in_channels * 4
self.time_mix_time_embed = nn.Sequential(
linear(self.in_channels, time_embed_dim),
nn.SiLU(),
linear(time_embed_dim, self.in_channels),
)
self.use_spatial_context = use_spatial_context
if merge_strategy == "fixed":
self.register_buffer("mix_factor", th.Tensor([merge_factor]))
elif merge_strategy == "learned" or merge_strategy == "learned_with_images":
self.register_parameter(
"mix_factor", th.nn.Parameter(th.Tensor([merge_factor]))
)
elif merge_strategy == "fixed_with_images":
self.mix_factor = None
else:
raise ValueError(f"unknown merge strategy {merge_strategy}")
self.get_alpha_fn = functools.partial(
get_alpha,
merge_strategy,
self.mix_factor,
apply_sigmoid=apply_sigmoid_to_merge,
)
def forward(
self,
x: th.Tensor,
context: Optional[th.Tensor] = None,
# cam: Optional[th.Tensor] = None,
time_context: Optional[th.Tensor] = None,
timesteps: Optional[int] = None,
image_only_indicator: Optional[th.Tensor] = None,
conv_view: Optional[th.Tensor] = None,
conv_motion: Optional[th.Tensor] = None,View on GitHub (pinned to e8cd657656)
Solutions
- Use a supported merge_strategy: 'fixed', 'learned', or 'fixed_with_images' (whichever set this class documents).
- Check that the strategy string matches exactly (case and underscores) the values in the constructor.
- Validate config with a schema or assert against the supported list before model construction.
Example fix
// before block = VideoResBlock(..., merge_strategy="learned_with_images") // after block = VideoResBlock(..., merge_strategy="fixed_with_images")
Defensive patterns
Strategy: validation
Validate before calling
VALID = {"fixed", "learned", "fixed_with_images"}
if merge_strategy not in VALID:
raise ValueError(f"merge_strategy must be one of {VALID}, got {merge_strategy!r}") Type guard
def is_valid_video_merge_strategy(s) -> bool:
return isinstance(s, str) and s in {"fixed", "learned", "fixed_with_images"} Try / catch
try:
block = VideoResBlock(..., merge_strategy=strategy)
except ValueError as e:
logger.warning("%s; defaulting to 'fixed'", e)
block = VideoResBlock(..., merge_strategy="fixed") Prevention
- Keep a single constants module listing valid strategies per class.
- Do not reuse AlphaBlender strategy strings for video blocks without checking support.
- Add config schema validation with an enum before model build.
When it happens
Trigger: Creating a VideoResBlock (or similar) with merge_strategy not matching any known string — e.g. 'learned_with_images' when only 'fixed_with_images' plus the fixed/learned variants are supported at this site, or a typo like 'fixd'.
Common situations: Config values copied between AlphaBlender and VideoResBlock (their supported strategy sets differ), YAML typos, or overriding merge_strategy from the CLI with an invalid value.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- unsupported dimensions: {dims}
- unknown merge strategy {self.merge_strategy}
- input has {x.ndim} dims but target_dims is {target_dims}, wh
- Model {model_id} not supported
- unknown discretization {params.discretization}
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/5c3f9b84a9951d89.
Report an issue: GitHub.