LossGraphNode raises ZeroDivisionError for a single-step training run
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
### Custom Node Testing
- [x] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)
### Expected Behavior
A constant or single-point loss series should render without raising. A
one-step training run is a cheap and useful way to validate a training
configuration before committing to a long run.
### Actual Behavior
`LossGraphNode` normalizes the loss curve without guarding against the case
where all loss values are equal (`comfy_extras/nodes_train.py`, line ~1618):
```python
scaled_loss = [(l - min_loss) / (max_loss - min_loss) for l in loss_values]
```
With `steps=1` there is exactly one loss value, so `min_loss == max_loss` by
definition and the division raises `ZeroDivisionError`. The same would occur
for any run in which every recorded loss value happens to be identical.
Training itself completes normally and the LoRA is produced; the workflow then
fails at the graph node.
### Steps to Reproduce
Any `TrainLoraNode` graph with `steps=1` and a `LossGraphNode` connected to the
`loss_map` output. Model and dataset are irrelevant.
### Debug Logs
```powershell
Training LoRA: 100%|##########| 1/1 [00:11<00:00, 11.14s/it, loss=3.1607, bucket=3]
!!! Exception during processing !!! float division by zero
Traceback (most recent call last):
...
File "comfy_extras/nodes_train.py", line 1618, in execute
scaled_loss = [(l - min_loss) / (max_loss - min_loss) for l in loss_values]
~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero
```
### Other
**Environment**
- ComfyUI commit `4da9e2dbead52fc1e68beae33fe3d7ad63b63241`, base tag `v0.33.3`
- `comfy_extras/nodes_train.py` as of commit `d0fec2ef` (2026-07-21)
- PyTorch 2.10.0, macOS 26.6.2, Apple Silicon, device MPS
**Suggested fix**
```python
if max_loss > min_loss:
scaled_loss = [(l - min_loss) / (max_loss - min_loss) for l in loss_values]
else:
scaled_loss = [0.0] * len(loss_values)
```
Happy to open a PR if that would be useful.
Contributor guide
Research direction
Start in comfy_extras/nodes_train.py around LossGraphNode.execute at line 1618, where the loss values are normalized. Reproduce with a TrainLoraNode graph using steps=1 and a connected LossGraphNode, then verify that constant or single-point loss data renders without ZeroDivisionError and that the training workflow completes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100