kohya-ss / kohya-ss/sd-scripts

TypeError in FluxTrainAndValidateLoop: sample_images() takes 4 positional arguments but 10 were given

Open
#2,099 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
7.2k
Forks
1.2k
Avg merge
11m
Merged PRs (30d)
2

Description

I'm counted a TypeError when using the **FluxTrainAndValidateLoop** node with **FluxTrainValidationSettings**.
The error occurs during the training flux lora model with validation loop process.

**Error message:**
```
[2025-05-26 20:49:00.857] running training
[2025-05-26 20:49:00.857] num train images * repeats: 40
[2025-05-26 20:49:00.857] num reg images: 0
[2025-05-26 20:49:00.857] num batches per epoch: 40
[2025-05-26 20:49:00.858] num epochs: 250
[2025-05-26 20:49:00.858] batch size per device: 1
[2025-05-26 20:49:00.858] gradient accumulation steps: 1
[2025-05-26 20:49:00.858] total optimization steps: 10000
[2025-05-26 20:49:23.883] 2025-05-26 20:49:23 INFO text_encoder is not needed for training. deleting to save memory. train_network.py:1107
[2025-05-26 20:49:24.219] 2025-05-26 20:49:24 INFO unet dtype: torch.bfloat16, device: cuda:0 train_network.py:1124
[2025-05-26 21:09:51.945] 2025-05-26 21:09:51 ERROR !!! Exception during processing !!! FluxNetworkTrainer.sample_images() takes 4 positional execution.py:396
arguments but 10 were given
[2025-05-26 21:09:51.949] ERROR Traceback (most recent call last): execution.py:397
File "/data1/choi_hyunseok/ComfyUI/execution.py", line 327, in execute
output_data, output_ui, has_subgraph = get_output_data(obj, input_data_all,
execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data1/choi_hyunseok/ComfyUI/execution.py", line 202, in get_output_data
return_values = _map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True,
execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data1/choi_hyunseok/ComfyUI/execution.py", line 174, in _map_node_over_list
process_inputs(input_dict, i)
File "/data1/choi_hyunseok/ComfyUI/execution.py", line 163, in process_inputs
results.append(getattr(obj, func)(**inputs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data1/choi_hyunseok/ComfyUI/custom_nodes/comfyui-fluxtrainer/nodes.py", line 961, in
train
self.validate(network_trainer, validation_settings)
File "/data1/choi_hyunseok/ComfyUI/custom_nodes/comfyui-fluxtrainer/nodes.py", line 990, in
validate
image_tensors = network_trainer.sample_images(*params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: FluxNetworkTrainer.sample_images() takes 4 positional arguments but 10 were given
```

**What I solved:**
The issue appears to be a mismatch between the parameter definitions in different files:

1. In `flux_train_network_comfy.py`, the `sample_images()` method is defined to take 3 parameters (plus self):
```python
def sample_images(self, epoch, global_step, validation_settings):
```

2. However, in `nodes.py`, the `validate()` method is trying to pass 9 parameters (plus self):
```python
class FLuxTrainAndValidateLoop:

...

def validate(self, network_trainer, validation_settings=None):
params = (
network_trainer.accelerator,
network_trainer.args,
network_trainer.current_epoch.value,
network_trainer.global_step,
network_trainer.unet,
network_trainer.vae,
network_trainer.text_encoder,
network_trainer.sample_prompts_te_outputs,
validation_settings
)
network_trainer.optimizer_eval_fn()
image_tensors = network_trainer.sample_images(*params)
network_trainer.optimizer_train_fn()
print("Validating at step:", network_trainer.global_step)
```

3. This should be modified to:
```python
class FLuxTrainAndValidateLoop:

...

def validate(self, network_trainer, validation_settings=None):
network_trainer.optimizer_eval_fn()
image_tensors = network_trainer.sample_images(network_trainer.current_epoch.value, network_trainer.global_step, validation_settings)
network_trainer.optimizer_train_fn()
print("Validating at step:", network_trainer.global_step)
```

I think this issue occurred with difference between flux_train_network.py and flux_train_network_comfy.py versions.

And now I'm working well on the flux lora train pipeline. Thanks.

![Image](https://github.com/user-attachments/assets/c4fc4a83-bc78-4ceb-9fe0-e1bd7eb2d040)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in custom_nodes/comfyui-fluxtrainer/nodes.py at FLuxTrainAndValidateLoop.validate, then compare its sample_images call with the method signature in flux_train_network_comfy.py. Run the FluxTrainAndValidateLoop with FluxTrainValidationSettings and confirm validation completes without the positional-argument TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.