Stability-AI/generative-models · error · ValueError
unknown merge strategy {self.merge_strategy}
Error message
unknown merge strategy {self.merge_strategy} What it means
VideoTransformerBlock validates merge_strategy in __init__ and only 'fixed' (buffer) and 'learned' (parameter) are accepted; any other string raises ValueError at construction time.
Source
Thrown at sgm/modules/autoencoding/temporal_ae.py:52
dims=3,
use_scale_shift_norm=False,
use_conv=False,
up=False,
down=False,
kernel_size=video_kernel_size,
use_checkpoint=False,
skip_t_emb=True,
)
self.merge_strategy = merge_strategy
if self.merge_strategy == "fixed":
self.register_buffer("mix_factor", torch.Tensor([alpha]))
elif self.merge_strategy == "learned":
self.register_parameter(
"mix_factor", torch.nn.Parameter(torch.Tensor([alpha]))
)
else:
raise ValueError(f"unknown merge strategy {self.merge_strategy}")
def get_alpha(self, bs):
if self.merge_strategy == "fixed":
return self.mix_factor
elif self.merge_strategy == "learned":
return torch.sigmoid(self.mix_factor)
else:
raise NotImplementedError()
def forward(self, x, temb, skip_video=False, timesteps=None):
if timesteps is None:
timesteps = self.timesteps
b, c, h, w = x.shape
x = super().forward(x, temb)
if not skip_video:View on GitHub (pinned to e8cd657656)
Solutions
- Set merge_strategy to 'fixed' or 'learned' in the block config
- Fix the typo in the config key value
- Check the class __init__ signature for the default ('learned') and rely on it
Example fix
// before VideoTransformerBlock(in_channels=320, merge_strategy="average") // after VideoTransformerBlock(in_channels=320, merge_strategy="learned")
Defensive patterns
Strategy: validation
Validate before calling
VALID = {"fixed", "learned"}
assert merge_strategy in VALID, f"merge_strategy must be one of {VALID}, got {merge_strategy!r}" Type guard
def is_valid_merge_strategy(s) -> bool:
return s in ("fixed", "learned") Try / catch
try:
block = VideoTransformerBlock(in_channels=320, merge_strategy=cfg.strategy)
except ValueError as e:
logger.error("bad merge_strategy in config, falling back to 'learned'")
block = VideoTransformerBlock(in_channels=320, merge_strategy="learned") Prevention
- Keep merge_strategy values in a shared constants module
- Validate model configs against a JSON/YAML schema before construction
- Use the default value instead of hand-typing strategy strings
When it happens
Trigger: Instantiating VideoTransformerBlock with merge_strategy set to anything other than 'fixed' or 'learned', e.g. a config typo like 'fixed_with_decay' or 'average'.
Common situations: YAML/JSON config typos for temporal autoencoder attention blocks; copying older config keys into a newer code version that renamed allowed values.
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
- unknown merge strategy {merge_strategy}
- Unknown loss type {self.loss_type}
- provide num_res_blocks either as an int (globally constant)
- Order {order} too high for step {i}
- Decay must be between 0 and 1
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/0dd0f73eb0a9c46d.
Report an issue: GitHub.