{"record":{"id":"6d7f858b6aba4123","repo":"invoke-ai/InvokeAI","slug":"per-layer-weights-must-be-comma-separated-numbers","errorCode":null,"errorMessage":"per_layer_weights must be comma-separated numbers: {e}","messagePattern":"per_layer_weights must be comma-separated numbers: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"invokeai/app/invocations/krea2_conditioning_rebalance.py","lineNumber":53,"sourceCode":"    conditioning: Krea2ConditioningField = InputField(\n        description=FieldDescriptions.cond, input=Input.Connection, title=\"Conditioning\"\n    )\n    per_layer_weights: str = InputField(\n        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\",\n        description=f\"Comma-separated gains for the {_NUM_TEXT_LAYERS} tapped encoder layers (exactly \"\n        f\"{_NUM_TEXT_LAYERS} values).\",\n    )\n    multiplier: float = InputField(\n        default=4.0,\n        allow_inf_nan=False,\n        description=\"Overall multiplier applied to the conditioning after per-layer weighting.\",\n    )\n\n    def _parse_weights(self) -> list[float]:\n        try:\n            weights = [float(x.strip()) for x in self.per_layer_weights.split(\",\") if x.strip() != \"\"]\n        except ValueError as e:\n            raise ValueError(f\"per_layer_weights must be comma-separated numbers: {e}\") from e\n        if len(weights) != _NUM_TEXT_LAYERS:\n            raise ValueError(f\"per_layer_weights must have exactly {_NUM_TEXT_LAYERS} values, got {len(weights)}.\")\n        if not all(math.isfinite(weight) for weight in weights):\n            raise ValueError(\"per_layer_weights must contain only finite values.\")\n        return weights\n\n    @torch.no_grad()\n    def invoke(self, context: InvocationContext) -> Krea2ConditioningOutput:\n        weights = self._parse_weights()\n\n        cond_data = context.conditioning.load(self.conditioning.conditioning_name)\n        assert len(cond_data.conditionings) == 1\n        conditioning = cond_data.conditionings[0]\n        assert isinstance(conditioning, Krea2ConditioningInfo)\n\n        embeds = conditioning.prompt_embeds  # (B, seq, 12, hidden)\n        gains = torch.tensor(weights, dtype=embeds.dtype, device=embeds.device).view(1, 1, _NUM_TEXT_LAYERS, 1)\n        embeds = embeds * gains * self.multiplier","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/invocations/krea2_conditioning_rebalance.py#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"Locale confusion (comma as decimal separator) breaking the comma-separated list; typos when hand-typing 12 values; whitespace/odd characters pasted from a spreadsheet.","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()]."],"exampleFix":"// before\nper_layer_weights=\"1.0, 0,8, 1.2, ...\"  // '0,8' -> float() ValueError\n// after\nper_layer_weights=\"1.0, 0.8, 1.2, ...\"","handlingStrategy":"validation","validationCode":"def valid_weights(s: str, n: int = 12) -> bool:\n    try:\n        vals = [float(x) for x in s.split(\",\") if x.strip() != \"\"]\n    except ValueError:\n        return False\n    return len(vals) == n","typeGuard":null,"tryCatchPattern":"try:\n    out = invoke(node)\nexcept ValueError as e:\n    if \"comma-separated numbers\" in str(e):\n        node.per_layer_weights = \",\".join([\"1.0\"] * 12)  # neutral default\n        out = invoke(node)","preventionTips":["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."],"tags":["validation","parsing","invokeai","krea2"],"backgroundTag":"numeric-parse-failed","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}