Stability-AI/generative-models · error · NotImplementedError
NotImplementedError
Error message
NotImplementedError
What it means
FrozenOpenCLIPVisualStyleEmbedder (around modules.py:439) accepts layer='last' or layer='penultimate' to select which CLIP transformer output to use; any other string raises NotImplementedError in __init__. Unlike some OpenCLIP wrappers there is no support for indexed/hidden-layer names here.
Source
Thrown at sgm/modules/encoders/modules.py:439
arch,
device=torch.device("cpu"),
pretrained=version,
)
del model.visual
self.model = model
self.device = device
self.max_length = max_length
self.return_pooled = always_return_pooled
if freeze:
self.freeze()
self.layer = layer
if self.layer == "last":
self.layer_idx = 0
elif self.layer == "penultimate":
self.layer_idx = 1
else:
raise NotImplementedError()
self.legacy = legacy
def freeze(self):
self.model = self.model.eval()
for param in self.parameters():
param.requires_grad = False
@autocast
def forward(self, text):
tokens = open_clip.tokenize(text)
z = self.encode_with_transformer(tokens.to(self.device))
if not self.return_pooled and self.legacy:
return z
if self.return_pooled:
assert not self.legacy
return z[self.layer], z["pooled"]
return z[self.layer]
View on GitHub (pinned to e8cd657656)
Solutions
- Set layer='last' (layer_idx 0) or layer='penultimate' (layer_idx 1) in the embedder config
- Check the exact string in the config YAML for case/whitespace/typos
- If you need another layer, patch the class to map your layer string to the right layer_idx
Example fix
// before params: layer: hidden // after params: layer: penultimate
Defensive patterns
Strategy: validation
Validate before calling
ALLOWED_LAYERS = {'last', 'penultimate'}
layer = cfg.model.params.embedder.get('params', {}).get('layer', 'last')
if layer not in ALLOWED_LAYERS:
raise ValueError(f"layer must be one of {ALLOWED_LAYERS}, got {layer!r}") Try / catch
try:
embedder = instantiate_from_config(emb_config)
except NotImplementedError:
emb_config['params']['layer'] = 'last'
embedder = instantiate_from_config(emb_config) Prevention
- Never copy layer='hidden' from LDM FrozenCLIP configs into SGM OpenCLIP embedders
- Validate layer strings against the whitelist at config-load time
- Note the two supported values map to layer_idx 0 and 1 only
When it happens
Trigger: Constructing the embedder with layer set to something other than 'last' or 'penultimate', e.g. layer='hidden', layer=7, or a config omitting/misspelling the layer param.
Common situations: Copying config snippets from the Stable Diffusion (LDM-style) CLIP embedder which used layer='hidden'; typos like 'penultimate ' with whitespace; passing None when the config lacks params.
Related errors
- Unknown loss type {self.loss_type}
- rearranging not available for {len(in_shape)}-dimensional in
- unknown merge strategy {self.merge_strategy}
- provide num_res_blocks either as an int (globally constant)
- NotImplementedError
AI-assisted analysis of Stability-AI/generative-models@e8cd657656 (2026-08-29).
Data as JSON: /api/errors/a6561ac993a31838.
Report an issue: GitHub.