invoke-ai/InvokeAI · error · ValueError
per_layer_weights must be comma-separated numbers: {e}
Error message
per_layer_weights must be comma-separated numbers: {e} What it means
Krea2ConditioningRebalanceInvocation._parse_weights splits the per_layer_weights string on commas and converts each token with float(); if any token is not a valid decimal number (e.g. '1.2.3' or 'abc'), float() raises ValueError, which is re-raised with this message. The field is expected to be comma-separated numeric gains for the 12 tapped Krea2 text-encoder layers.
Source
Thrown at invokeai/app/invocations/krea2_conditioning_rebalance.py:53
conditioning: Krea2ConditioningField = InputField(
description=FieldDescriptions.cond, input=Input.Connection, title="Conditioning"
)
per_layer_weights: str = InputField(
default="1.0,1.0,1.0,1.0,1.0,1.0,1.0,2.5,5.0,1.1,4.0,1.0",
description=f"Comma-separated gains for the {_NUM_TEXT_LAYERS} tapped encoder layers (exactly "
f"{_NUM_TEXT_LAYERS} values).",
)
multiplier: float = InputField(
default=4.0,
allow_inf_nan=False,
description="Overall multiplier applied to the conditioning after per-layer weighting.",
)
def _parse_weights(self) -> list[float]:
try:
weights = [float(x.strip()) for x in self.per_layer_weights.split(",") if x.strip() != ""]
except ValueError as e:
raise ValueError(f"per_layer_weights must be comma-separated numbers: {e}") from e
if len(weights) != _NUM_TEXT_LAYERS:
raise ValueError(f"per_layer_weights must have exactly {_NUM_TEXT_LAYERS} values, got {len(weights)}.")
if not all(math.isfinite(weight) for weight in weights):
raise ValueError("per_layer_weights must contain only finite values.")
return weights
@torch.no_grad()
def invoke(self, context: InvocationContext) -> Krea2ConditioningOutput:
weights = self._parse_weights()
cond_data = context.conditioning.load(self.conditioning.conditioning_name)
assert len(cond_data.conditionings) == 1
conditioning = cond_data.conditionings[0]
assert isinstance(conditioning, Krea2ConditioningInfo)
embeds = conditioning.prompt_embeds # (B, seq, 12, hidden)
gains = torch.tensor(weights, dtype=embeds.dtype, device=embeds.device).view(1, 1, _NUM_TEXT_LAYERS, 1)
embeds = embeds * gains * self.multiplierView on GitHub (pinned to 0b6a024f2f)
Solutions
- Fix the string so every comma-separated token parses with Python float(), e.g. '1.0,0.8,...' (12 values).
- Use dots, not commas, as decimal separators (the comma is the list separator).
- Validate the string programmatically before building the graph: try [float(x) for x in s.split(',') if x.strip()].
Example fix
// before per_layer_weights="1.0, 0,8, 1.2, ..." // '0,8' -> float() ValueError // after per_layer_weights="1.0, 0.8, 1.2, ..."
Defensive patterns
Strategy: validation
Validate before calling
def valid_weights(s: str, n: int = 12) -> bool:
try:
vals = [float(x) for x in s.split(",") if x.strip() != ""]
except ValueError:
return False
return len(vals) == n Try / catch
try:
out = invoke(node)
except ValueError as e:
if "comma-separated numbers" in str(e):
node.per_layer_weights = ",".join(["1.0"] * 12) # neutral default
out = invoke(node) Prevention
- Use dots as decimal separators; the comma is reserved as the list separator.
- Build the string programmatically with ','.join(f'{w:g}' for w in weights).
- Paste from plain text, not spreadsheet cells that may insert locale formatting.
When it happens
Trigger: Invoking a krea2_conditioning_rebalance node with per_layer_weights containing a token that float() cannot parse, such as '0.5,,x' with a non-numeric entry, or with a decimal comma ('0,5') instead of a dot.
Common situations: Locale confusion (comma as decimal separator) breaking the comma-separated list; typos when hand-typing 12 values; whitespace/odd characters pasted from a spreadsheet.
Related errors
- per_layer_weights must have exactly {_NUM_TEXT_LAYERS} value
- per_layer_weights must contain only finite values.
- cfg_scale values must be finite.
- shift must be finite.
- At least one Krea-2 conditioning is required.
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/6d7f858b6aba4123.
Report an issue: GitHub.