Add LoRA trainer nodes and image-set loaders
Tier 2 medium python · local · real merged PR from comfyanonymous/ComfyUI #8446
Ground-truth defects
The new image-set loader offers a "Pad" resize option whose branch is identical to "Stretch": it calls the same full resize to the target width and height, with no aspect-preserving thumbnail and no border fill. A user who loads a folder of differently sized images and picks "Pad" to keep aspect ratio gets every image whose size differs from the first one non-uniformly squashed, silently corrupting the training data, with nothing reporting that the chosen option behaved the same as "Stretch".
The change under review
diff (truncated — full diff)
@@ -37,6 +37,8 @@ class IO(StrEnum): CONTROL_NET = "CONTROL_NET" VAE = "VAE" MODEL = "MODEL" + LORA_MODEL = "LORA_MODEL" + LOSS_MAP = "LOSS_MAP" CLIP_VISION = "CLIP_VISION" CLIP_VISION_OUTPUT = "CLIP_VISION_OUTPUT" STYLE_MODEL = "STYLE_MODEL" @@ -796,12 +796,15 @@ class GeneralDITTransformerBlock(nn.Module): adaln_lora_B_3D: Optional[torch.Tensor] = None, ) -> torch.Tensor: for block in self.blocks: - x = block( - x, - emb_B_D, - crossattn_emb, - crossattn_mask, - rope_emb_L_1_1_D=rope_emb_L_1_1_D, - adaln_lora_B_3D=adaln_lora_B_3D, - ) + if self.training: + x = torch.utils.checkpoint.checkpoint(block, x, emb_B_D, crossattn_emb, crossattn_mask, rope_emb_L_1_1_D, adaln_lora_B_3D, use_reentrant=False) + else: + x = block( + x, + emb_B_D, + crossattn_emb, + crossattn_mask, + rope_emb_L_1_1_D=rope_emb_L_1_1_D, + adaln_lora_B_3D=adaln_lora_B_3D, + ) return x @@ -753,7 +753,7 @@ class BasicTransformerBlock(nn.Module): for p in patch: n = p(n, extra_options) - x += n + x = n + x if "middle_patch" in transformer_patches: patch = transformer_patches["middle_patch"] for p in patch: @@ -793,12 +793,12 @@ class BasicTransformerBlock(nn.Module): for p in patch: n = p(n, extra_options) - x += n + x = n + x if self.is_res: x_skip = x x = self.ff(self.norm3(x)) if self.is_res: - x += x_skip + x = x_skip + x return x @@ -17,23 +17,26 @@ """ from __future__ import annotations -from typing import Optional, Callable -import torch + +import collections import copy import inspect import logging -import uuid -import collections import math +import uuid +from typing import Callable, Optional + +import torch -import comfy.utils import comfy.float -import comfy.model_management -import comfy.lora import comfy.hooks +import comfy.lora +import comfy.model_management import comfy.patcher_extension -from comfy.patcher_extension import CallbacksMP, WrappersMP, PatcherInjection +import comfy.utils from comfy.comfy_types import UnetWrapperFunction +from comfy.patcher_extension import CallbacksMP, PatcherInjection, WrappersMP + def string_to_seed(data): crc = 0xFFFFFFFF @@ -1081,7 +1081,28 @@ def load_state_dict_guess_config(sd, output_vae=True, output_clip=True, output_c return (model_patcher, clip, vae, clipvision) -def load_diffusion_model_state_dict(sd, model_options={}): #load unet in diffusers or regular format +def load_diffusion_model_state_dict(sd, model_options={}): + """ + Loads a UNet diffusion model from a state dictionary, supporting both diffusers and regular formats. + + Args: + sd (dict): State dictionary containing model weights and configuration + model_options (dict, optional): Additional options for model loading. Supports: + - dtype: Override model data type + - custom_operations: Custom model operations + - fp8_optimizations: Enable FP8 optimizations + + Returns: + ModelPatcher: A wrapped model instance that handles device management and weight loading. + Returns None if the model configuration cannot be detected. + + The function: + 1. Detects and handles different model formats (regular, diffusers, mmdit) + 2. Configures model dtype based on parameters and device capabilities + 3. Handles weight conversion and device placement + 4. Manages model optimization settings + 5. Loads weights and returns a device-managed model instance + """ dtype = model_options.get("dtype", None) #Allow loading unets from checkpoint files @@ -1,4 +1,4 @@ -from .base import WeightAdapterBase +from .base import WeightAdapterBase, WeightAdapterTrainBase from .lora import LoRAAdapter from .loha import LoHaAdapter from .lokr import LoKrAdapter @@ -15,3 +15,9 @@ adapters: list[type[WeightAdapterBase]] = [ OFTAdapter, BOFTAdapter, ] + +__all__ = [ + "WeightAdapterBase", + "WeightAdapterTrainBase", + "adapters" +] + [a.__name__ for a in adapters] @@ -12,12 +12,20 @@ class WeightAdapterBase: weights: list[torch.Tensor] @classmethod - def load(cls, x: str, lora: dict[str, torch.Tensor]) -> Optional["WeightAdapterBase"]: + def load(cls, x: str, lora: dict[str, torch.Tensor], alpha: float, dora_scale: torch.Tensor) -> Optional["WeightAdapterBase"]: raise NotImplementedError def to_train(self) -> "WeightAdapterTrainBase": raise NotImplementedError + @classmethod + def create_train(cls, weight, *args) -> "WeightAdapterTrainBase": + """ + weight: The original weight tensor to be modified. + *args: Additional arguments for configuration, such as rank, alpha etc. + """ + raise NotImplementedError + def calculate_weight( self, weight, @@ -33,10 +41,22 @@ class WeightAdapterBase: class WeightAdapterTrainBase(nn.Module): + # We follow the scheme of PR #7032 def __init__(self): super().__init__() - # [TODO] Collaborate with LoRA training PR #7032 + def __call__(self, w): + """ + w: The original weight tensor to be modified. + """ + raise NotImplementedError + + def passive_memory_usage(self): + raise NotImplementedError("passive_memory_usage is not implemented") + + def move_to(self, device): + self.to(device) + return self.passive_memory_usage() def weight_decompose(dora_scale, weight, lora_diff, alpha, strength, intermediate_dtype, function): @@ -102,3 +122,14 @@ def pad_tensor_to_shape(tensor: torch.Tensor, new_shape: list[int]) -> torch.Ten padded_tensor[new_slices] = tensor[orig_slices] return padded_tensor + + +def tucker_weight_from_conv(up, down, mid): + up = up.reshape(up.size(0), up.size(1)) + down = down.reshape(down.size(0), down.size(1)) + return torch.einsum("m n ..., i m, n j -> i j ...", mid, up, down) + + +def tucker_weight(wa, wb, t): + temp = torch.einsum("i j ..., j r -> i r ...", t, wb) + return torch.einsum("i j ..., i r -> r j ...", temp, wa) @@ -3,7 +3,56 @@ from typing import Optional import torch import comfy.model_management -from .base import WeightAdapterBase, weight_decompose, pad_tensor_to_shape +from .base import ( + WeightAdapterBase, + WeightAdapterTrainBase, + weight_decompose, + pad_tensor_to_shape, + tucker_weight_from_conv, +) + + +class LoraDiff(WeightAdapterTrainBase): + def __init__(self, weights): + super().__init__() + mat1, mat2, alpha, mid, dora_scale, reshape = weights + out_dim, rank = mat1.shape[0], mat1.shape[1] + rank, in_dim = mat2.shape[0], mat2.shape[1] + if mid is not None: + convdim = mid.ndim - 2 + layer = ( + torch.nn.Conv1d, + torch.nn.Conv2d, + torch.nn.Conv3d + )[convdim] + else: + layer = torch.nn.Linear + self.lora_up = layer(rank, out_dim, bias=False) + self.lora_down = layer(in_dim, rank, bias=False) + self.lora_up.weight.data.copy_(mat1) + self.lora_down.weight.data.copy_(mat2) + if mid is not None: + self.lora_mid = layer(mid, rank, bias=False) + self.lora_mid.weight.data.copy_(mid) + else: + self.lora_mid = None + self.rank = rank + self.alpha = torch.nn.Parameter(torch.tensor(alpha), requires_grad=False) + + def __call__(self, w): + org_dtype = w.dtype + if self.lora_mid is None: + diff = self.lora_up.weight @ self.lora_down.weight + else: + diff = tucker_weight_from_conv( + self.lora_up.weight, self.lora_down.weight, self.lora_mid.weight + ) + scale = self.alpha / self.rank + weight = w + scale * diff.reshape(w.shape) + return weight.to(org_dtype) + + def passive_memory_usage(self): + return sum(param.numel() * param.element_size() for param in self.parameters()) class LoRAAdapter(WeightAdapterBase): @@ -13,6 +62,21 @@ class LoRAAdapter(WeightAdapterBase): self.loaded_keys = loaded_keys self.weights = weights + @classmethod + def create_train(cls, weight, rank=1, alpha=1.0): + out_dim = weight.shape[0] + in_dim = weight.shape[1:].numel() + mat1 = torch.empty(out_dim, rank, device=weight.device, dtype=weight.dtype) + mat2 = torch.empty(rank, in_dim, device=weight.device, dtype=weight.dtype) + torch.nn.init.kaiming_uniform_(mat1, a=5**0.5) + torch.nn.init.constant_(mat2, 0.0) + return LoraDiff( + (mat1, mat2, alpha, None, None, None) + ) + + def to_train(self): + return LoraDiff(self.weights) + @classmethod def load( cls, new file mode 100644 @@ -0,0 +1,711 @@ +import datetime +import json +import logging +import os + +import numpy as np +import safetensors +import torch +from PIL import Image, ImageDraw, ImageFont +from PIL.PngImagePlugin import PngInfo +import torch.utils.checkpoint +import tqdm + +import comfy.samplers +import comfy.sd +import comfy.utils +import comfy.model_management +import comfy_extras.nodes_custom_sampler +import folder_paths +import node_helpers +from comfy.cli_args import args +from comfy.comfy_types.node_typing import IO +from comfy.weight_adapter import adapters + + +class TrainSampler(comfy.samplers.Sampler): + + def __init__(self, loss_fn, optimizer, loss_callback=None): + self.loss_fn = loss_fn + self.optimizer = optimizer + self.loss_callback = loss_callback + + def sample(self, model_wrap, sigmas, extra_args, callback, noise, latent_image=None, denoise_mask=None, disable_pbar=False): + self.optimizer.zero_grad() + noise = model_wrap.inner_model.model_sampling.noise_scaling(sigmas, noise, latent_image, False) + latent = model_wrap.inner_model.model_sampling.noise_scaling( + torch.zeros_like(sigmas), + torch.zeros_like(noise, requires_grad=True), + latent_image, + False + ) + + # Ensure model is in training mode and computing gradients + # x0 pred + denoised = model_wrap(noise, sigmas, **extra_args) + try: + loss = self.loss_fn(denoised, latent.clone()) + except RuntimeError as e: + if "does not require grad and does not have a grad_fn" in str(e): + logging.info("WARNING: This is likely due to the model is loaded in inference mode.") + loss.backward() + if self.loss_callback: + self.loss_callback(loss.item()) + + self.optimizer.step() + # torch.cuda.memory._dump_snapshot("trainn.pickle") + # torch.cuda.memory._record_memory_history(enabled=None) + return torch.zeros_like(latent_image) + + +class BiasDiff(torch.nn.Module): + def __init__(self, bias): + super().__init__() + self.bias = bias + + def __call__(self, b): + return b + self.bias + + def passive_memory_usage(self): + return self.bias.nelement() * self.bias.element_size() + + def move_to(self, device): + self.to(device=device) + return self.passive_memory_usage() + + +def load_and_process_images(image_files, input_dir, resize_method="None"): + """Utility function to load and process a list of images. + + Args: + image_files: List of image filenames + input_dir: Base directory containing the images + resize_method: How to handle images of different sizes ("None", "Stretch", "Crop", "Pad") + + Returns: + torch.Tensor: Batch of processed images + """ + if not image_files: + raise ValueError("No valid images found in input") + + output_images = [] + w, h = None, None + + for file in image_files: + image_path = os.path.join(input_dir, file) + img = node_helpers.pillow(Image.open, image_path) + + if img.mode == "I": + img = img.point(lambda i: i * (1 / 255)) + img = img.convert("RGB") + + if w is None and h is None: + w, h = img.size[0], img.size[1] + + # Resize image to first image + if img.size[0] != w or img.size[1] != h: + if resize_method == "Stretch": + img = img.resize((w, h), Image.Resampling.LANCZOS) + elif resize_method == "Crop": + img = img.crop((0, 0, w, h)) + elif resize_method == "Pad": + img = img.resize((w, h), Image.Resampling.LANCZOS) + elif resize_method == "None": + raise ValueError( + "Your input image size does not match the first image in the dataset. Either select a valid resize method or use the same size for all images." + ) + + img_array = np.array(img).astype(np.float32) / 255.0 + img_tensor = torch.from_numpy(img_array)[None,] + output_images.append(img_tensor) + + return torch.cat(output_images, dim=0) + + +class LoadImageSetNode: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "images": ( + [ + f + for f in os.listdir(folder_paths.get_input_directory()) + if f.endswith((".png", ".jpg", ".jpeg", ".webp", ".bmp", ".gif", ".jpe", ".apng", ".tif", ".tiff")) + ], + {"image_upload": True, "allow_batch": True}, + ) + }, + "optional": { + "resize_method": ( + ["None", "Stretch", "Crop", "Pad"], + {"default": "None"}, + ), + }, + } + + INPUT_IS_LIST = True + RETURN_TYPES = ("IMAGE",) + FUNCTION = "load_images" + CATEGORY = "loaders" + EXPERIMENTAL = True + DESCRIPTION = "Loads a batch of images from a directory for training." + + @classmethod + def VALIDATE_INPUTS(s, images, resize_method): + filenames = images[0] if isinstance(images[0], list) else images + + for image in filenames: + if not folder_paths.exists_annotated_filepath(image): + return "Invalid image file: {}".format(image) + return True + + def load_images(self, input_files, resize_method): + input_dir = folder_paths.get_input_directory() + valid_extensions = [".png", ".jpg", ".jpeg", ".webp", ".bmp", ".gif", ".jpe", ".apng", ".tif", ".tiff"] + image_files = [ + f + for f in input_files + if any(f.lower().endswith(ext) for ext in valid_extensions) + ] + output_tensor = load_and_process_images(image_files, input_dir, resize_method) + return (output_tensor,) + + +class LoadImageSetFromFolderNode: + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "folder": (folder_paths.get_input_subfolders(), {"tooltip": "The folder to load images from."}) + }, + "optional": { + "resize_method": (
Leaderboard for this case
medium · 3 of 9 bots fully caught it (33% solve rate) · 33% avg coverage.
| # | Bot | Result | Caught | Coverage | Findings | False alarms |
|---|---|---|---|---|---|---|
| 1 | cursor | solved | 1/1 | 100.0% | 11 | 0 |
| 2 | Drape (Deep Review) | solved | 1/1 | 100.0% | 17 | 0 |
| 3 | Claude Code (Opus 5.5) | solved | 1/1 | 100.0% | 13 | 1 |
| 4 | Cubic | miss | 0/1 | 0.0% | 10 | 0 |
| 5 | Drape (Review) | miss | 0/1 | 0.0% | 11 | 0 |
| 6 | Mjolnir (Opus 5.5) | miss | 0/1 | 0.0% | 19 | 0 |
| 7 | Mjolnir (Sonnet 5.5) | miss | 0/1 | 0.0% | 13 | 0 |
| 8 | qodo | miss | 0/1 | 0.0% | 10 | 0 |
| 9 | greptile | miss | 0/1 | 0.0% | 8 | 1 |
Bot results
Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | off by one |
The user-controlled prefix goes straight into a path relative to the CWD, with no normalization and no use of folder_paths. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
For 'my_lora.safetensors' the last token is 'lora.safetensors', so int() raises ValueError. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
LoHa, LoKr, GLoRA, OFT and BOFT inherit the base to_train, which raises NotImplementedError, and the loop can select any of them. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Conv layers need kernel_size and here get a tensor as in_channels. 4-D conv weights can't be copied into Linear weights. Conv LoRAs crash. [grounded: diff-section comfy/weight_adapter/lora.py] [consensus 3/3: valid=3]
key is '<n>.weight', so the lookup uses '<n>.weight.alpha'. LoRA files, including this node's own saves, store '<n>.alpha', so alpha always falls back to 1.0. The None part is not reachable from the node. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The except block does not re-raise, so loss.backward() hits an unbound loss and raises UnboundLocalError instead of the original error. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The subset is chosen once and encoded once, and every step reuses encoded.clone(), so images outside the batch are never trained on. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
steps=1 is allowed and gives one loss value, so max-min is 0 and the division raises ZeroDivisionError. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The diff and diff_b parameters are always created as zeros and never loaded from existing_weights, so resuming discards them. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The default 'bf32' is not in ['bf16', 'fp32'], so a default value submitted via the API fails the value_not_in_list validation. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The generator is never passed to init, randperm or rand, so the seed has no effect on reproducibility despite the tooltip. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
LoadImageSetNode is not in NODE_CLASS_MAPPINGS, so nothing triggers the mismatch today. The finding admits this itself. [invalid: contradiction] [consensus 3/4: invalid=3, valid=1]
raw comments (13)
SaveLoRA puts the user-controlled `prefix` directly into the relative path `models/loras/{prefix}_...safetensors`. A prefix containing `../` or an absolute-path component can write a file outside the loras directory (arbitrary file write through the API). The path also resolves against the process CWD rather than `folder_paths`, so `--base-directory` and extra model paths are ignored. If `models/loras` does not exist relative to CWD, the save fails. Use `folder_paths.get_folder_paths('loras')` / `get_save_image_path` and reject or normalize traversal.
When an existing LoRA is selected, `existing_steps = int(existing_lora.split("_steps_")[0].split("_")[-1])` raises ValueError for any filename that doesn't follow the `<prefix>_<N>_steps_...` pattern. Examples are `my_lora.safetensors` or files saved by SaveLoRA without `steps` (`{prefix}_{date}_lora`). So continuing training from almost any normal LoRA crashes the node.
The loader loops over every adapter class (LoHa, LoKr, GLoRA, OFT, BOFT), but only LoRAAdapter implements `to_train()`. If `existing_lora` is any non-LoRA format, `existing_adapter.to_train()` raises NotImplementedError from the base class.
LoraDiff fails on any LoRA with a `lora_mid` (Tucker/conv) or with conv-shaped up/down weights. `layer(mid, rank, bias=False)` passes a tensor as `in_channels` and leaves out `kernel_size`, which Conv layers require. The up/down Conv layers are also built without `kernel_size`. For conv LoRAs without mid, `mat1`/`mat2` are 4-D but go into `nn.Linear` weights, so `copy_` fails on shape. Loading such a LoRA via `existing_lora` crashes training.
`torch.tensor(alpha)` raises when `alpha` is None, which LoRA weights tuples allow (`calculate_weight` checks `v[2] is not None`). On top of that, TrainLoraNode looks up alpha as `f"{key}.alpha"`, i.e. `<module>.weight.alpha`. LoRA files, including the ones this node saves (`<module>.alpha`), store it under `<module>.alpha`. The real alpha is never found and always defaults to 1.0, so third-party LoRAs resume with the wrong scale (alpha/rank).
In TrainSampler.sample the `except RuntimeError` block only logs and does not re-raise. `loss` is then unbound at `loss.backward()`, so the real error is replaced by a confusing UnboundLocalError. Any other RuntimeError is silently swallowed the same way.
`indices = torch.randperm(num_images)[:batch_size]` picks one fixed subset once, before the training loop. Every step trains on the same latents, and with `num_images > batch_size` the remaining images are never used. Batches should be resampled each step.
LossGraphNode divides by `(max_loss - min_loss)`. This raises ZeroDivisionError when all losses are equal, e.g. `steps=1`, which the node allows. An empty loss list fails on `min()`. `draw_loss_graph` has the same divide-by-zero and also divides by `steps - 1`.
When resuming from an existing LoRA, the 1-D weight diffs (`.diff`) and bias diffs (`.diff_b`) are always recreated as zeros and never loaded from `existing_weights`. Those trained parameters are lost and the saved LoRA overwrites them.
The `lora_dtype` default is "bf32", which is not one of the options ["bf16", "fp32"]. Workflows using the default can fail combo validation. If the value ever reaches `string_to_torch_dtype`, it returns None and `.to(None)` behaves unexpectedly.
The seeded `generator` is never used. LoRA init (`kaiming_uniform_`), batch selection (`randperm`) and sigma sampling (`torch.rand`) all use the global RNG, so the `seed` input does not make training reproducible as its tooltip claims. `step * 1000 + seed` can also exceed the 64-bit seed range when seed is near its 0xFFFFFFFFFFFFFFFF max.
LoadImageSetNode.load_images takes `input_files`, but the input is named `images`, so calling it would raise TypeError. With INPUT_IS_LIST, `resize_method` would also arrive as a list. The node isn't in NODE_CLASS_MAPPINGS, so it is currently dead code.
The "Pad" resize method just stretches with LANCZOS, the same as "Stretch". "Crop" on a smaller image extends it with black fill rather than cropping. Neither matches its label.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✗ | — |
Conv LoRA factors are 4-D (e.g. out,rank,1,1); with mid None a Linear with 2-D weight is created and copy_ of a 4-D tensor into 2-D fails. [grounded: tree comfy/weight_adapter/lora.py] [consensus 5/5: valid=5]
For a 4-D mid, convdim=2 picks Conv3d, and Conv layers are constructed without kernel_size (and lora_mid gets a tensor as in_channels), raising TypeError. [grounded: tree comfy/weight_adapter/lora.py] [consensus 5/5: valid=5]
The prefix string from the workflow is interpolated into the path with no traversal validation, unlike get_save_image_path used by other save nodes. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
This is only a type-annotation alignment. At runtime every subclass overrides load and accepts these arguments. [grounded: tree comfy/weight_adapter/base.py] [consensus 5/5: minor=5]
LoraDiff unpacks dora_scale but never uses it, so an existing DoRA adapter becomes plain additive LoRA during training. [grounded: tree comfy/weight_adapter/lora.py] [consensus 5/5: valid=5]
The generator is never passed to randperm, torch.rand (sigma) or the kaiming init, so these use the global RNG and the seed tooltip's promise doesn't hold. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
The default 'bf32' is not in the options ['bf16','fp32']. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
LoadImageSetNode is defined but missing from NODE_CLASS_MAPPINGS, so it is unusable. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
The relative hardcoded path depends on the CWD and ignores the folder_paths loras configuration and base_directory. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
For names without '_steps_' (including SaveLoRA output with no steps), the last token is something like 'lora.safetensors', so int() raises ValueError. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
raw comments (11)
<!-- cubic:v=8784d38f-6cf2-41ad-accd-40fcd6727da0 -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P1: When an existing Conv2d LoRA is continued, `to_train()` passes 4-D factors into `Linear` parameters and construction fails on `copy_`. Flatten the factors before creating the linear training adapter, or preserve compatible convolutional parameter shapes.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy/weight_adapter/lora.py, line 78:
<comment>When an existing Conv2d LoRA is continued, `to_train()` passes 4-D factors into `Linear` parameters and construction fails on `copy_`. Flatten the factors before creating the linear training adapter, or preserve compatible convolutional parameter shapes.</comment>
<file context>
@@ -13,6 +62,21 @@ def __init__(self, loaded_keys, weights):
+ )
+
+ def to_train(self):
+ return LoraDiff(self.weights)
+
@classmethod
</file context>
```
</details>
<!-- cubic:v=8332e798-bd8f-424d-b385-54195152bfee -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P1: When an existing LoCon adapter is converted for training, this branch selects the wrong convolution class and calls it without a kernel size, so `LoraDiff` raises during construction. Select the spatial rank correctly and pass kernel shapes plus integer channel counts for each convolution.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy/weight_adapter/lora.py, line 22:
<comment>When an existing LoCon adapter is converted for training, this branch selects the wrong convolution class and calls it without a kernel size, so `LoraDiff` raises during construction. Select the spatial rank correctly and pass kernel shapes plus integer channel counts for each convolution.</comment>
<file context>
@@ -3,7 +3,56 @@
+ out_dim, rank = mat1.shape[0], mat1.shape[1]
+ rank, in_dim = mat2.shape[0], mat2.shape[1]
+ if mid is not None:
+ convdim = mid.ndim - 2
+ layer = (
+ torch.nn.Conv1d,
</file context>
```
</details>
<!-- cubic:v=fa05278a-ee54-4d6c-8b96-65fe167278ea -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P1: A workflow-controlled `prefix` can contain `../`, allowing this node to escape `models/loras` and overwrite arbitrary writable files. Reject traversal and constrain the resolved path to the configured LoRA directory.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy_extras/nodes_train.py, line 599:
<comment>A workflow-controlled `prefix` can contain `../`, allowing this node to escape `models/loras` and overwrite arbitrary writable files. Reject traversal and constrain the resolved path to the configured LoRA directory.</comment>
<file context>
@@ -0,0 +1,711 @@
+ def save(self, lora, prefix, steps=None):
+ date = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
+ if steps is None:
+ output_file = f"models/loras/{prefix}_{date}_lora.safetensors"
+ else:
+ output_file = f"models/loras/{prefix}_{steps}_steps_{date}_lora.safetensors"
</file context>
```
</details>
<!-- cubic:v=cabe957d-779d-4833-8d1d-68706f7bf552 -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":8} -->
P2: Keep the base `load` contract aligned with the loader: accept an optional `loaded_keys` argument and mark `alpha` and `dora_scale` nullable. Otherwise code using `adapters` through its declared `WeightAdapterBase` type cannot call the common loader signature safely.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy/weight_adapter/base.py, line 15:
<comment>Keep the base `load` contract aligned with the loader: accept an optional `loaded_keys` argument and mark `alpha` and `dora_scale` nullable. Otherwise code using `adapters` through its declared `WeightAdapterBase` type cannot call the common loader signature safely.</comment>
<file context>
@@ -12,12 +12,20 @@ class WeightAdapterBase:
@classmethod
- def load(cls, x: str, lora: dict[str, torch.Tensor]) -> Optional["WeightAdapterBase"]:
+ def load(cls, x: str, lora: dict[str, torch.Tensor], alpha: float, dora_scale: torch.Tensor) -> Optional["WeightAdapterBase"]:
raise NotImplementedError
</file context>
```
</details>
```suggestion
def load(cls, x: str, lora: dict[str, torch.Tensor], alpha: Optional[float], dora_scale: Optional[torch.Tensor], loaded_keys: Optional[set[str]] = None) -> Optional["WeightAdapterBase"]:
```
<!-- cubic:v=3ecb149c-370b-428d-bd6a-e8482f8e6444 -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":9} -->
P2: When an existing DoRA LoRA is continued, `LoraDiff` silently changes it into an ordinary additive LoRA, so the training model no longer matches the loaded adapter. Preserve the `weight_decompose` path or reject DoRA files before `to_train()`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy/weight_adapter/lora.py, line 50:
<comment>When an existing DoRA LoRA is continued, `LoraDiff` silently changes it into an ordinary additive LoRA, so the training model no longer matches the loaded adapter. Preserve the `weight_decompose` path or reject DoRA files before `to_train()`.</comment>
<file context>
@@ -3,7 +3,56 @@
+ diff = tucker_weight_from_conv(
+ self.lora_up.weight, self.lora_down.weight, self.lora_mid.weight
+ )
+ scale = self.alpha / self.rank
+ weight = w + scale * diff.reshape(w.shape)
+ return weight.to(org_dtype)
</file context>
```
</details>
<!-- cubic:v=86ba1a8f-b46d-41fd-a049-25066f924f26 -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P2: The `seed` input does not make training reproducible because this generator is never used by the random operations. Pass it to each operation that supports a generator, and seed the adapter initialization explicitly.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy_extras/nodes_train.py, line 395:
<comment>The `seed` input does not make training reproducible because this generator is never used by the random operations. Pass it to each operation that supports a generator, and seed the adapter initialization explicitly.</comment>
<file context>
@@ -0,0 +1,711 @@
+ with torch.inference_mode(False):
+ lora_sd = {}
+ generator = torch.Generator()
+ generator.manual_seed(seed)
+
+ # Load existing LoRA weights if provided
</file context>
```
</details>
<!-- cubic:v=807b0ef0-f83d-4ff9-a7cb-b8593b94d866 -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P2: The LoRA dtype default is `bf32`, which is neither an available choice nor a dtype recognized by `string_to_torch_dtype`. Change the default to a declared value such as `bf16`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy_extras/nodes_train.py, line 346:
<comment>The LoRA dtype default is `bf32`, which is neither an available choice nor a dtype recognized by `string_to_torch_dtype`. Change the default to a declared value such as `bf16`.</comment>
<file context>
@@ -0,0 +1,711 @@
+ ),
+ "lora_dtype": (
+ ["bf16", "fp32"],
+ {"default": "bf32", "tooltip": "The dtype to use for lora."},
+ ),
+ "existing_lora": (
</file context>
```
</details>
```suggestion
{"default": "bf16", "tooltip": "The dtype to use for lora."},
```
<!-- cubic:v=04456eaa-0251-45b6-a877-bc5d9630a51a -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P2: The newly defined `LoadImageSetNode` is never registered, so the multi-file image loader cannot be created or used. Add it to `NODE_CLASS_MAPPINGS`.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy_extras/nodes_train.py, line 701:
<comment>The newly defined `LoadImageSetNode` is never registered, so the multi-file image loader cannot be created or used. Add it to `NODE_CLASS_MAPPINGS`.</comment>
<file context>
@@ -0,0 +1,711 @@
+ "TrainLoraNode": TrainLoraNode,
+ "SaveLoRANode": SaveLoRA,
+ "LoraModelLoader": LoraModelLoader,
+ "LoadImageSetFromFolderNode": LoadImageSetFromFolderNode,
+ "LossGraphNode": LossGraphNode,
+}
</file context>
```
</details>
```suggestion
"LoadImageSetNode": LoadImageSetNode,
"LoadImageSetFromFolderNode": LoadImageSetFromFolderNode,
```
<!-- cubic:v=22c4fcdd-27a8-4700-ac0e-d981d0cb736c -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":9} -->
P2: When ComfyUI uses a custom base directory or configured LoRA path, this node writes outside the directory the loader searches. Resolve the destination from `folder_paths` and create it before saving.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy_extras/nodes_train.py, line 599:
<comment>When ComfyUI uses a custom base directory or configured LoRA path, this node writes outside the directory the loader searches. Resolve the destination from `folder_paths` and create it before saving.</comment>
<file context>
@@ -0,0 +1,711 @@
+ def save(self, lora, prefix, steps=None):
+ date = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
+ if steps is None:
+ output_file = f"models/loras/{prefix}_{date}_lora.safetensors"
+ else:
+ output_file = f"models/loras/{prefix}_{steps}_steps_{date}_lora.safetensors"
</file context>
```
</details>
<!-- cubic:v=acea1a4c-7451-461f-a1ec-3a408a05859b -->
<!-- cubic:review-run=80974c62-4347-59c7-9b76-39940c214e97 -->
<!-- metadata:{"confidence":10} -->
P2: When an existing LoRA filename has no `_steps_` marker, including files saved without the optional step count, this conversion aborts training. Treat the step count as optional and default it to zero when the marker is absent.
<details>
<summary>Prompt for AI agents</summary>
```text
Check if this issue is valid — if so, understand the root cause and fix it. At comfy_extras/nodes_train.py, line 403:
<comment>When an existing LoRA filename has no `_steps_` marker, including files saved without the optional step count, this conversion aborts training. Treat the step count as optional and default it to zero when the marker is absent.</comment>
<file context>
@@ -0,0 +1,711 @@
+ if existing_lora != "[None]":
+ lora_path = folder_paths.get_full_path_or_raise("loras", existing_lora)
+ # Extract steps from filename like "trained_lora_10_steps_20250225_203716"
+ existing_steps = int(existing_lora.split("_steps_")[0].split("_")[-1])
+ if lora_path:
+ existing_weights = comfy.utils.load_torch_file(lora_path)
</file context>
```
</details>
```suggestion
existing_steps = int(existing_lora.split("_steps_")[0].split("_")[-1]) if "_steps_" in existing_lora else 0
```
<!-- cubic:review-summary:start -->
**10 issues found** across 12 files
<!-- cubic:review-summary:end -->
<details>
<summary>Prompt for AI agents (unresolved issues)</summary>
```text
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="comfy/weight_adapter/base.py">
<violation number="1" location="comfy/weight_adapter/base.py:15">
P2: Keep the base `load` contract aligned with the loader: accept an optional `loaded_keys` argument and mark `alpha` and `dora_scale` nullable. Otherwise code using `adapters` through its declared `WeightAdapterBase` type cannot call the common loader signature safely.</violation>
</file>
<file name="comfy/weight_adapter/lora.py">
<violation number="1" location="comfy/weight_adapter/lora.py:22">
P1: When an existing LoCon adapter is converted for training, this branch selects the wrong convolution class and calls it without a kernel size, so `LoraDiff` raises during construction. Select the spatial rank correctly and pass kernel shapes plus integer channel counts for each convolution.</violation>
<violation number="2" location="comfy/weight_adapter/lora.py:50">
P2: When an existing DoRA LoRA is continued, `LoraDiff` silently changes it into an ordinary additive LoRA, so the training model no longer matches the loaded adapter. Preserve the `weight_decompose` path or reject DoRA files before `to_train()`.</violation>
<violation number="3" location="comfy/weight_adapter/lora.py:78">
P1: When an existing Conv2d LoRA is continued, `to_train()` passes 4-D factors into `Linear` parameters and construction fails on `copy_`. Flatten the factors before creating the linear training adapter, or preserve compatible convolutional parameter shapes.</violation>
</file>
<file name="comfy_extras/nodes_train.py">
<violation number="1" location="comfy_extras/nodes_train.py:346">
P2: The LoRA dtype default is `bf32`, which is neither an available choice nor a dtype recognized by `string_to_torch_dtype`. Change the default to a declared value such as `bf16`.</violation>
<violation number="2" location="comfy_extras/nodes_train.py:395">
P2: The `seed` input does not make training reproducible because this generator is never used by the random operations. Pass it to each operation that supports a generator, and seed the adapter initialization explicitly.</violation>
<violation number="3" location="comfy_extras/nodes_train.py:403">
P2: When an existing LoRA filename has no `_steps_` marker, including files saved without the optional step count, this conversion aborts training. Treat the step count as optional and default it to zero when the marker is absent.</violation>
<violation number="4" location="comfy_extras/nodes_train.py:599">
P2: When ComfyUI uses a custom base directory or configured LoRA path, this node writes outside the directory the loader searches. Resolve the destination from `folder_paths` and create it before saving.</violation>
<violation number="5" location="comfy_extras/nodes_train.py:599">
P1: A workflow-controlled `prefix` can contain `../`, allowing this node to escape `models/loras` and overwrite arbitrary writable files. Reject traversal and constrain the resolved path to the configured LoRA directory.</violation>
<violation number="6" location="comfy_extras/nodes_train.py:701">
P2: The newly defined `LoadImageSetNode` is never registered, so the multi-file image loader cannot be created or used. Add it to `NODE_CLASS_MAPPINGS`.</violation>
</file>
```
</details>
<sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/105/ai_pr_review_github_delivery_df2256143c6969c4e3fae67255b6736e1da5ff04ce201c7a6bb1f232640a023c?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F105)</sub>
<!-- cubic:review-post:ai_pr_review_github_delivery_df2256143c6969c4e3fae67255b6736e1da5ff04ce201c7a6bb1f232640a023c:c6849ab018c29f728c8d1d1a6180f1c8a2a704ed:80974c62-4347-59c7-9b76-39940c214e97 -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | exact |
The except branch only logs and doesn't re-raise. That leaves `loss` unbound, so `loss.backward()` raises UnboundLocalError and hides the original error. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
The default 'bf32' is not one of the combo options. `string_to_torch_dtype` has no branch for it and returns None, so `.to(None)` breaks. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
For any filename without '_steps_', the last '_' segment is not an integer, so `int()` raises ValueError. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
The Conv layers are built without kernel_size, and the `mid` tensor is passed as in_channels. 4D conv LoRA weights without a mid are copied into Linear weights. So `to_train()` fails for conv/locon LoRAs. [grounded: tree comfy/weight_adapter/lora.py] [consensus 5/5: valid=5]
The path is relative to the working directory and ignores folder_paths/base_directory. Saving fails or the file lands outside the configured loras folder. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
One subset is picked and encoded once before the loop and reused every step, so the remaining images are never trained on. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
The seeded generator is never used. randperm, kaiming_uniform_ and torch.rand use the global RNG, so the seed tooltip's promise about init and sampling doesn't hold. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
`key` is '{n}.weight', so the lookup is '{n}.weight.alpha'. LoRA files store '{n}.alpha', so the lookup always misses and falls back to 1.0. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
With steps=1, which is allowed (min 1), or with identical losses, max equals min and the division raises ZeroDivisionError. [grounded: tree comfy_extras/nodes_train.py] [consensus 5/5: valid=5]
The input is named 'images' in INPUT_TYPES but 'input_files' in the function, and the class is missing from NODE_CLASS_MAPPINGS. It is dead and broken code. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/5: valid=3, invalid=2]
raw comments (12)
### Training loss used after failed compute
**High Severity**
<!-- DESCRIPTION START -->
When loss computation raises a `RuntimeError`, the handler logs a warning and then still calls `loss.backward()`. `loss` is never assigned in that path, so training crashes with `UnboundLocalError` and hides the original error, including the inference-mode case this block was meant to catch.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 737765f2-1cb7-434d-bfdb-bf7eb75d7169 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L45-L51
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmI4MjRiM2Y0LTM0ZDQtNGZiMS05MWFjLWRmZjJiOTJmOGY3YyIsImVuY3J5cHRpb25LZXkiOiJ2SmJrSE5ZRzI5TUZva1RrQkJ3NEN1eXRFRUdYaHhiTHIxcC1BSHJSM05nIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmI4MjRiM2Y0LTM0ZDQtNGZiMS05MWFjLWRmZjJiOTJmOGY3YyIsImVuY3J5cHRpb25LZXkiOiJ2SmJrSE5ZRzI5TUZva1RrQkJ3NEN1eXRFRUdYaHhiTHIxcC1BSHJSM05nIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Invalid default LoRA dtype
**High Severity**
<!-- DESCRIPTION START -->
The `lora_dtype` combo lists `bf16` and `fp32`, but its default is `bf32`, which is not a valid dtype. `string_to_torch_dtype` returns `None` for that string, and the later `.to(lora_dtype)` call on the adapters then fails on a newly added Train LoRA node.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: f59aa351-9835-4433-aeaf-a6b43a85581d -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L343-L347
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYzYThhYzI2LTE1YTctNDllZC05YjY5LTEyNGNhNDkxNzk0NCIsImVuY3J5cHRpb25LZXkiOiJBZjRVdVFfM2xaTjBIcTVYQ3MzMDJMQlZtdHY1bnhxSU10Z3RVQlBKSXF3IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjYzYThhYzI2LTE1YTctNDllZC05YjY5LTEyNGNhNDkxNzk0NCIsImVuY3J5cHRpb25LZXkiOiJBZjRVdVFfM2xaTjBIcTVYQ3MzMDJMQlZtdHY1bnhxSU10Z3RVQlBKSXF3IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Resume parsing crashes on LoRA names
**High Severity**
<!-- DESCRIPTION START -->
Continuing from an existing LoRA always does `int(...)` on a filename segment before `_steps_`. The dropdown lists every file in the loras folder, so typical names without that pattern raise `ValueError` and abort training before weights are loaded.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 7028748c-3fb9-496b-a75b-1307de6bfc84 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L399-L403
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjkyNzQzNjA1LTlkYzgtNGIwOC04ZjFiLTRiYzM5MDg0YzIwZiIsImVuY3J5cHRpb25LZXkiOiJOSmhQSXlrQ1hOQnVSbEZrTGJiZ19LN3FmVzFPckwySGlZRXRIVzV3Q1A0IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjkyNzQzNjA1LTlkYzgtNGIwOC04ZjFiLTRiYzM5MDg0YzIwZiIsImVuY3J5cHRpb25LZXkiOiJOSmhQSXlrQ1hOQnVSbEZrTGJiZ19LN3FmVzFPckwySGlZRXRIVzV3Q1A0IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### LoRA mid layer constructed incorrectly
**Medium Severity**
<!-- DESCRIPTION START -->
`LoraDiff` builds conv modules with a missing `kernel_size` and passes the `mid` tensor as `in_channels`. Conv LoRA weights also get copied into `Linear` parameters. `to_train()` therefore crashes or mis-shapes weights for locon/conv adapters.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: cd9997f9-0620-4033-99f5-69ce030bfe3f -->
<!-- LOCATIONS START
comfy/weight_adapter/lora.py#L20-L36
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmUxNTBhNjQwLTIzNjAtNDA5My04ZjkwLTI1OWRjZTYwZGY5NiIsImVuY3J5cHRpb25LZXkiOiJuOWVCOUFqZUhzTXN5QzFzM29fMy1YZEExMGNGb3hkQ3pPRFlSMGM3b2tvIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmUxNTBhNjQwLTIzNjAtNDA5My04ZjkwLTI1OWRjZTYwZGY5NiIsImVuY3J5cHRpb25LZXkiOiJuOWVCOUFqZUhzTXN5QzFzM29fMy1YZEExMGNGb3hkQ3pPRFlSMGM3b2tvIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Pad resize stretches images instead
**Medium Severity**
<!-- DESCRIPTION START -->
The `Pad` resize option calls the same LANCZOS `resize` as `Stretch`, so it distorts images to the first frame's size instead of padding them. Training batches then use warped pixels whenever the user picks `Pad` to preserve aspect ratio.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 509b00bb-be9d-4eb2-b895-06bc20664f21 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L106-L112
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE0N2FhYTUyLTA1NTItNDIzMC1iZDIyLWM4ZTIzYjEwODJmMyIsImVuY3J5cHRpb25LZXkiOiJvWlZmYVZ5cDZGejAySWxNa0RTQUFjVkM3ZE42Vk5NTXpscXFlUFJxTEtjIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjE0N2FhYTUyLTA1NTItNDIzMC1iZDIyLWM4ZTIzYjEwODJmMyIsImVuY3J5cHRpb25LZXkiOiJvWlZmYVZ5cDZGejAySWxNa0RTQUFjVkM3ZE42Vk5NTXpscXFlUFJxTEtjIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### LoRA save ignores configured paths
**Medium Severity**
<!-- DESCRIPTION START -->
`SaveLoRA` writes to a CWD-relative `models/loras/` path and never creates the directory or uses `folder_paths`. If the process was not started from the ComfyUI root, or loras live in a custom folder, save fails or the file never appears in the LoRA list.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: b23383d7-9622-4b1c-96d4-ded1278eb7cf -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L595-L602
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZlYmIyZjM2LWRkODEtNDc4Ni1hOGQwLWYxOTRlMDQ4Mjk0MCIsImVuY3J5cHRpb25LZXkiOiI4clFidVlmQVBGZUdKV19DM1VWVEtLQ3R3MFJXTVdqcmJmbkNMb25rajNzIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmZlYmIyZjM2LWRkODEtNDc4Ni1hOGQwLWYxOTRlMDQ4Mjk0MCIsImVuY3J5cHRpb25LZXkiOiI4clFidVlmQVBGZUdKV19DM1VWVEtLQ3R3MFJXTVdqcmJmbkNMb25rajNzIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Training reuses a single image batch
**Medium Severity**
<!-- DESCRIPTION START -->
A random slice of `batch_size` images is encoded once before the loop and reused every step. Extra dataset images are never seen, and `batch_size` does not act as a mini-batch over the full set, so longer runs overfit that one subset.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: e9b18773-357c-42e1-bca7-7d2e72942c91 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L380-L386
comfy_extras/nodes_train.py#L501-L514
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`comfy_extras/nodes_train.py#L501-L514`](https://github.com/drape-io/crbench-cursor-2026-09/blob/af2e5b90029649d1bf0ae1479b7484e8aa04b155/comfy_extras/nodes_train.py#L501-L514)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmM0NWM3MjcwLTFjMTItNDI5Yi05MTFlLWMwMDgyNWVmZDc0NCIsImVuY3J5cHRpb25LZXkiOiJneTltZWs0OGdOVFVYLTVMY1JsR1NBQmd2d0hLSE1NekJTUlRxdFEwQVBrIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmM0NWM3MjcwLTFjMTItNDI5Yi05MTFlLWMwMDgyNWVmZDc0NCIsImVuY3J5cHRpb25LZXkiOiJneTltZWs0OGdOVFVYLTVMY1JsR1NBQmd2d0hLSE1NekJTUlRxdFEwQVBrIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Seed does not initialize LoRA weights
**Medium Severity**
<!-- DESCRIPTION START -->
A `torch.Generator` is seeded from the node `seed` but never passed into LoRA init, batch sampling, or sigma sampling. `kaiming_uniform_` and `torch.randperm` use the global RNG, so runs with the same seed are not reproducible despite the tooltip.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 15d95d0f-fe00-4fb0-ad92-9eedffaab115 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L393-L395
comfy/weight_adapter/lora.py#L68-L72
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`comfy/weight_adapter/lora.py#L68-L72`](https://github.com/drape-io/crbench-cursor-2026-09/blob/af2e5b90029649d1bf0ae1479b7484e8aa04b155/comfy/weight_adapter/lora.py#L68-L72)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmRhYTNmN2FlLTEwYWYtNDM0Yi1hZjQ5LWE1N2Y5NDY4ZDU0NiIsImVuY3J5cHRpb25LZXkiOiJaanhVVThyVklQekVrQVhXU2FPTGI2UWlIU0g2YzhKUnFPMGN3OHI4OERnIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OmRhYTNmN2FlLTEwYWYtNDM0Yi1hZjQ5LWE1N2Y5NDY4ZDU0NiIsImVuY3J5cHRpb25LZXkiOiJaanhVVThyVklQekVrQVhXU2FPTGI2UWlIU0g2YzhKUnFPMGN3OHI4OERnIiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Resume looks up alpha under wrong key
**Medium Severity**
<!-- DESCRIPTION START -->
Existing alpha and dora scale are read from `{module}.weight.alpha` / `{module}.weight.dora_scale`, but adapters save and load `{module}.alpha`. Resume therefore always falls back to alpha `1.0` and drops dora scale even when those tensors are in the file.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: b30de97d-bf52-4026-9c17-d367005760db -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L410-L417
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjNhZjk3YTRlLTc4ZjEtNDMzZS1hNWM4LTA2YWFmZTk4OGU2NSIsImVuY3J5cHRpb25LZXkiOiIxVmgwUUVhWW5Odm90a0ZDWllDbGE2OVBOOVJuUGR5VzU5eVRsN2lwQ0o0IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjNhZjk3YTRlLTc4ZjEtNDMzZS1hNWM4LTA2YWFmZTk4OGU2NSIsImVuY3J5cHRpb25LZXkiOiIxVmgwUUVhWW5Odm90a0ZDWllDbGE2OVBOOVJuUGR5VzU5eVRsN2lwQ0o0IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Loss graph divides by zero
**Low Severity**
<!-- DESCRIPTION START -->
The plot scales losses by `(max_loss - min_loss)`. When every recorded loss is the same value, that denominator is zero and Python raises `ZeroDivisionError`, so the graph node crashes after an otherwise successful train.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 0a1e055c-bf99-429e-8103-506ac1a74ca2 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L636-L638
LOCATIONS END -->
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjBkYWVjNDY4LTY3NDYtNDhmYi1hMjI1LTUyMDNlYzcwZjE4ZSIsImVuY3J5cHRpb25LZXkiOiJvb0pqbV9rR0UxeVZIemc2RE56WjJxUzFpbGVaZjczMFBCNEhEdDBGWGp3IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjBkYWVjNDY4LTY3NDYtNDhmYi1hMjI1LTUyMDNlYzcwZjE4ZSIsImVuY3J5cHRpb25LZXkiOiJvb0pqbV9rR0UxeVZIemc2RE56WjJxUzFpbGVaZjczMFBCNEhEdDBGWGp3IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
### Image set loader is unused and broken
**Low Severity**
<!-- DESCRIPTION START -->
`LoadImageSetNode` is never registered in `NODE_CLASS_MAPPINGS`, so users cannot load a picked image set. The execute method also takes `input_files` while `INPUT_TYPES` names the input `images`, so the node would fail immediately if it were registered.
<!-- DESCRIPTION END -->
<!-- BUGBOT_BUG_ID: 831c32b2-23ed-4de6-a147-5d2e43cc9159 -->
<!-- LOCATIONS START
comfy_extras/nodes_train.py#L124-L172
comfy_extras/nodes_train.py#L696-L703
LOCATIONS END -->
<details>
<summary>Additional Locations (1)</summary>
- [`comfy_extras/nodes_train.py#L696-L703`](https://github.com/drape-io/crbench-cursor-2026-09/blob/af2e5b90029649d1bf0ae1479b7484e8aa04b155/comfy_extras/nodes_train.py#L696-L703)
</details>
<div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjllMDU3N2NmLWY4NzEtNDllOC1hMjAwLTYwYzAwMGJkYzI3YiIsImVuY3J5cHRpb25LZXkiOiJ3TVZXaXBYQ3RZbUgtWjZZT3VlOVVIa1NIT19OYzgxRHp4ckVRUGI0WXk0IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjllMDU3N2NmLWY4NzEtNDllOC1hMjAwLTYwYzAwMGJkYzI3YiIsImVuY3J5cHRpb25LZXkiOiJ3TVZXaXBYQ3RZbUgtWjZZT3VlOVVIa1NIT19OYzgxRHp4ckVRUGI0WXk0IiwiYnJhbmNoIjoicHItNTZjZTFjNjdhMCIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjEwNSwiY29tbWl0U2hhIjoiYWYyZTViOTAwMjk2NDlkMWJmMGFlMTQ3OWI3NDg0ZThhYTA0YjE1NSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div>
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_REVIEW -->
Cursor Bugbot has reviewed your changes using high effort and found 11 potential issues.
<!-- BUGBOT_FIX_ALL -->
<a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo3MzMwYmE5NC0yZjUyLTQ0NDYtOTBlNS0zNWYwMTBjYjY0OTQiLCJlbmNyeXB0aW9uS2V5IjoiX0RpNzBsQkt2THg1bGNackNBSkVBQjVEOWpYb1ZsUDk0dTJXWWRUY1RHZyIsImJyYW5jaCI6InByLTU2Y2UxYzY3YTAiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>
<!-- /BUGBOT_FIX_ALL -->
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN -->
<sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END -->
<sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit af2e5b90029649d1bf0ae1479b7484e8aa04b155. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✓ | off by one |
If the filename has no _steps_ pattern, the last '_' segment (e.g. 'foo.safetensors') gets passed to int(), which raises ValueError. [grounded: diff] [consensus 3/3: valid=3]
key is '<n>.weight', so the lookup is '<n>.weight.alpha'. LoRA files, including this node's own saves, store '<n>.alpha', so the lookup always falls back to 1.0. [grounded: diff] [consensus 3/3: valid=3]
The diff and diff_b parameters are always created as zeros and existing_weights is never consulted for them, so prior training of these weights is lost when resuming. [grounded: diff] [consensus 3/3: valid=3]
The prompt-supplied prefix is joined into the path without validation, unlike get_save_image_path, so '../' can write outside the temp directory. [grounded: diff] [consensus 3/3: valid=3]
With steps=1 (the allowed minimum) or identical losses, max_loss - min_loss is 0 and the division raises ZeroDivisionError. [grounded: diff] [consensus 3/3: valid=3]
'bf32' is not one of the combo options, and string_to_torch_dtype returns None for it. [grounded: diff] [consensus 3/3: valid=3]
The except block only logs and never re-raises, so if loss_fn raised, loss is unbound and backward() raises UnboundLocalError. The grad error the handler targets comes from backward(), which is outside the try. [grounded: diff] [consensus 3/3: valid=3]
The path is relative to the working directory, ignores folder_paths, and uses an unsanitized prefix, so it allows traversal and breaks when ComfyUI runs from another directory. [grounded: diff] [consensus 3/3: valid=3]
A 4-D conv LoRA tensor cannot broadcast into a 2-D Linear weight, so copy_ fails when resuming from a conv LoRA without mid. [grounded: diff] [consensus 3/3: valid=3]
The conv layer is built with a tensor as in_channels and no kernel_size, and a 4-D mid gives convdim=2, which selects Conv3d. Any LoRA with lora_mid crashes. [grounded: diff] [consensus 3/3: valid=3]
Only LoRAAdapter overrides to_train. Every other adapter inherits the base method, which raises NotImplementedError. [grounded: diff] [consensus 3/3: valid=3]
The subset is chosen and encoded once before the loop, so every step reuses the same batch and images beyond batch_size are never trained on. [grounded: diff] [consensus 3/3: valid=3]
The generator is seeded but never passed to randperm, rand or the init, so those use the global RNG. Noise is seeded separately, so the seed has only partial effect. [grounded: diff] [consensus 3/3: valid=3]
The matrices are allocated in the base weight's dtype, and kaiming_uniform_ (uniform_) is not implemented for fp8 dtypes, so init fails on fp8 weights. [grounded: diff] [consensus 3/3: valid=3]
patch() runs on the shared model before the try. If the load or later setup raises, the finally/unpatch never runs. [grounded: diff] [consensus 3/3: valid=3]
model_base only calls eval() on specific models (lines 650 and 679), not Cosmos, so training stays at the nn.Module default of True. Inference therefore goes through checkpoint, which stashes RNG state and adds overhead on every block call. [grounded: diff] [consensus 3/3: valid=3]
raw comments (17)
**Resuming from most LoRA filenames crashes**
The step count is parsed from the filename with no fallback, so any LoRA not named like `..._N_steps_...` makes `int()` raise and the node fails. Use a regex match and fall back to 0 when the pattern is absent.
```
comfy_extras/nodes_train.py:398 existing_weights = {}
comfy_extras/nodes_train.py:399 existing_steps = 0
comfy_extras/nodes_train.py:400 if existing_lora != "[None]":
comfy_extras/nodes_train.py:401 lora_path = folder_paths.get_full_path_or_raise("loras", existing_lora)
comfy_extras/nodes_train.py:402 # Extract steps from filename like "trained_lora_10_steps_20250225_203716"
```
**Existing LoRA alpha is never read**
The alpha is looked up as `<module>.weight.alpha`, but LoRA files (including the ones this node saves) store it as `<module>.alpha`. So resumed training always uses alpha 1.0. Look up f"{n}.alpha" and f"{n}.dora_scale".
```
comfy_extras/nodes_train.py:410 if m.weight is not None:
comfy_extras/nodes_train.py:411 key = "{}.weight".format(n)
comfy_extras/nodes_train.py:412 shape = m.weight.shape
comfy_extras/nodes_train.py:413 if len(shape) >= 2:
comfy/lora.py:72 diff_name = "{}.diff".format(x)
comfy_extras/nodes_train.py:440 mp.add_weight_wrapper(key, train_adapter)
```
**Resumed training drops existing diff/diff_b weights**
When `existing_lora` is given, the 1D weight diffs (`<n>.diff`) and bias diffs (`<n>.diff_b`) are always re-created as zeros instead of loaded from `existing_weights`. Previously trained norm/bias changes are lost while the step count still includes them. Initialise from existing_weights.get(f"{n}.diff") / f"{n}.diff_b" when present.
```
comfy_extras/nodes_train.py:443 diff = torch.nn.Parameter(
comfy_extras/nodes_train.py:444 torch.zeros(
comfy_extras/nodes_train.py:445 m.weight.shape, dtype=dtype, requires_grad=True
comfy_extras/nodes_train.py:446 )
comfy_extras/nodes_train.py:447 )
comfy_extras/nodes_train.py:448 diff_module = BiasDiff(diff)
comfy_extras/nodes_train.py:449 mp.add_weight_wrapper(key, BiasDiff(diff))
comfy_extras/nodes_train.py:450 all_weight_adapters.append(diff_module)
comfy_extras/nodes_train.py:451 lora_sd["{}.diff".format(n)] = diff
comfy_extras/nodes_train.py:452 if hasattr(m, "bias") and m.bias is not None:
```
**Loss graph filename prefix allows path traversal**
`filename_prefix` is joined into the temp dir path without validation, so `../` sequences write the PNG outside the temp directory. Use folder_paths.get_save_image_path for the filename.
```
comfy_extras/nodes_train.py:686 "images": [
comfy_extras/nodes_train.py:687 {
comfy_extras/nodes_train.py:688 "filename": f"{filename_prefix}_{date}.png",
comfy_extras/nodes_train.py:689 "subfolder": "",
```
**Loss graph crashes when loss doesn't vary**
With one training step, or any run where all loss values are equal, `max_loss - min_loss` is 0, so scaling divides by zero. Use a non-zero range, e.g. max(max_loss - min_loss, 1e-8).
```
comfy_extras/nodes_train.py:655 try:
comfy_extras/nodes_train.py:656 font = ImageFont.truetype("arial.ttf", 12)
```
**"Pad" resize stretches instead of padding**
The "Pad" branch does the same LANCZOS stretch as "Stretch", so choosing Pad distorts the aspect ratio instead of padding the image. Resize to fit, then paste onto a (w, h) canvas.
```
comfy_extras/nodes_train.py:110 img = img.crop((0, 0, w, h))
comfy_extras/nodes_train.py:111 elif resize_method == "Pad":
comfy_extras/nodes_train.py:106 if img.size[0] != w or img.size[1] != h:
comfy_extras/nodes_train.py:107 if resize_method == "Stretch":
comfy_extras/nodes_train.py:108 img = img.resize((w, h), Image.Resampling.LANCZOS)
comfy_extras/nodes_train.py:109 elif resize_method == "Crop":
```
**lora_dtype default 'bf32' is not a valid option**
The default for `lora_dtype` is "bf32", which isn't in the ["bf16","fp32"] options. A newly added node can then fail validation, or `string_to_torch_dtype` returns None for it. Change the default to "bf16" or "fp32".
```
comfy_extras/nodes_train.py:365 self,
comfy_extras/nodes_train.py:366 model,
comfy_extras/nodes_train.py:367 vae,
comfy_extras/nodes_train.py:368 positive,
node_helpers.py:46 def string_to_torch_dtype(string):
node_helpers.py:47 if string == "fp32":
node_helpers.py:48 return torch.float32
node_helpers.py:49 if string == "fp16":
node_helpers.py:50 return torch.float16
node_helpers.py:51 if string == "bf16":
```
**Swallowed loss error causes UnboundLocalError**
When `loss_fn` raises a RuntimeError, the except block only logs it, and `loss.backward()` then runs on an unset `loss`. Also, the "does not require grad" error this handler is meant to catch is raised by `backward()`, which sits outside the try. Put `loss.backward()` inside the try and re-raise after logging.
```
comfy_extras/nodes_train.py:46 try:
comfy_extras/nodes_train.py:47 loss = self.loss_fn(denoised, latent.clone())
comfy_extras/nodes_train.py:48 except RuntimeError as e:
comfy_extras/nodes_train.py:49 if "does not require grad and does not have a grad_fn" in str(e):
comfy_extras/nodes_train.py:50 logging.info("WARNING: This is likely due to the model is loaded in inference mode.")
comfy_extras/nodes_train.py:51 loss.backward()
comfy_extras/nodes_train.py:52 if self.loss_callback:
```
**SaveLoRA writes to CWD path with unsanitized prefix**
`save` builds the path as `models/loras/{prefix}...` relative to the current working directory, ignoring `folder_paths`. `prefix` comes straight from the prompt, so `../` sequences can write the file anywhere, and the save fails when ComfyUI runs from another directory. Resolve the path with `folder_paths.get_save_image_path(prefix, folder_paths.get_folder_paths('loras')[0])`, which validates it.
```
comfy_extras/nodes_train.py:588 }
comfy_extras/nodes_train.py:590 RETURN_TYPES = ()
comfy_extras/nodes_train.py:591 FUNCTION = "save"
comfy_extras/nodes_train.py:592 CATEGORY = "loaders"
comfy_extras/nodes_train.py:593 EXPERIMENTAL = True
comfy_extras/nodes_train.py:594 OUTPUT_NODE = True
```
**Conv LoRA weights don't fit Linear layer**
When there is no `mid`, `LoraDiff` always builds `nn.Linear` layers. A regular conv LoRA stores `lora_up` as (out, rank, 1, 1) and `lora_down` as (rank, in, k, k), so `copy_` into the 2-D Linear weight fails. Flatten mat1/mat2 to 2-D before copying, or keep them as raw Parameters.
```
comfy/weight_adapter/lora.py:30 self.lora_up = layer(rank, out_dim, bias=False)
comfy/weight_adapter/lora.py:31 self.lora_down = layer(in_dim, rank, bias=False)
comfy/weight_adapter/lora.py:32 self.lora_up.weight.data.copy_(mat1)
comfy/weight_adapter/lora.py:33 self.lora_down.weight.data.copy_(mat2)
```
**Resuming from a conv/LoCon LoRA crashes**
`LoraDiff` builds conv layers with no kernel_size, passes the `mid` tensor as the channel count, and indexes the conv classes off by one. Any existing LoRA with `lora_mid` fails. Keep mat1/mat2/mid as plain nn.Parameters in their original shapes.
```
comfy/weight_adapter/lora.py:22 convdim = mid.ndim - 2
comfy/weight_adapter/lora.py:23 layer = (
comfy/weight_adapter/lora.py:24 torch.nn.Conv1d,
comfy/weight_adapter/lora.py:25 torch.nn.Conv2d,
comfy/weight_adapter/lora.py:26 torch.nn.Conv3d
comfy/weight_adapter/lora.py:27 )[convdim]
comfy/weight_adapter/lora.py:28 else:
comfy/weight_adapter/lora.py:29 layer = torch.nn.Linear
comfy/weight_adapter/lora.py:30 self.lora_up = layer(rank, out_dim, bias=False)
comfy/weight_adapter/lora.py:31 self.lora_down = layer(in_dim, rank, bias=False)
```
**Resuming a LoHa/LoKr/OFT LoRA raises NotImplementedError**
Every adapter class gets to load the existing weights, but only `LoRAAdapter` implements `to_train`. A matching LoHa, LoKr, OFT, BOFT or GLoRA file crashes. Only try LoRAAdapter here, or raise a clear unsupported-format error.
```
comfy_extras/nodes_train.py:423 break
comfy_extras/nodes_train.py:424 else:
comfy_extras/nodes_train.py:425 # If no existing adapter found, use LoRA
comfy_extras/nodes_train.py:426 # We will add algo option in the future
comfy/weight_adapter/base.py:18 def to_train(self) -> "WeightAdapterTrainBase":
comfy/weight_adapter/base.py:19 raise NotImplementedError
```
**Training only ever sees one random subset**
`torch.randperm(num_images)[:batch_size]` runs once before the loop and is encoded once. Every step reuses the same images, and images beyond `batch_size` are never trained on. Encode all images once and pick a random batch inside the step loop.
```
comfy_extras/nodes_train.py:385 # Ensure we're not in inference mode when encoding
comfy_extras/nodes_train.py:386 encoded = vae.encode(batch_tensor)
comfy_extras/nodes_train.py:387 mp = model.clone()
comfy_extras/nodes_train.py:388 dtype = node_helpers.string_to_torch_dtype(training_dtype)
comfy_extras/nodes_train.py:389 lora_dtype = node_helpers.string_to_torch_dtype(lora_dtype)
comfy_extras/nodes_train.py:390 mp.set_model_compute_dtype(dtype)
```
**Seed has no effect on init or sigma**
The seeded `generator` is never used. LoRA init (`kaiming_uniform_`), the subset `randperm` and the per-step `torch.rand` sigma all use the global RNG, so the same seed gives different runs. Pass the generator to randperm, rand and the init.
```
comfy_extras/nodes_train.py:386 encoded = vae.encode(batch_tensor)
comfy_extras/nodes_train.py:400 if existing_lora != "[None]":
comfy_extras/nodes_train.py:401 lora_path = folder_paths.get_full_path_or_raise("loras", existing_lora)
comfy_extras/nodes_train.py:513 noise, guider, train_sampler, sigma, {"samples": encoded.clone()}
comfy_extras/nodes_train.py:514 )
```
**Training an fp8 model crashes at LoRA init**
`create_train` allocates the LoRA matrices in the base weight's dtype, then runs `kaiming_uniform_` on them. For fp8 weights the uniform init isn't implemented, so it fails before the later `.to(lora_dtype)`. Allocate in float32 (or the LoRA dtype), not weight.dtype.
```
comfy/weight_adapter/lora.py:66 def create_train(cls, weight, rank=1, alpha=1.0):
comfy/weight_adapter/lora.py:67 out_dim = weight.shape[0]
comfy/weight_adapter/lora.py:68 in_dim = weight.shape[1:].numel()
comfy/weight_adapter/lora.py:69 mat1 = torch.empty(out_dim, rank, device=weight.device, dtype=weight.dtype)
comfy/weight_adapter/lora.py:70 mat2 = torch.empty(rank, in_dim, device=weight.device, dtype=weight.dtype)
comfy/weight_adapter/lora.py:71 torch.nn.init.kaiming_uniform_(mat1, a=5**0.5)
```
**Shared model left patched if GPU load fails**
`patch()` replaces `forward` on modules of the shared diffusion model before the try/finally. If `load_models_gpu` throws (for example OOM), `unpatch` never runs and every later use of that model keeps the checkpointing forwards. Move the patch loop and the GPU load inside the try.
```
comfy_extras/nodes_train.py:498 # yoland: this currently resize to the first image in the dataset
comfy_extras/nodes_train.py:521 for adapter in all_weight_adapters:
comfy_extras/nodes_train.py:522 adapter.requires_grad_(False)
```
**Cosmos inference now runs through gradient checkpointing**
ComfyUI never puts the Cosmos diffusion model in eval mode, so `self.training` is True by default. Normal sampling now goes through `torch.utils.checkpoint`, which adds overhead for no benefit. Also require torch.is_grad_enabled() before checkpointing.
```
comfy/ldm/cosmos/blocks.py:799 if self.training:
comfy/ldm/cosmos/blocks.py:800 x = torch.utils.checkpoint.checkpoint(block, x, emb_B_D, crossattn_emb, crossattn_mask, rope_emb_L_1_1_D, adaln_lora_B_3D, use_reentrant=False)
comfy/model_base.py:112 class BaseModel(torch.nn.Module):
comfy/model_base.py:113 def __init__(self, model_config, model_type=ModelType.EPS, device=None, unet_model=UNetModel):
comfy/model_base.py:114 super().__init__()
comfy/model_base.py:116 unet_config = model_config.unet_config
comfy/model_base.py:117 self.latent_format = model_config.latent_format
comfy/model_base.py:118 self.model_config = model_config
comfy/model_base.py:119 self.manual_cast_dtype = model_config.manual_cast_dtype
comfy/model_base.py:120 self.device = device
```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✗ | — |
No guard when all losses are equal (e.g. steps=1), so float division by zero raises ZeroDivisionError. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
For a filename without '_steps_', the last '_' segment (e.g. 'lora.safetensors') is not an int, so ValueError is raised. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
key is '<n>.weight', so the lookup goes to '<n>.weight.alpha', while alphas are stored as '<n>.alpha' (the same convention as the adapter keys under '<n>.'). The saved alpha is therefore ignored. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The except block swallows the RuntimeError without re-raising, so loss is unbound and loss.backward() raises UnboundLocalError, which hides the original error. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The path is relative to cwd, ignores the configured lora folders, and the prefix is not sanitized, so it can traverse outside the folder. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The seeded generator is never passed to anything. create_train uses the global RNG for kaiming_uniform_, so the seed does not control initialization. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The conv layer constructor gets a tensor as in_channels and no kernel_size (lora_up/lora_down are also missing kernel_size), so it raises TypeError whenever a LoRA with lora_mid is resumed. [grounded: diff-section comfy/weight_adapter/lora.py] [consensus 3/3: valid=3]
The default 'bf32' is not among the options and string_to_torch_dtype returns None for it. Combo validation may reject it before .to(None) is reached, but the invalid default is still a real defect. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Only LoRAAdapter overrides to_train. The other adapters inherit the base method, which raises NotImplementedError, so resuming from a LoHa/LoKr/GLoRA/OFT/BOFT file crashes. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The modules are patched before the try/finally, so if load_models_gpu raises, the shared model keeps its checkpointing forwards. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The parameter is named input_files but the declared input is 'images', so calling it raises TypeError. The class is not registered, which limits the impact. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
raw comments (11)
**Loss graph crashes when loss is constant**
`plot_loss` divides by `max_loss - min_loss` with no guard. With `steps=1`, or any constant loss, it raises ZeroDivisionError. Use a divisor of 1 when the range is zero, and handle an empty list.
```
comfy_extras/nodes_train.py:637 min_loss, max_loss = min(loss_values), max(loss_values)
comfy_extras/nodes_train.py:638 scaled_loss = [(l - min_loss) / (max_loss - min_loss) for l in loss_values]
```
**Existing LoRA without `_steps_` in name crashes**
The step count is parsed from the filename with `int(existing_lora.split("_steps_")[0].split("_")[-1])`. Any LoRA whose name lacks `_steps_` (any ordinary LoRA) raises ValueError, so the "append to existing LoRA" option only works for files this node saved. Parse with a regex and default to 0 when no match.
```
comfy_extras/nodes_train.py:434 train_adapter = adapter_cls.create_train(
comfy_extras/nodes_train.py:435 m.weight, rank=rank, alpha=1.0
comfy_extras/nodes_train.py:436 ).to(lora_dtype)
comfy_extras/nodes_train.py:437 for name, parameter in train_adapter.named_parameters():
```
**Existing LoRA alpha looked up under wrong key**
Alpha is read from `f"{key}.alpha"` where key is `<module>.weight`, but alphas are saved/loaded as `<module>.alpha`. Existing alpha is therefore ignored (always 1.0) for resumed LoRAs and dora_scale lookup also misses. Use `f"{n}.alpha"` and `f"{n}.dora_scale"`.
```
comfy_extras/nodes_train.py:444 torch.zeros(
comfy_extras/nodes_train.py:445 m.weight.shape, dtype=dtype, requires_grad=True
comfy_extras/nodes_train.py:446 )
comfy_extras/nodes_train.py:447 )
```
**Loss undefined if non-grad RuntimeError occurs**
The `except RuntimeError` only logs for one specific message; for any other RuntimeError it swallows the exception and then `loss.backward()` raises UnboundLocalError/NameError. Even for the grad message, it falls through to `loss.backward()` with `loss` unset, hiding the real error. Re-raise after logging (`raise`).
```
comfy_extras/nodes_train.py:30 self.optimizer = optimizer
comfy_extras/nodes_train.py:31 self.loss_callback = loss_callback
comfy_extras/nodes_train.py:33 def sample(self, model_wrap, sigmas, extra_args, callback, noise, latent_image=None, denoise_mask=None, disable_pbar=False):
comfy_extras/nodes_train.py:34 self.optimizer.zero_grad()
```
**Save path ignores LoRA folder and allows traversal**
SaveLoRA writes to the cwd-relative string `models/loras/{prefix}...` instead of using folder_paths, and `prefix` is unsanitized. Custom model dirs or a different working directory break saving (or fail with missing dir), and a prefix like `../../x` writes outside the loras folder. Use `folder_paths.get_folder_paths("loras")[0]` and sanitize/validate the prefix (e.g. via get_save_image_path-style handling).
```
comfy_extras/nodes_train.py:644 x = margin + int(i / steps * width) # Scale X properly
comfy_extras/nodes_train.py:645 y = height - int(l * height)
comfy_extras/nodes_train.py:646 draw.line([prev_point, (x, y)], fill="blue", width=2)
comfy_extras/nodes_train.py:647 prev_point = (x, y)
```
**Seed does not control LoRA initialization**
A `torch.Generator` is created and seeded, but never used: `create_train` initializes with kaiming_uniform_ via the global RNG. The tooltip claims the seed controls LoRA initialization, but it doesn't. Pass the generator to the initializer or seed the global RNG.
```
comfy_extras/nodes_train.py:424 else:
comfy_extras/nodes_train.py:425 # If no existing adapter found, use LoRA
comfy/weight_adapter/lora.py:66 def create_train(cls, weight, rank=1, alpha=1.0):
comfy/weight_adapter/lora.py:67 out_dim = weight.shape[0]
```
**Conv LoRA with mid tensor breaks in LoraDiff**
For a LoRA with `lora_mid`, `layer(mid, rank, bias=False)` passes the mid tensor as in_channels, which raises TypeError. Conv layers are also built without kernel_size. Store mid as a parameter with its own shape, not a conv layer built from the tensor.
```
comfy/weight_adapter/lora.py:21 if mid is not None:
comfy/weight_adapter/lora.py:22 convdim = mid.ndim - 2
comfy/weight_adapter/lora.py:23 layer = (
comfy/weight_adapter/lora.py:24 torch.nn.Conv1d,
```
**Invalid default for lora_dtype**
The `lora_dtype` default is "bf32", which is not one of its options ["bf16","fp32"]. `string_to_torch_dtype` returns None for it, so `.to(None)` is used. Change the default to "bf16".
```
comfy_extras/nodes_train.py:262 return {
comfy_extras/nodes_train.py:263 "required": {
comfy_extras/nodes_train.py:264 "model": (IO.MODEL, {"tooltip": "The model to train the LoRA on."}),
```
**Resuming non-LoRA adapter files crashes**
The train loop tries every adapter class in `adapters` and calls `existing_adapter.to_train()`. Only `LoRAAdapter` implements `to_train`; LoHa, LoKr, GLoRA, OFT and BOFT inherit the base one that raises NotImplementedError. Only try adapters that implement `to_train`, or catch NotImplementedError and report it clearly.
```
comfy_extras/nodes_train.py:449 mp.add_weight_wrapper(key, BiasDiff(diff))
comfy_extras/nodes_train.py:450 all_weight_adapters.append(diff_module)
comfy_extras/nodes_train.py:451 lora_sd["{}.diff".format(n)] = diff
comfy_extras/nodes_train.py:452 if hasattr(m, "bias") and m.bias is not None:
```
**Checkpoint patching not undone if model load fails**
`patch(m)` replaces every leaf module's `forward` before `load_models_gpu(... memory_required=1e20, force_full_load=True)`, but the `try/finally` that calls `unpatch` starts only after that call. If loading raises (e.g. OOM), the forwards stay wrapped in checkpointing. Move the patch loop and `load_models_gpu` inside the `try` so `finally` always unpatches.
```
comfy_extras/nodes_train.py:488 def loss_callback(loss):
comfy_extras/nodes_train.py:489 loss_map["loss"].append(loss)
comfy_extras/nodes_train.py:490 pbar.set_postfix({"loss": f"{loss:.4f}"})
comfy_extras/nodes_train.py:491 train_sampler = TrainSampler(
```
**Image set loader signature mismatches inputs**
`LoadImageSetNode.load_images(self, input_files, resize_method)` doesn't match the declared input name `images`. Calling it would raise TypeError. With INPUT_IS_LIST, `resize_method` also arrives as a list. The class is not registered in NODE_CLASS_MAPPINGS. Rename the parameter to `images`, unwrap the list inputs, and register the node, or remove the class.
```
comfy_extras/nodes_train.py:118 img_array = np.array(img).astype(np.float32) / 255.0
comfy_extras/nodes_train.py:119 img_tensor = torch.from_numpy(img_array)[None,]
comfy_extras/nodes_train.py:120 output_images.append(img_tensor)
comfy_extras/nodes_train.py:122 return torch.cat(output_images, dim=0)
```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✗ | — |
The prefix is put into the path unchecked, and a `../` in it lets the file be written outside models/loras. [grounded: diff] [consensus 3/3: valid=3]
If the filename has no `_steps_`, this parses the last underscore-separated part of the name as an int, which raises ValueError. [grounded: diff] [consensus 3/3: valid=3]
Only LoRAAdapter overrides to_train. The other adapters inherit the base version, which raises NotImplementedError. [grounded: diff] [consensus 3/3: valid=3]
The Conv layer gets a tensor as in_channels and no kernel_size, so constructing it raises TypeError. [grounded: diff] [consensus 3/3: valid=3]
`bf32` is not one of the combo options, and string_to_torch_dtype returns None for it. [grounded: diff] [consensus 3/3: valid=3]
When max equals min, Python float division raises ZeroDivisionError rather than producing NaN. The mechanism is described wrongly, but the node still crashes. [grounded: diff] [consensus 3/3: valid=3]
The seeded generator is never passed to randperm or kaiming_uniform_, so batch selection and LoRA init still use the global RNG. [grounded: diff] [consensus 3/3: valid=3]
PIL's Image.crop always returns an image of the box size and fills any area outside the source with zeros. Smaller images therefore come out at w x h, and the shapes match. [invalid: contradiction] [consensus 3/3: invalid=3]
raw comments (9)
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> <a href="#"><img alt="security" src="https://greptile-static-assets.s3.amazonaws.com/badges/Security.svg?v=2" align="top"></a> **LoRA save path escapes**
The workflow-controlled `prefix` is inserted directly into the save path without a containment check. A prefix containing `../` can make this node create a safetensors file outside the intended LoRA directory. This also bypasses the repository's configured model paths and safe save-path helpers.
**How this was verified:** Plain STRING inputs reach this method without sanitization, and the resulting traversable path is passed directly to the filesystem-writing API.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Valid LoRA names crash**
The picker exposes every registered LoRA file, but this code assumes every selected filename contains the generated `_steps_` naming pattern and unconditionally parses part of it as an integer. Selecting a valid third-party or manually named LoRA therefore raises `ValueError` before its weights are loaded.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Supported adapters cannot resume**
The adapter loop detects existing LoHa, LoKr, GLoRA, OFT, and BOFT checkpoints, but then calls `to_train()` on them. Those formats inherit the base implementation that raises `NotImplementedError`; only regular LoRA implements this conversion. Selecting one of the other registered formats therefore crashes training instead of resuming it.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Midpoint LoRA conversion crashes**
When an existing convolutional LoRA contains `lora_mid.weight`, `mid` is a weight tensor. This passes that tensor as the convolution's `in_channels` argument and omits the required `kernel_size`, so LoCon/Tucker-style checkpoints fail during `to_train()` before training begins.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Default LoRA dtype invalid**
The declared default is `bf32`, but the allowed values are only `bf16` and `fp32`, and the dtype conversion helper does not recognize `bf32`. When this default is used, conversion returns `None`, so the later `.to(lora_dtype)` calls become no-ops and the LoRA weights are not converted to the requested dtype.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Constant loss plotting crashes**
A valid one-step training run produces a single loss value, so `min_loss` equals `max_loss`. This normalization divides by zero and then attempts to convert the resulting NaN to an integer coordinate, causing the Plot Loss node to crash. Any longer run with a constant loss fails in the same way.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Seed does not reproduce**
The seed is applied to a new generator that is never passed to any operation. Dataset shuffling and LoRA initialization instead use the global random generator, so repeated training runs with the same documented seed can choose different batches and initialize different weights.
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Crop leaves mismatched sizes**
The `Crop` branch does not guarantee the first image's dimensions: cropping an image smaller than the first image leaves it undersized. The resulting tensors then have different spatial shapes, so `torch.cat` fails instead of creating a batch for a valid mixed-size dataset.
<!-- greptile_summary -->
<h2><a href="https://app.greptile.com/api/retrigger?id=66790233"><picture><source media="(prefers-color-scheme: dark)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/RetriggerDark.svg?v=2"><source media="(prefers-color-scheme: light)" srcset="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2"><img alt="Retrigger" src="https://greptile-static-assets.s3.amazonaws.com/badges/Retrigger.svg?v=2" align="right"></picture></a>Confidence Score: 0/5</h2>
This PR is not safe to merge because the new training workflow permits an out-of-directory file write and contains multiple deterministic crashes for supported inputs.
<h2>Findings</h2>
1. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> <img alt="Security" src="https://greptile-static-assets.s3.amazonaws.com/badges/Security.svg?v=2" align="top"> **LoRA save path escapes** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127512">▶</a>
2. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Valid LoRA names crash** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127517">▶</a>
3. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Supported adapters cannot resume** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127523">▶</a>
4. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Midpoint LoRA conversion crashes** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127528">▶</a>
5. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Default LoRA dtype invalid** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127531">▶</a>
6. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Constant loss plotting crashes** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127534">▶</a>
7. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Seed does not reproduce** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127536">▶</a>
8. <img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"> **Crop leaves mismatched sizes** <a href="https://github.com/drape-io/crbench-greptile-2026-09/pull/105#discussion_r4059127538">▶</a>
<h3>Summary</h3>
This PR introduces experimental LoRA training, loading, saving, dataset-loading, and loss-visualization nodes, adds trainable weight-adapter infrastructure, and enables checkpointing for Cosmos training. The new training workflow currently has several blocking runtime and safety problems:
- LoRA saving permits paths outside the intended model directory.
- Valid existing adapter files can fail due to filename assumptions, unsupported adapter conversion, or malformed convolutional midpoint construction.
- The default LoRA dtype is invalid and the documented seed does not make training reproducible.
- Valid one-step loss plots and mixed-size cropped datasets can crash.
<details open><summary>Diagram</summary>
```mermaid
%%{init: {'theme': 'neutral'}}%%
flowchart TD
Images[Image dataset] --> VAE[VAE encode]
Model[Base model] --> Clone[Clone model]
Existing[Optional existing adapter] --> Convert[Convert to trainable adapter]
Clone --> Wrap[Attach trainable weight wrappers]
Convert --> Wrap
VAE --> Sample[Training sampler]
Wrap --> Sample
Sample --> Loss[Compute loss and optimize]
Loss --> State[LoRA state dictionary]
State --> Apply[Apply to model]
State --> Save[Save safetensors]
Loss --> Plot[Plot loss graph]
```
</details>
<sub>Reviews (1) · Last reviewed commit: ["Update comfy/comfy\_types/node\_typing.py ..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/23bdf4abb9d80a091fcd830aa04d694157096d58)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✗ | — |
The int() parse has no guard, so any filename without the pattern raises ValueError. [grounded: diff] [consensus 3/3: valid=3]
The path is hard-coded relative to the CWD and ignores folder_paths and base_directory. [grounded: diff] [consensus 3/3: valid=3]
The batch is chosen once with the unseeded global RNG, and `encoded` is reused for every step. [grounded: diff] [consensus 3/3: valid=3]
Cosmos models are never set to eval (eval() is only called in a few model_base spots), so training stays True and inference goes through checkpoint. [grounded: diff] [consensus 3/3: valid=3]
When max == min the division is by zero, and steps=1 always produces that case. [grounded: diff] [consensus 3/3: valid=3]
The default is not in the options list, so validation fails with value-not-in-list. [grounded: diff] [consensus 3/3: valid=3]
key is "{n}.weight", but saved params are "{n}.alpha" (from named_parameters), so the lookup misses and alpha falls back to 1.0. [grounded: diff] [consensus 3/3: valid=3]
The except block never re-raises, so loss.backward() then hits UnboundLocalError. [grounded: diff] [consensus 3/3: valid=3]
A tensor is passed as in_channels, the Conv layers are built without kernel_size, and 4-D conv LoRA weights cannot be copied into Linear weights. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 2: one fixed batch, never resampled during training. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 0. [grounded: diff] [consensus 3/3: valid=3]
The path is CWD-relative and ignores folder_paths, and the prefix is not sanitized. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 5. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 6. comfy/lora.py reads "{x}.alpha". [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 8: the Conv constructors lack kernel_size and the shapes don't match. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 3. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 4. [grounded: diff] [consensus 3/3: valid=3]
Same issue as finding 7. [grounded: diff] [consensus 3/3: valid=3]
The generator is created but never used, and create_train uses the global RNG via kaiming_uniform_, despite what the tooltip says. [grounded: diff] [consensus 3/3: valid=3]
raw comments (19)
[P1] Resuming from an existing LoRA crashes unless the filename has the `_steps_` pattern
`existing_steps = int(existing_lora.split("_steps_")[0].split("_")[-1])` assumes every selected file follows the `‹prefix›_‹N›_steps_‹date›` convention. The `existing_lora` dropdown lists every file in `models/loras`, so most choices hit this case. For example, `my_style.safetensors` gives `int("style.safetensors")`. A file saved by SaveLoRA without the optional `steps` input (`trained_lora_20250101_120000_lora.safetensors`) also fails, here with `int("trained_lora")`. Either way the node raises `ValueError` before training starts. Parsing should fall back to 0 when the pattern isn't present.
[P2] SaveLoRA writes to a path relative to the current working directory
The output path is hard-coded as `models/loras/...` relative to the process CWD instead of being resolved through `folder_paths`. If ComfyUI is started from another directory, or uses `--base-directory` or extra model paths, `safetensors.torch.save_file` either fails because the directory doesn't exist or writes somewhere the `loras` loader never looks. The trained LoRA then can't be found or resumed. The path should come from `folder_paths.get_folder_paths("loras")[0]` (or a similar folder_paths lookup).
[P2] Training uses one fixed random subset of the dataset for every step
`indices = torch.randperm(num_images)[:batch_size]` runs once, before the loop, and `encoded` is reused for every step. Whenever the input image batch is larger than `batch_size`, the remaining images are never trained on. With the default `batch_size=1`, a 20-image dataset trains on a single randomly chosen image for all steps. The selection also uses the global RNG rather than the `seed` input, so which image gets trained isn't reproducible. Batches should be resampled (or cycled) inside the step loop.
[P2] Cosmos inference now always goes through gradient checkpointing
The new branch keys on `self.training`, but ComfyUI never calls `.eval()` on Cosmos diffusion models. Only StableCascade and PixArt are switched to eval in model_base/supported_models. Every module therefore stays in training mode, and normal Cosmos sampling now routes each block through `torch.utils.checkpoint.checkpoint`. That adds RNG-state capture and hook overhead to every inference call, even though no gradients are needed. The condition should also check something like `torch.is_grad_enabled()`, or use an explicit flag.
[P2] Loss graph divides by zero when all loss values are equal
`(l - min_loss) / (max_loss - min_loss)` raises `ZeroDivisionError` whenever `max_loss == min_loss`. `steps` has a minimum of 1, so a 1-step run always produces a single loss value and always hits this, and LossGraphNode fails. The zero range needs a guard.
[P3] `lora_dtype` default is not one of its options
The options are `["bf16", "fp32"]` but the default is `"bf32"`. A freshly added TrainLoraNode either fails prompt validation ("value not in list") or, if the value gets through, `string_to_torch_dtype("bf32")` returns `None`, and the LoRA parameters are then converted with `.to(None)`. The default should probably be `"bf16"` or `"fp32"`.
[P3] Existing LoRA alpha and dora_scale are looked up under the wrong key
`key` is `"{n}.weight"`, so the lookup is `"{n}.weight.alpha"`. The trained LoRA dict, and the generic LoRA format that `LoRAAdapter.load(n, ...)` matches, store the value as `"{n}.alpha"`. Resuming a LoRA whose alpha isn't 1.0 therefore silently resets alpha to 1.0 and changes the effective scale of the loaded weights. `dora_scale` has the same problem.
[P3] TrainSampler swallows the RuntimeError and then fails with an unrelated error
If `self.loss_fn` raises a `RuntimeError`, the `except` only logs when the message matches and never re-raises. `loss.backward()` then fails with `UnboundLocalError`, which hides the original error. The "does not require grad" error is raised by `backward()`, not by `loss_fn`, so the try block also doesn't cover the case it is meant to diagnose.
[P3] LoraDiff builds tucker/conv layers incorrectly
When `mid` is set, `layer(mid, rank, bias=False)` passes the `mid` tensor as `in_channels`. The Conv `lora_up`/`lora_down` are also built without the required `kernel_size`. So `to_train()` raises for any loaded LoRA that has a `lora_mid` (LoCon/tucker) weight. The Linear path also can't `copy_` the 4-D `lora_up`/`lora_down` tensors that conv LoRAs use.
[P2] Only one fixed random batch is ever trained on; the rest of the dataset is ignored
The node picks `indices = torch.randperm(num_images)[:batch_size]` once, before training starts, and encodes just those images. Every step then reuses the same `encoded` latents. With the default `batch_size=1` and a folder of N images, the LoRA trains on a single random image for all steps and never sees the other N-1. The choice also isn't seeded, so which image gets picked changes between runs. Batches should be sampled per step, or the whole dataset should be encoded and indexed inside the loop.
[P2] Choosing any existing LoRA not saved by this node crashes on step parsing
`existing_steps = int(existing_lora.split("_steps_")[0].split("_")[-1])` only works for filenames shaped like `‹prefix›_‹N›_steps_‹date›`. For any other LoRA in the `loras` folder, e.g. `my_style.safetensors`, this evaluates `int("style.safetensors")` and throws `ValueError`. That breaks the "existing_lora" option for basically every third-party LoRA, which the dropdown offers. The parse should fall back to 0 when the pattern doesn't match.
[P2] SaveLoRA writes to a CWD-relative hard-coded path
The output path is `f"models/loras/{prefix}_..."`, resolved against the process working directory. It ignores `folder_paths` (`--base-directory`, `extra_model_paths.yaml`, custom loras dirs). If ComfyUI is started from another directory, or that folder doesn't exist, the save fails with a file-not-found error, or the file lands somewhere the LoRA loaders and the `existing_lora` dropdown never look. `prefix` is also not sanitized, so a value with `../` writes outside the models directory. The path should be built from `folder_paths.get_folder_paths("loras")[0]` (or `get_save_image_path`-style handling).
[P2] `lora_dtype` default is not one of the allowed options
The combo choices are `["bf16", "fp32"]` but the default is `"bf32"`. A newly added Train LoRA node starts with a value that fails "value not in list" validation, so the user has to change it by hand before the workflow runs. It is probably meant to be `"bf16"`.
[P3] Existing LoRA alpha/dora_scale looked up under the wrong key
`key` is `"{n}.weight"`, so the lookup is `"{n}.weight.alpha"` / `"{n}.weight.dora_scale"`. LoRA files, including the ones this node saves via `named_parameters()`, store them as `"{n}.alpha"`, and `comfy/lora.py` reads `"{x}.alpha"`. When continuing training from a LoRA whose alpha isn't 1.0, alpha silently resets to 1.0, which changes the effective scale (`alpha / rank`) and is then saved back with the wrong alpha.
[P3] `LoraDiff` cannot be built for conv/Tucker LoRAs
When `mid` is not None, the conv layer constructors are called without `kernel_size` (`layer(rank, out_dim, bias=False)`), which raises `TypeError`. `layer(mid, rank, ...)` also passes a tensor as the channel count. For conv LoRAs without `mid`, `mat1`/`mat2` are 4D but are copied into `Linear` weights, so `copy_` fails on the shape mismatch. Any existing LoCon-style LoRA picked as `existing_lora` crashes in `to_train()`.
[P3] Cosmos inference now always runs through gradient checkpointing
ComfyUI never calls `.eval()` on Cosmos diffusion models: `BaseModel` doesn't, and only PixArt/a few others do. Since `nn.Module.training` defaults to True, `self.training` is True during normal sampling. Every Cosmos block in regular inference therefore goes through `torch.utils.checkpoint.checkpoint`, adding RNG-state save/restore and checkpoint bookkeeping overhead. The training node never toggles train/eval either, so this condition doesn't actually separate training from inference.
[P3] Loss graph divides by zero for single-step or constant loss
`(l - min_loss) / (max_loss - min_loss)` raises `ZeroDivisionError` when all loss values are equal. This always happens with `steps=1`, which the Train LoRA node allows (min is 1), so connecting LossGraphNode crashes in that case.
[P3] TrainSampler swallows the loss error and then hits UnboundLocalError
If `self.loss_fn` raises a `RuntimeError`, the except block only logs for one message pattern and then falls through to `loss.backward()` with `loss` unbound. The user gets `UnboundLocalError` instead of the real error. The "does not require grad" error is raised by `backward()`, not by the loss function, so the guard as written never catches the case it targets.
[P3] Seed does not control LoRA initialization despite the tooltip
The tooltip says the seed is used for LoRA weight initialization, but the `torch.Generator` created here is never passed anywhere. `LoRAAdapter.create_train` uses `kaiming_uniform_` with the global RNG, and the batch `randperm` is unseeded too. Runs with the same seed are therefore not reproducible.
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✗ | — |
The except block never re-raises and never assigns loss, so the following loss.backward() raises UnboundLocalError and hides the original error. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
For a filename without '_steps_', the last '_' segment is something like 'lora.safetensors', so int() raises ValueError and training cannot start. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
key is '{n}.weight', so the lookup asks for '{n}.weight.alpha'. The LoRA saved here (parameter path '{n}.alpha') and standard LoRAs use '{n}.alpha', so the lookup never matches and the stored alpha is ignored. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
A tensor is passed as in_channels to the Conv constructor, so building the layer fails whenever to_train() is called on a LoRA with a mid weight. [grounded: diff-section comfy/weight_adapter/lora.py] [consensus 3/4: valid=3, uncertain=1]
The output path is relative to the current working directory and ignores folder_paths and --base-directory. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
steps can be 1, which gives a single loss value, so max_loss - min_loss is 0 and the division raises ZeroDivisionError. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The default value is not one of the combo options, so it is an invalid default. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Same defect as finding 3: the mid tensor is passed as a channel count, so constructing the layer fails. [grounded: diff-section comfy/weight_adapter/lora.py] [consensus 3/4: valid=3, uncertain=1]
Same defect as finding 0: the swallowed RuntimeError leaves loss unassigned before backward(). [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The default is invalid, and node_helpers.string_to_torch_dtype returns None for 'bf32' (the function has no case for it). Execution-time combo validation would likely reject the value before train() runs, so the impact is low. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Same defect as finding 2: the wrong key means alpha and dora_scale are never read. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Same defect as finding 5: the division fails when all loss values are equal. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Same defect as finding 4: the path is hard-coded relative to the working directory instead of using folder_paths. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
raw comments (13)
[P2] Swallowed RuntimeError leads to UnboundLocalError / hidden failures
The `except RuntimeError` only logs when the message matches "does not require grad…". Any other RuntimeError (e.g. OOM, shape mismatch) is silently swallowed. In both cases `loss` is never assigned, so `loss.backward()` raises `UnboundLocalError`, which hides the real error. The matching branch also doesn't stop the run with a useful message. It should re-raise or raise a clear error.
[P2] Existing-LoRA step parsing crashes on any LoRA not named with `_steps_`
`int(existing_lora.split("_steps_")[0].split("_")[-1])` assumes the file name came from SaveLoRA with a `steps` input. SaveLoRA's `steps` input is optional, so it can write `{prefix}_{date}_lora.safetensors`. For any such file, or any externally created LoRA chosen in `existing_lora`, this raises `ValueError` (e.g. `int('lora')`) and training can't start. Fall back to 0 when parsing fails.
[P2] alpha / dora_scale looked up under the wrong key when loading an existing LoRA
`key` is `"{n}.weight"`, so the lookups `f"{key}.alpha"` and `f"{key}.dora_scale"` ask for `"{n}.weight.alpha"`. LoRA files store these as `"{n}.alpha"` and `"{n}.dora_scale"`. The lookups never match, so alpha is always 1.0 and dora_scale is always None. Continuing from an existing LoRA with a non-default alpha (any externally trained LoRA) therefore uses the wrong scale, and the alpha stored in the file is ignored.
[P2] Tucker/conv LoRA path constructs the mid layer with a tensor as channel count
`layer(mid, rank, bias=False)` passes the `mid` tensor as `in_channels`. It should pass the channel count. This raises a TypeError whenever `to_train()` is called on a LoRA that has a `mid` weight (conv/tucker LoRA), which `TrainLoraNode` does when `existing_lora` points to one. The mid weight is also never set up with the right kernel size.
[P2] SaveLoRA writes to a cwd-relative `models/loras/` path
The output path is hard-coded as `models/loras/...`, ignoring `folder_paths` (`folder_names_and_paths["loras"]` / `--base-directory`). If the process isn't started from the repo root, or the loras dir is configured elsewhere, the save fails (directory missing) or the file lands where `TrainLoraNode`'s `existing_lora` list and the loader can't find it. Use the configured loras directory (e.g. `folder_paths.get_folder_paths("loras")[0]`).
[P2] Loss graph divides by zero when all losses are equal or only one step is run
`steps` has min 1 in TrainLoraNode, and a run with a single step yields one loss value. Then `max_loss - min_loss == 0` and `(l - min_loss) / (max_loss - min_loss)` raises `ZeroDivisionError`. The same happens with a constant loss. Guard the zero range.
[P3] `lora_dtype` default `"bf32"` isn't a valid option
The combo options are `["bf16", "fp32"]` but the default is `"bf32"`. Default-value validation or the frontend will either reject it or fall back inconsistently. The default should be `"bf16"` or `"fp32"`.
[P1] Conv-LoRA with a mid tensor crashes in LoraDiff
layer(mid, rank, bias=False)` passes the `mid` tensor as `in_channels`, so constructing the layer raises TypeError. It is hit whenever `to_train()` is called on a LoRA that has a `lora_mid` weight (Tucker/conv LoRAs), for example when Train LoRA is given such a file as `existing_lora`. It should use `mid.shape[1]`/`mid.shape[0]` for the channel sizes. Also, `lora_mid` is a conv with `rank` channels but is copied from `mid` without matching shapes
[P2] Exception handler in TrainSampler leaves `loss` undefined and swallows real errors
The `except RuntimeError` only logs when the message matches the "does not require grad" case, and silently swallows every other RuntimeError (for example OOM). In both cases execution then reaches `loss.backward()` and raises `UnboundLocalError`/`NameError` on `loss`, which hides the original error. The handler should re-raise
[P2] Invalid default for `lora_dtype` — comfy_extras/nodes_train.py:~273. The default is `"bf32"`, which is not in the options `["bf16","fp32"]`. `string_to_torch_dtype("bf32")` returns None, so if the default reaches `train()`, `.to(None)` and `torch.tensor` get dtype None and the adapters and saved LoRA are not cast as intended. In the UI the default is not a valid combo choice.
[P2] Existing-LoRA alpha and dora_scale looked up under the wrong key — comfy_extras/nodes_train.py:~416-420. They are read from `f"{key}.alpha"` / `f"{key}.dora_scale"` with `key = "{n}.weight"`, but LoRA files store them as `{n}.alpha` and `{n}.dora_scale`. When continuing training from an existing LoRA, alpha therefore always falls back to 1.0 and dora_scale to None. A LoRA trained with a different alpha gets the wrong scale, and the DoRA scale is dropped.
[P2] Loss graph divides by zero on constant loss — comfy_extras/nodes_train.py:~598-599. `(l - min_loss) / (max_loss - min_loss)` raises ZeroDivisionError when all recorded losses are equal. This happens whenever `steps` is 1, which the node allows because `steps` has `min` 1, and it can also happen if the loss is constant. The graph node then fails after training has finished.
[P3] SaveLoRA writes to a CWD-relative path and bypasses folder_paths — comfy_extras/nodes_train.py:~560-563. The output is `models/loras/...` relative to the current working directory. It ignores configured/extra model paths, and `save_file` raises if the process is not started from the repo root or the directory is missing. It should use `folder_paths.get_folder_paths("loras")[0]`.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
| Defect | Severity | Found | Grade |
|---|---|---|---|
| d1 | medium | ✗ | — |
Both save paths take the prefix from the workflow and join it into the path without any containment check, so a '../' prefix can write outside the intended directory. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The except block only logs and does not re-raise, so `loss` is never assigned and the next line raises UnboundLocalError, hiding the original error. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
The seeded generator is never passed to randperm, torch.rand or the kaiming init, so all of them draw from the global RNG. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
'bf32' is not one of the offered options, and node_helpers.string_to_torch_dtype only maps fp32/fp16/bf16, so it returns None. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
A filename like 'style_lora.safetensors' gives 'lora.safetensors' here, and int() raises ValueError on it. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Only LoRAAdapter overrides to_train; LoHa, LoKr, GLoRA, OFT and BOFT inherit the base version, which raises NotImplementedError. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
Without a mid tensor, a conv LoRA gets Linear layers with 2D weights, so copying 4D factors into them fails. With a mid tensor, the tensor itself is passed as in_channels and no kernel_size is given. [grounded: diff-section comfy/weight_adapter/lora.py] [consensus 3/3: valid=3]
dora_scale and reshape are unpacked but never stored or used, so __call__ computes a plain LoRA delta that differs from the DoRA/reshape inference path. [grounded: diff-section comfy/weight_adapter/lora.py] [consensus 3/3: valid=3]
With one step or a constant loss, max equals min and this raises ZeroDivisionError. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
LoadImageSetNode is defined but missing from NODE_CLASS_MAPPINGS, so it is never registered. It may have been left out on purpose, which makes this a low-impact issue. [grounded: tree comfy_extras/nodes_train.py] [consensus 3/3: valid=3]
raw comments (12)
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
1\. Workflow prefixes escape save folders <code>🐞 Bug</code> <code>⛨ Security</code>
<pre>
<b><i>SaveLoRA.save</i></b> and <b><i>LossGraphNode.plot_loss</i></b> interpolate unrestricted workflow prefixes directly
into output paths and pass them to file-writing APIs without normalization or resolved-path
containment checks. Prefixes containing <b><i>../</i></b> can escape the configured LoRA or temporary directory
and write or overwrite safetensors and PNG files anywhere writable by the server process.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The new LoRA and loss-graph output nodes use workflow-controlled, free-form prefixes as filesystem path components without verifying that the resulting safetensors and PNG destinations remain inside their configured LoRA and temporary output directories.
## Fix Focus Areas
- comfy_extras/nodes_train.py[571-577]
- comfy_extras/nodes_train.py[596-602]
- comfy_extras/nodes_train.py[613-618]
- comfy_extras/nodes_train.py[679-683]
- folder_paths.py[356-394]
## Recommended Fix
Build each destination from its configured absolute root directory, normalize and resolve the supplied prefix, and reject any destination whose resolved parent falls outside the intended root. Follow or reuse the containment check in `get_save_image_path`, create only validated subdirectories, and pass the validated path to the safetensors writer or `img.save`.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
2\. Training failures hide their cause <code>🐞 Bug</code> <code>◔ Observability</code>
<pre>
<b><i>TrainSampler.sample</i></b> catches every <b><i>RuntimeError</i></b> raised while calculating the loss but then
executes <b><i>loss.backward()</i></b> even though <b><i>loss</i></b> was never assigned. The original model or loss failure
is consequently replaced by an <b><i>UnboundLocalError</i></b>, including the inference-mode condition the
handler attempts to diagnose.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Loss calculation errors are swallowed and replaced by a secondary unbound-local exception.
## Fix Focus Areas
- comfy_extras/nodes_train.py[43-55]
## Recommended Fix
Do not continue without a valid loss. Re-raise unexpected runtime errors with their traceback, and for the recognized inference-mode condition raise a clear chained exception or return through an explicit failure path before calling `backward`.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
7\. Equal seeds produce different training <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>TrainLoraNode.train</i></b> seeds a local generator that is never passed to any random operation. Dataset
selection, adapter initialization, and sigma sampling use global random state, so identical inputs
and seed values can produce different learned adapters.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The advertised training seed does not control several random operations that affect the result.
## Fix Focus Areas
- comfy_extras/nodes_train.py[381-395]
- comfy_extras/nodes_train.py[503-510]
- comfy/weight_adapter/lora.py[65-75]
## Recommended Fix
Create the seeded generator on the appropriate device and pass it to batch permutation, sigma sampling, and LoRA initialization. If an initializer cannot accept a generator directly, initialize the factors with generator-aware tensor operations or isolate and restore RNG state.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
8\. Default adapter precision is ignored <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>TrainLoraNode.INPUT_TYPES</i></b> offers <b><i>bf16</i></b> and <b><i>fp32</i></b> for <b><i>lora_dtype</i></b> but declares the unrecognized
value <b><i>bf32</i></b> as its default. <b><i>string_to_torch_dtype()</i></b> therefore returns <b><i>None</i></b>, which reaches the
train adapters’ and output tensors’ <b><i>.to()</i></b> calls during default-workflow training setup instead of
requesting an advertised precision conversion.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The default `lora_dtype` is neither selectable nor recognized by the dtype conversion helper, so it converts to `None` and is passed to PyTorch `.to()` calls during training setup.
## Fix Focus Areas
- comfy_extras/nodes_train.py[340-347]
- comfy_extras/nodes_train.py[388-390]
- node_helpers.py[46-53]
## Recommended Fix
Change the default to `bf16` or `fp32`, matching the intended advertised precision. Validate that dtype conversion does not return `None` before converting adapters or output tensors, and raise an explicit error for unknown dtype names rather than silently leaving tensors unchanged.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
3\. Normal existing loras abort training <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>TrainLoraNode.train</i></b> unconditionally parses every selected existing filename using the
node-specific numeric <b><i>*_steps_*</i></b> convention before loading its weights. Because the selector
includes all files in the LoRA folders, selecting an ordinary filename such as
<b><i>style_lora.safetensors</i></b> makes <b><i>int(...)</i></b> raise <b><i>ValueError</i></b> before the file is loaded.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Existing LoRA selection accepts all configured LoRA filenames, but resuming training unconditionally parses a step count using a filename convention that ordinary LoRAs need not follow, preventing their weights from being loaded.
## Fix Focus Areas
- comfy_extras/nodes_train.py[348-354]
- comfy_extras/nodes_train.py[397-405]
## Recommended Fix
Treat the prior step count as optional metadata. Explicitly match the node-generated filename pattern and parse the suffix only when it is present and numeric; otherwise retain `existing_steps = 0` and continue loading the selected weights.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
4\. Several existing adapters cannot train <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>TrainLoraNode.train</i></b> accepts the first matching class from the complete exported adapter registry
and unconditionally calls <b><i>existing_adapter.to_train()</i></b>, even though only <b><i>LoRAAdapter</i></b> overrides
the base method that raises <b><i>NotImplementedError</i></b>. Selecting a LoHa, LoKr, GLoRA, OFT, or BOFT
checkpoint therefore reaches the inherited implementation before the optimizer can be constructed.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The existing-adapter resume path detects every format in the exported weight-adapter registry, but conversion to a trainable adapter is implemented only for LoRA. Unsupported formats therefore reach the base conversion implementation instead of producing a clear validation error.
## Fix Focus Areas
- comfy_extras/nodes_train.py[418-436]
- comfy/weight_adapter/base.py[18-27]
- comfy/weight_adapter/__init__.py[1-17]
- comfy/weight_adapter/loha.py[8-49]
## Recommended Fix
Either implement `to_train` and `create_train` for every adapter format exposed to this training path, or restrict resume detection to formats with trainable implementations. For unsupported formats, return a clear node validation error before calling `to_train` or constructing the optimizer.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
5\. Convolutional loras cannot resume training <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>LoraDiff.__init__</i></b> selects <b><i>Linear</i></b> for ordinary convolution LoRAs without a <b><i>mid</i></b> tensor and
copies multidimensional factors into two-dimensional weights, while the <b><i>mid</i></b> branch omits required
convolution arguments and passes the tensor itself where an input-channel count is required. Loaded
convolutional and Tucker/LoCon formats retain these tensor shapes and therefore reach shape or
constructor errors during conversion for resumed training.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
`LoraDiff` cannot convert loaded convolutional or Tucker/LoCon tensors into trainable modules, causing existing convolutional LoRAs to fail before resumed training starts.
## Fix Focus Areas
- comfy/weight_adapter/lora.py[21-36]
- comfy/weight_adapter/lora.py[76-78]
- comfy/weight_adapter/lora.py[160-180]
- comfy/weight_adapter/lora.py[15-38]
- comfy/weight_adapter/lora.py[127-171]
- comfy/weight_adapter/base.py[127-130]
## Recommended Fix
Preserve loaded LoRA factors directly as trainable parameters, or construct linear and convolutional layers with integer channel dimensions, correct tensor dimensionality, and kernel sizes derived from each factor. Normalize factor shapes consistently with the existing inference calculation, ensure ordinary convolution factors and optional Tucker/LoCon mid factors round-trip without invalid flattening or constructor arguments, and add tests covering both plain convolution and mid-factor LoRAs.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
6\. Resumed dora weights change meaning <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>LoraDiff.__init__</i></b> unpacks loaded <b><i>dora_scale</i></b> and <b><i>reshape</i></b> metadata but neither stores nor
applies them in <b><i>__call__</i></b>, which calculates only the ordinary <b><i>alpha / rank * diff</i></b> LoRA delta.
When a DoRA or reshape-weight adapter is resumed, its trainable representation diverges from the
established inference calculation—which reshapes before calculating the delta and invokes
<b><i>weight_decompose</i></b> when a scale is present—and subsequently saves changed adapter state.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Trainable conversion drops loaded DoRA scale and reshape metadata, so resumed adapters no longer calculate the same weight update as inference and may save changed adapter state.
## Fix Focus Areas
- comfy/weight_adapter/lora.py[15-52]
- comfy/weight_adapter/lora.py[151-188]
- comfy/weight_adapter/base.py[62-91]
## Recommended Fix
Store `dora_scale` as an appropriate parameter or buffer and preserve `reshape` in the trainable adapter. Apply reshape and the same DoRA normalization semantics used by the inference adapter when producing the wrapped weight, include the required metadata in the returned training state dictionary, and add a resume test that compares the converted adapter’s initial output with the loaded adapter’s output.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
9\. One-step loss graphs always fail <code>🐞 Bug</code> <code>☼ Reliability</code>
<pre>
<b><i>LossGraphNode.plot_loss</i></b> divides every loss delta by <b><i>max_loss - min_loss</i></b> without handling an
equal minimum and maximum. A valid one-step training run, or any run with constant losses, produces
a zero denominator before the graph can be written.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
Loss plotting divides by zero whenever all recorded losses have the same value, including every valid one-step training run, preventing the graph output node from completing.
## Fix Focus Areas
- comfy_extras/nodes_train.py[289-296]
- comfy_extras/nodes_train.py[627-647]
## Recommended Fix
Handle empty and constant loss lists explicitly. When `max_loss == min_loss`, use a fixed plotted value such as 0.5 or another center/baseline for all points instead of normalizing by the zero range, and calculate horizontal positions so a single point remains valid.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
10\. The image-set loader is unavailable <code>🐞 Bug</code> <code>≡ Correctness</code>
<pre>
<b><i>LoadImageSetNode</i></b> defines a complete upload-based image loader and UI contract but is omitted from
<b><i>NODE_CLASS_MAPPINGS</i></b>. Because the server registers only the folder-based loader and other training
nodes, users cannot add or instantiate this image-upload batch loader in workflows.
</pre>
<details>
<summary><strong>Agent Prompt</strong></summary>
```
## Issue description
The multi-file, upload-based image-set loader is implemented but not exported through the node mappings, so the application cannot expose or instantiate it in workflows.
## Fix Focus Areas
- comfy_extras/nodes_train.py[125-172]
- comfy_extras/nodes_train.py[697-710]
## Recommended Fix
If the node is intended to ship, add `LoadImageSetNode` to `NODE_CLASS_MAPPINGS` and add its display name to `NODE_DISPLAY_NAME_MAPPINGS`; otherwise, remove the unreachable implementation.
```
<code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
</details>
<h3>PR Summary by Qodo</h3>
Add experimental in-app LoRA training workflow
<code>✨ Enhancement</code> <code>🐞 Bug fix</code> <code>🕐 40+ Minutes</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<details>
<summary>AI Description</summary>
<dl>
<dd>
<br/>
><pre>
>• Adds nodes for dataset loading, LoRA training, saving, loading, and loss plotting.
>• Introduces trainable weight adapters and gradient checkpointing for memory-efficient optimization.
>• Registers LoRA and loss output types for training workflows.
></pre>
</dd>
</dl>
</details>
<details>
<summary>Diagram</summary>
<dl>
<dd>
<br/>
```mermaid
graph TD
D[("Image Dataset")] --> L["Dataset Loader"] --> T["Train LoRA"]
T --> A["Trainable Adapters"] --> M["Patched Model"]
T --> S["Training Sampler"] --> M
M --> O["LoRA and Loss"] --> C["Load Save Plot"]
```
</dd>
</dl>
</details>
<details>
<summary>High-Level Assessment</summary>
<dl>
<dd>
<br/>
>The following are alternative approaches to this PR:
<details>
<summary><b>1. Dedicated training service module</b></summary>
<dl>
<dd>
- ➕ Separates training orchestration from UI node definitions
- ➕ Enables focused unit and integration testing
- ➕ Allows future training front ends to reuse the same engine
- ➖ Requires additional interfaces for progress, cancellation, and model lifecycle management
- ➖ Increases the initial implementation scope
</dd>
</dl>
</details>
<details>
<summary><b>2. External LoRA trainer integration</b></summary>
<dl>
<dd>
- ➕ Isolates training memory and failures from workflow execution
- ➕ Can reuse mature dataset, scheduling, and checkpointing capabilities
- ➖ Weakens native workflow composition
- ➖ Requires process coordination and model-format translation
- ➖ Provides a less interactive user experience
</dd>
</dl>
</details>
<details>
<summary><b>3. PyTorch parametrizations</b></summary>
<dl>
<dd>
- ➕ Avoids broad model traversal and custom weight-wrapper attachment
- ➕ Uses a standard mechanism for trainable parameter transformations
- ➖ May conflict with existing model patching and device-management abstractions
- ➖ Requires careful serialization compatibility with supported LoRA formats
</dd>
</dl>
</details>
>**Recommendation:** Keep native workflow nodes for the intended user experience, but extract the training loop, adapter lifecycle, and checkpoint policy into a dedicated reusable module. Thin node wrappers would reduce coupling, make failure cleanup testable, and avoid growing a single UI-oriented file into the training subsystem.
</dd>
</dl>
</details>
<details>
<summary> Files changed (12) <code> +914 / -31 </code> </summary>
<dl>
<dd>
<br/>
<details>
<summary>Enhancement (7) <code> +858 / -12 </code></summary>
<dl>
<dd>
<details>
<summary>node_typing.py<code>Add LoRA model and loss-map socket types</code> <code>+2/-0</code></summary>
<br/>
>Add LoRA model and loss-map socket types
>
><pre>
>• Adds dedicated node I/O identifiers for trainable LoRA state dictionaries and training loss histories.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-07b2476feaa956e943d98dd1721d00bf7f137bd319aa8b4eeafce1803c3d9756'>comfy/comfy_types/node_typing.py</a>
</details>
<details>
<summary>blocks.py<code>Checkpoint Cosmos transformer blocks during training</code> <code>+11/-8</code></summary>
<br/>
>Checkpoint Cosmos transformer blocks during training
>
><pre>
>• Runs each Cosmos DIT block through non-reentrant activation checkpointing in training mode while preserving the direct inference path. This reduces activation memory during optimization.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-130560fbe13a0833b38448dc07eea11c56d86003747281b3fe225001a1d1a022'>comfy/ldm/cosmos/blocks.py</a>
</details>
<details>
<summary>__init__.py<code>Export trainable adapter interfaces</code> <code>+7/-1</code></summary>
<br/>
>Export trainable adapter interfaces
>
><pre>
>• Exposes 'WeightAdapterTrainBase' and defines the package's public adapter API through '__all__'.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-49ef37f470dd250f3530c30a95d8adb68fcae3c4c265959fb55ac03c866f5992'>comfy/weight_adapter/__init__.py</a>
</details>
<details>
<summary>base.py<code>Define trainable weight-adapter lifecycle</code> <code>+33/-2</code></summary>
<br/>
>Define trainable weight-adapter lifecycle
>
><pre>
>• Extends the adapter contract with training creation, callable weight transformation, device movement, and memory accounting. It also adds shared Tucker decomposition helpers for convolutional adapters.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-cc48875b83e4aee56c3af902c7a43b3deaaa0398013186b4288813f7d48bbbfd'>comfy/weight_adapter/base.py</a>
</details>
<details>
<summary>lora.py<code>Implement trainable LoRA weight adapters</code> <code>+65/-1</code></summary>
<br/>
>Implement trainable LoRA weight adapters
>
><pre>
>• Adds 'LoraDiff' for differentiable linear and convolutional LoRA transformations. Existing LoRA weights can be converted to trainable modules, while new zero-impact adapters can be initialized by rank and alpha.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-97de7d08553da73573f1e74f5011edad6c176a4f2df388467e9c60b25968b03f'>comfy/weight_adapter/lora.py</a>
</details>
<details>
<summary>nodes_train.py<code>Add experimental LoRA training nodes</code> <code>+711/-0</code></summary>
<br/>
>Add experimental LoRA training nodes
>
><pre>
>• Introduces dataset loading, LoRA training, existing-adapter continuation, optimizer and loss selection, gradient checkpointing, safetensors export, model application, and loss plotting. Training emits a patched model, LoRA state dictionary, loss map, and cumulative step count.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ce'>comfy_extras/nodes_train.py</a>
</details>
<details>
<summary>folder_paths.py<code>Discover input dataset subfolders</code> <code>+29/-0</code></summary>
<br/>
>Discover input dataset subfolders
>
><pre>
>• Adds recursive discovery of input-directory subfolders for dataset selection and documents full-path lookup helpers. Returned folder paths are normalized and sorted.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-dbe582257d5c437493b61937cf8e1b9de6623c8d4922498a4a5d82cc7b485430'>folder_paths.py</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Bug fix (1) <code> +3 / -3 </code></summary>
<dl>
<dd>
<details>
<summary>attention.py<code>Make attention residual additions autograd-safe</code> <code>+3/-3</code></summary>
<br/>
>Make attention residual additions autograd-safe
>
><pre>
>• Replaces in-place residual additions with out-of-place expressions in transformer blocks, preventing mutation-related gradient failures during training.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-c584dc24c89116a545c8c4b8000a87193aa0978d89f99807dd656b8781b4e4a9'>comfy/ldm/modules/attention.py</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Refactor (2) <code> +30 / -15 </code></summary>
<dl>
<dd>
<details>
<summary>model_patcher.py<code>Normalize model patcher imports</code> <code>+11/-8</code></summary>
<br/>
>Normalize model patcher imports
>
><pre>
>• Reorders and groups standard-library, PyTorch, and Comfy imports without changing runtime behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-2ae26a19653c5687be8f1b6bcb63fcb4a40b2a70cd418bc7754f9957a10cf05c'>comfy/model_patcher.py</a>
</details>
<details>
<summary>execution.py<code>Normalize execution module imports</code> <code>+19/-7</code></summary>
<br/>
>Normalize execution module imports
>
><pre>
>• Reorders and formats execution-engine imports without changing execution behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-b1534f3f58d78f527c22bf15c92758355aa12b1dfb5d799852f36880fa0c6487'>execution.py</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Documentation (1) <code> +22 / -1 </code></summary>
<dl>
<dd>
<details>
<summary>sd.py<code>Document diffusion model state loading</code> <code>+22/-1</code></summary>
<br/>
>Document diffusion model state loading
>
><pre>
>• Adds detailed documentation for supported state-dictionary formats, model options, device placement, and return behavior.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-16fd00518fe6f54047b71d48522725da977410f8c2b77b15f6ba7d7dac85cf4f'>comfy/sd.py</a>
</details>
</dd>
</dl>
</details>
<details>
<summary>Other (1) <code> +1 / -0 </code></summary>
<dl>
<dd>
<details>
<summary>nodes.py<code>Register experimental training nodes</code> <code>+1/-0</code></summary>
<br/>
>Register experimental training nodes
>
><pre>
>• Adds 'nodes_train.py' to the built-in extra-node initialization list so the new workflow nodes are loaded at startup.
></pre>
>
><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-e485eb8bfa77e53e217e9b400c67298309ef679c6ecd69a1174366f48bb93499'>nodes.py</a>
</details>
</dd>
</dl>
</details>
</dd>
</dl>
</details>
<h3>Code Review by Qodo</h3>
<code>🐞 Bugs (10)</code> <code>📘 Rule violations (0)</code> <code>📜 Skill insights (0)</code>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<br/>
<img src="https://img.shields.io/badge/High-634FD1?style=flat-square" height="20px" alt="Action required">
<details>
<summary> 1. Workflow prefixes escape save folders <code>🐞 Bug</code> <code>⛨ Security</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>SaveLoRA.save</i></b> and <b><i>LossGraphNode.plot_loss</i></b> interpolate unrestricted workflow prefixes directly
>into output paths and pass them to file-writing APIs without normalization or resolved-path
>containment checks. Prefixes containing <b><i>../</i></b> can escape the configured LoRA or temporary directory
>and write or overwrite safetensors and PNG files anywhere writable by the server process.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R599-602]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR599-R602)</code>
>
>```diff
>+ output_file = f"models/loras/{prefix}_{date}_lora.safetensors"
>+ else:
>+ output_file = f"models/loras/{prefix}_{steps}_steps_{date}_lora.safetensors"
>+ safetensors.torch.save_file(lora, output_file)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>Both nodes expose their filename prefixes as free-form strings and pass paths built from those
>values directly to safetensors or image-writing APIs. The repository’s existing output-path helper
>demonstrates the missing protection by resolving destinations and rejecting paths outside the
>configured output directory.
></pre>
>
> <code>[comfy_extras/nodes_train.py[571-602]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L571-L602)</code>
> <code>[comfy_extras/nodes_train.py[613-615]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L613-L615)</code>
> <code>[comfy_extras/nodes_train.py[679-683]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L679-L683)</code>
> <code>[folder_paths.py[356-394]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/folder_paths.py/#L356-L394)</code>
> <code>[comfy_extras/nodes_train.py[571-577]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L571-L577)</code>
> <code>[comfy_extras/nodes_train.py[596-602]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L596-L602)</code>
> <code>[folder_paths.py[357-383]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/folder_paths.py/#L357-L383)</code>
> <code>[comfy_extras/nodes_train.py[613-618]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L613-L618)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The new LoRA and loss-graph output nodes use workflow-controlled, free-form prefixes as filesystem path components without verifying that the resulting safetensors and PNG destinations remain inside their configured LoRA and temporary output directories.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[571-577]
>- comfy_extras/nodes_train.py[596-602]
>- comfy_extras/nodes_train.py[613-618]
>- comfy_extras/nodes_train.py[679-683]
>- folder_paths.py[356-394]
>
>## Recommended Fix
>Build each destination from its configured absolute root directory, normalize and resolve the supplied prefix, and reject any destination whose resolved parent falls outside the intended root. Follow or reuse the containment check in `get_save_image_path`, create only validated subdirectories, and pass the validated path to the safetensors writer or `img.save`.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 2. Training failures hide their cause <code>🐞 Bug</code> <code>◔ Observability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TrainSampler.sample</i></b> catches every <b><i>RuntimeError</i></b> raised while calculating the loss but then
>executes <b><i>loss.backward()</i></b> even though <b><i>loss</i></b> was never assigned. The original model or loss failure
>is consequently replaced by an <b><i>UnboundLocalError</i></b>, including the inference-mode condition the
>handler attempts to diagnose.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R46-51]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR46-R51)</code>
>
>```diff
>+ try:
>+ loss = self.loss_fn(denoised, latent.clone())
>+ except RuntimeError as e:
>+ if "does not require grad and does not have a grad_fn" in str(e):
>+ logging.info("WARNING: This is likely due to the model is loaded in inference mode.")
>+ loss.backward()
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>Assignment to <b><i>loss</i></b> occurs inside the <b><i>try</i></b>, the handler does not assign or return, and the next
>statement dereferences <b><i>loss</i></b> unconditionally.
></pre>
>
> <code>[comfy_extras/nodes_train.py[43-55]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L43-L55)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Loss calculation errors are swallowed and replaced by a secondary unbound-local exception.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[43-55]
>
>## Recommended Fix
>Do not continue without a valid loss. Re-raise unexpected runtime errors with their traceback, and for the recognized inference-mode condition raise a clear chained exception or return through an explicit failure path before calling `backward`.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 3. Normal existing LoRAs abort training <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TrainLoraNode.train</i></b> unconditionally parses every selected existing filename using the
>node-specific numeric <b><i>*_steps_*</i></b> convention before loading its weights. Because the selector
>includes all files in the LoRA folders, selecting an ordinary filename such as
><b><i>style_lora.safetensors</i></b> makes <b><i>int(...)</i></b> raise <b><i>ValueError</i></b> before the file is loaded.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[403]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR403-R403)</code>
>
>```diff
>+ existing_steps = int(existing_lora.split("_steps_")[0].split("_")[-1])
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The input selector is populated from the complete configured LoRA filename list, while the new
>loading path treats every non-sentinel selection as though it follows this node's generated filename
>convention and unconditionally converts the presumed step segment to an integer.
></pre>
>
> <code>[comfy_extras/nodes_train.py[348-353]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L348-L353)</code>
> <code>[comfy_extras/nodes_train.py[400-405]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L400-L405)</code>
> <code>[folder_paths.py[342-350]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/folder_paths.py/#L342-L350)</code>
> <code>[comfy_extras/nodes_train.py[348-354]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L348-L354)</code>
> <code>[comfy_extras/nodes_train.py[397-405]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L397-L405)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Existing LoRA selection accepts all configured LoRA filenames, but resuming training unconditionally parses a step count using a filename convention that ordinary LoRAs need not follow, preventing their weights from being loaded.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[348-354]
>- comfy_extras/nodes_train.py[397-405]
>
>## Recommended Fix
>Treat the prior step count as optional metadata. Explicitly match the node-generated filename pattern and parse the suffix only when it is present and numeric; otherwise retain `existing_steps = 0` and continue loading the selected weights.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details><summary><ins><strong>View high (3)</strong></ins></summary><br/>
<details>
<summary> 4. Several existing adapters cannot train <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TrainLoraNode.train</i></b> accepts the first matching class from the complete exported adapter registry
>and unconditionally calls <b><i>existing_adapter.to_train()</i></b>, even though only <b><i>LoRAAdapter</i></b> overrides
>the base method that raises <b><i>NotImplementedError</i></b>. Selecting a LoHa, LoKr, GLoRA, OFT, or BOFT
>checkpoint therefore reaches the inherited implementation before the optimizer can be constructed.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R430-431]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR430-R431)</code>
>
>```diff
>+ if existing_adapter is not None:
>+ train_adapter = existing_adapter.to_train().to(lora_dtype)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The cited training node iterates over the exported adapter registry, selects the first matching
>adapter, and calls <b><i>to_train()</i></b> unconditionally. The registry contains six adapter classes, while
>the base conversion method raises unconditionally and only <b><i>LoRAAdapter</i></b> provides an override, as
>illustrated by the non-overriding LoHa implementation.
></pre>
>
> <code>[comfy_extras/nodes_train.py[418-431]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L418-L431)</code>
> <code>[comfy/weight_adapter/__init__.py[1-17]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/__init__.py/#L1-L17)</code>
> <code>[comfy/weight_adapter/base.py[18-20]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/base.py/#L18-L20)</code>
> <code>[comfy/weight_adapter/lora.py[76-78]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L76-L78)</code>
> <code>[comfy/weight_adapter/__init__.py[9-17]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/__init__.py/#L9-L17)</code>
> <code>[comfy/weight_adapter/base.py[18-27]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/base.py/#L18-L27)</code>
> <code>[comfy/weight_adapter/lora.py[77-78]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L77-L78)</code>
> <code>[comfy/weight_adapter/loha.py[8-49]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/loha.py/#L8-L49)</code>
> <code>[comfy_extras/nodes_train.py[418-436]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L418-L436)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The existing-adapter resume path detects every format in the exported weight-adapter registry, but conversion to a trainable adapter is implemented only for LoRA. Unsupported formats therefore reach the base conversion implementation instead of producing a clear validation error.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[418-436]
>- comfy/weight_adapter/base.py[18-27]
>- comfy/weight_adapter/__init__.py[1-17]
>- comfy/weight_adapter/loha.py[8-49]
>
>## Recommended Fix
>Either implement `to_train` and `create_train` for every adapter format exposed to this training path, or restrict resume detection to formats with trainable implementations. For unsupported formats, return a clear node validation error before calling `to_train` or constructing the optimizer.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 5. Convolutional LoRAs cannot resume training <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>LoraDiff.__init__</i></b> selects <b><i>Linear</i></b> for ordinary convolution LoRAs without a <b><i>mid</i></b> tensor and
>copies multidimensional factors into two-dimensional weights, while the <b><i>mid</i></b> branch omits required
>convolution arguments and passes the tensor itself where an input-channel count is required. Loaded
>convolutional and Tucker/LoCon formats retain these tensor shapes and therefore reach shape or
>constructor errors during conversion for resumed training.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy/weight_adapter/lora.py[R22-35]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-97de7d08553da73573f1e74f5011edad6c176a4f2df388467e9c60b25968b03fR22-R35)</code>
>
>```diff
>+ convdim = mid.ndim - 2
>+ layer = (
>+ torch.nn.Conv1d,
>+ torch.nn.Conv2d,
>+ torch.nn.Conv3d
>+ )[convdim]
>+ else:
>+ layer = torch.nn.Linear
>+ self.lora_up = layer(rank, out_dim, bias=False)
>+ self.lora_down = layer(in_dim, rank, bias=False)
>+ self.lora_up.weight.data.copy_(mat1)
>+ self.lora_down.weight.data.copy_(mat2)
>+ if mid is not None:
>+ self.lora_mid = layer(mid, rank, bias=False)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The cited trainable constructor assumes two-dimensional factors whenever <b><i>mid</i></b> is absent, even
>though the loader retains convolutional tensors unchanged and the established inference path
>explicitly flattens factors for its calculation. When <b><i>mid</i></b> is present, the constructor selects a
>convolution class but omits required kernel information and uses the <b><i>mid</i></b> tensor itself as
><b><i>in_channels</i></b>, demonstrating why both ordinary convolution and Tucker/LoCon inputs fail during
>conversion.
></pre>
>
> <code>[comfy/weight_adapter/lora.py[15-36]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L15-L36)</code>
> <code>[comfy/weight_adapter/lora.py[76-78]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L76-L78)</code>
> <code>[comfy/weight_adapter/lora.py[91-139]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L91-L139)</code>
> <code>[comfy/weight_adapter/lora.py[160-180]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L160-L180)</code>
> <code>[comfy/weight_adapter/lora.py[15-38]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L15-L38)</code>
> <code>[comfy/weight_adapter/lora.py[127-171]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L127-L171)</code>
> <code>[comfy/weight_adapter/base.py[127-130]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/base.py/#L127-L130)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>`LoraDiff` cannot convert loaded convolutional or Tucker/LoCon tensors into trainable modules, causing existing convolutional LoRAs to fail before resumed training starts.
>
>## Fix Focus Areas
>- comfy/weight_adapter/lora.py[21-36]
>- comfy/weight_adapter/lora.py[76-78]
>- comfy/weight_adapter/lora.py[160-180]
>- comfy/weight_adapter/lora.py[15-38]
>- comfy/weight_adapter/lora.py[127-171]
>- comfy/weight_adapter/base.py[127-130]
>
>## Recommended Fix
>Preserve loaded LoRA factors directly as trainable parameters, or construct linear and convolutional layers with integer channel dimensions, correct tensor dimensionality, and kernel sizes derived from each factor. Normalize factor shapes consistently with the existing inference calculation, ensure ordinary convolution factors and optional Tucker/LoCon mid factors round-trip without invalid flattening or constructor arguments, and add tests covering both plain convolution and mid-factor LoRAs.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 6. Resumed DoRA weights change meaning <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>LoraDiff.__init__</i></b> unpacks loaded <b><i>dora_scale</i></b> and <b><i>reshape</i></b> metadata but neither stores nor
>applies them in <b><i>__call__</i></b>, which calculates only the ordinary <b><i>alpha / rank * diff</i></b> LoRA delta.
>When a DoRA or reshape-weight adapter is resumed, its trainable representation diverges from the
>established inference calculation—which reshapes before calculating the delta and invokes
><b><i>weight_decompose</i></b> when a scale is present—and subsequently saves changed adapter state.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy/weight_adapter/lora.py[R18-20]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-97de7d08553da73573f1e74f5011edad6c176a4f2df388467e9c60b25968b03fR18-R20)</code>
>
>```diff
>+ mat1, mat2, alpha, mid, dora_scale, reshape = weights
>+ out_dim, rank = mat1.shape[0], mat1.shape[1]
>+ rank, in_dim = mat2.shape[0], mat2.shape[1]
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The cited constructor receives <b><i>dora_scale</i></b> and <b><i>reshape</i></b> in the loaded tuple but does not assign
>either value to the instance, while the trainable calculation only adds <b><i>alpha / rank * diff</i></b>. By
>contrast, the established inference path applies reshape metadata before calculating the delta and
>invokes <b><i>weight_decompose</i></b> whenever <b><i>dora_scale</i></b> is present, demonstrating that conversion to the
>trainable representation changes the effective weight calculation.
></pre>
>
> <code>[comfy/weight_adapter/lora.py[16-20]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L16-L20)</code>
> <code>[comfy/weight_adapter/lora.py[42-52]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L42-L52)</code>
> <code>[comfy/weight_adapter/lora.py[151-188]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L151-L188)</code>
> <code>[comfy/weight_adapter/lora.py[15-52]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L15-L52)</code>
> <code>[comfy/weight_adapter/lora.py[173-185]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L173-L185)</code>
> <code>[comfy/weight_adapter/base.py[62-91]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/base.py/#L62-L91)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Trainable conversion drops loaded DoRA scale and reshape metadata, so resumed adapters no longer calculate the same weight update as inference and may save changed adapter state.
>
>## Fix Focus Areas
>- comfy/weight_adapter/lora.py[15-52]
>- comfy/weight_adapter/lora.py[151-188]
>- comfy/weight_adapter/base.py[62-91]
>
>## Recommended Fix
>Store `dora_scale` as an appropriate parameter or buffer and preserve `reshape` in the trainable adapter. Apply reshape and the same DoRA normalization semantics used by the inference adapter when producing the wrapped weight, include the required metadata in the returned training state dictionary, and add a resume test that compares the converted adapter’s initial output with the loaded adapter’s output.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
</details>
<br/>
<img src="https://img.shields.io/badge/Medium-634FD1?style=flat-square" height="20px" alt="Remediation recommended">
<details>
<summary> 7. Equal seeds produce different training <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TrainLoraNode.train</i></b> seeds a local generator that is never passed to any random operation. Dataset
>selection, adapter initialization, and sigma sampling use global random state, so identical inputs
>and seed values can produce different learned adapters.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R393-395]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR393-R395)</code>
>
>```diff
>+ lora_sd = {}
>+ generator = torch.Generator()
>+ generator.manual_seed(seed)
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The local generator is only seeded and never referenced again, while <b><i>torch.randperm</i></b>, <b><i>torch.rand</i></b>,
>and the adapter's initialization functions are invoked without it.
></pre>
>
> <code>[comfy_extras/nodes_train.py[381-395]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L381-L395)</code>
> <code>[comfy_extras/nodes_train.py[503-510]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L503-L510)</code>
> <code>[comfy/weight_adapter/lora.py[65-75]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy/weight_adapter/lora.py/#L65-L75)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The advertised training seed does not control several random operations that affect the result.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[381-395]
>- comfy_extras/nodes_train.py[503-510]
>- comfy/weight_adapter/lora.py[65-75]
>
>## Recommended Fix
>Create the seeded generator on the appropriate device and pass it to batch permutation, sigma sampling, and LoRA initialization. If an initializer cannot accept a generator directly, initialize the factors with generator-aware tensor operations or isolate and restore RNG state.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 8. Default adapter precision is ignored <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>TrainLoraNode.INPUT_TYPES</i></b> offers <b><i>bf16</i></b> and <b><i>fp32</i></b> for <b><i>lora_dtype</i></b> but declares the unrecognized
>value <b><i>bf32</i></b> as its default. <b><i>string_to_torch_dtype()</i></b> therefore returns <b><i>None</i></b>, which reaches the
>train adapters’ and output tensors’ <b><i>.to()</i></b> calls during default-workflow training setup instead of
>requesting an advertised precision conversion.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R344-347]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR344-R347)</code>
>
>```diff
>+ "lora_dtype": (
>+ ["bf16", "fp32"],
>+ {"default": "bf32", "tooltip": "The dtype to use for lora."},
>+ ),
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The node schema declares <b><i>bf32</i></b> as the default even though its selectable values are only <b><i>bf16</i></b> and
><b><i>fp32</i></b>, while <b><i>string_to_torch_dtype()</i></b> recognizes only <b><i>fp32</i></b>, <b><i>fp16</i></b>, and <b><i>bf16</i></b>. The resulting
>conversion value is passed directly to the adapter and output tensor <b><i>.to()</i></b> calls, demonstrating
>that the invalid default propagates into training setup.
></pre>
>
> <code>[comfy_extras/nodes_train.py[340-347]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L340-L347)</code>
> <code>[comfy_extras/nodes_train.py[388-390]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L388-L390)</code>
> <code>[comfy_extras/nodes_train.py[430-436]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L430-L436)</code>
> <code>[node_helpers.py[46-53]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/node_helpers.py/#L46-L53)</code>
> <code>[comfy_extras/nodes_train.py[340-346]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L340-L346)</code>
> <code>[comfy_extras/nodes_train.py[387-390]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L387-L390)</code>
> <code>[node_helpers.py[39-45]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/node_helpers.py/#L39-L45)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The default `lora_dtype` is neither selectable nor recognized by the dtype conversion helper, so it converts to `None` and is passed to PyTorch `.to()` calls during training setup.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[340-347]
>- comfy_extras/nodes_train.py[388-390]
>- node_helpers.py[46-53]
>
>## Recommended Fix
>Change the default to `bf16` or `fp32`, matching the intended advertised precision. Validate that dtype conversion does not return `None` before converting adapters or output tensors, and raise an explicit error for unknown dtype names rather than silently leaving tensors unchanged.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details>
<summary> 9. One-step loss graphs always fail <code>🐞 Bug</code> <code>☼ Reliability</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>LossGraphNode.plot_loss</i></b> divides every loss delta by <b><i>max_loss - min_loss</i></b> without handling an
>equal minimum and maximum. A valid one-step training run, or any run with constant losses, produces
>a zero denominator before the graph can be written.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R637-638]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR637-R638)</code>
>
>```diff
>+ min_loss, max_loss = min(loss_values), max(loss_values)
>+ scaled_loss = [(l - min_loss) / (max_loss - min_loss) for l in loss_values]
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The training input explicitly permits <b><i>steps=1</i></b>, which produces a single loss value whose minimum
>equals its maximum, while the plotting code uses that zero difference as the normalization divisor
>without a guard.
></pre>
>
> <code>[comfy_extras/nodes_train.py[289-296]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L289-L296)</code>
> <code>[comfy_extras/nodes_train.py[487-490]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L487-L490)</code>
> <code>[comfy_extras/nodes_train.py[637-643]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L637-L643)</code>
> <code>[comfy_extras/nodes_train.py[627-647]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L627-L647)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>Loss plotting divides by zero whenever all recorded losses have the same value, including every valid one-step training run, preventing the graph output node from completing.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[289-296]
>- comfy_extras/nodes_train.py[627-647]
>
>## Recommended Fix
>Handle empty and constant loss lists explicitly. When `max_loss == min_loss`, use a fixed plotted value such as 0.5 or another center/baseline for all points instead of normalizing by the zero range, and calculate horizontal positions so a single point remains valid.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
<details><summary><ins><strong>View medium (1)</strong></ins></summary><br/>
<details>
<summary> 10. The image-set loader is unavailable <code>🐞 Bug</code> <code>≡ Correctness</code></summary>
<br/>
> <details open>
><summary>Description</summary>
><br/>
>
><pre>
><b><i>LoadImageSetNode</i></b> defines a complete upload-based image loader and UI contract but is omitted from
><b><i>NODE_CLASS_MAPPINGS</i></b>. Because the server registers only the folder-based loader and other training
>nodes, users cannot add or instantiate this image-upload batch loader in workflows.
></pre>
></details>
> <details>
><summary>Code</summary>
><br/>
>
><code>[comfy_extras/nodes_train.py[R697-703]](https://github.com/drape-io/crbench-qodo-2026-09/pull/105/files#diff-f33558267a1f3ac449e3406f094e1da86b02aeaba19a5bb74853cb62013109ceR697-R703)</code>
>
>```diff
>+NODE_CLASS_MAPPINGS = {
>+ "TrainLoraNode": TrainLoraNode,
>+ "SaveLoRANode": SaveLoRA,
>+ "LoraModelLoader": LoraModelLoader,
>+ "LoadImageSetFromFolderNode": LoadImageSetFromFolderNode,
>+ "LossGraphNode": LossGraphNode,
>+}
>```
></details>
> <details>
><summary>Evidence</summary>
><br/>
>
><pre>
>The file defines <b><i>LoadImageSetNode</i></b> with executable loading behavior and UI inputs, while the
>registry at the end of the same module registers only the folder-based loader and other training
>nodes, with no entry for <b><i>LoadImageSetNode</i></b>.
></pre>
>
> <code>[comfy_extras/nodes_train.py[125-172]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L125-L172)</code>
> <code>[comfy_extras/nodes_train.py[697-711]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L697-L711)</code>
> <code>[comfy_extras/nodes_train.py[697-710]](https://github.com/drape-io/crbench-qodo-2026-09/blob/160a24ba05007adf9ac80c974d933e6fb478ccd2/comfy_extras/nodes_train.py/#L697-L710)</code>
></details>
> <details>
><summary>Agent prompt</summary>
><br/>
>
>```
>The issue below was found during a code review. Follow the provided context and guidance below and implement a solution
>
>## Issue description
>The multi-file, upload-based image-set loader is implemented but not exported through the node mappings, so the application cannot expose or instantiate it in workflows.
>
>## Fix Focus Areas
>- comfy_extras/nodes_train.py[125-172]
>- comfy_extras/nodes_train.py[697-710]
>
>## Recommended Fix
>If the node is intended to ship, add `LoadImageSetNode` to `NODE_CLASS_MAPPINGS` and add its display name to `NODE_DISPLAY_NAME_MAPPINGS`; otherwise, remove the unreachable implementation.
>```
> <code>ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools</code>
></details>
<hr/>
</details>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-context:start -->
<details><summary><strong>Context sources</strong></summary>
<div>Review mode: <code>🧠 Deep</code>: This introduces substantial new training, LoRA adapter, checkpointing, file-loading, and node-integration logic across multiple independent paths, creating a dense set of easy-to-miss behavioral defects with broad runtime impact.</div>
<!-- qodo-context:end -->
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:start -->
<details>
<summary><strong>Tip of the day</strong></summary>
<br/>
<pre>💡 Did you know, you can add REVIEW.md to your repo root and Qodo follows it on every PR</pre>
<a href="https://docs.qodo.ai/tips-and-tricks">More tips ↗</a> | <a href="https://app.qodo.ai/configurations?tab=display-preferences">Customize Qodo ↗</a> | <a href="https://docs.qodo.ai">Qodo docs ↗</a>
</details>
<img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider">
<!-- qodo-daily-tip:end -->
<!-- https://github.com/drape-io/crbench-qodo-2026-09/commit/160a24ba05007adf9ac80c974d933e6fb478ccd2 -->
<a href="https://www.qodo.ai"><img src="https://www.qodo.ai/wp-content/uploads/2025/03/qodo-logo.svg" width="80" alt="Qodo Logo"></a>