From c54de3468182964b8f03240454d8dd3585e7eda2 Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Thu, 12 Feb 2026 00:03:24 +0530 Subject: [PATCH] Fix loop variable shadowing in validation that corrupts sample iteration In the validate() method, the inner loop `for i, ... in enumerate(validation_artifacts)` shadows the outer loop variable `for i in range(num_validation_samples)`. After the inner loop completes, `i` holds the last enumerate index instead of the outer sample index. This causes subsequent validation samples to load incorrect prompts, images, and videos, and breaks DeepSpeed multi-GPU process distribution logic that depends on `i`. Renamed the inner variable to `artifact_idx` to prevent shadowing. --- finetune/trainer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/finetune/trainer.py b/finetune/trainer.py index 5746fee..056181e 100644 --- a/finetune/trainer.py +++ b/finetune/trainer.py @@ -588,9 +588,9 @@ class Trainer: "image": {"type": "image", "value": image}, "video": {"type": "video", "value": video}, } - for i, (artifact_type, artifact_value) in enumerate(validation_artifacts): + for artifact_idx, (artifact_type, artifact_value) in enumerate(validation_artifacts): artifacts.update( - {f"artifact_{i}": {"type": artifact_type, "value": artifact_value}} + {f"artifact_{artifact_idx}": {"type": artifact_type, "value": artifact_value}} ) logger.debug( f"Validation artifacts on process {accelerator.process_index}: {list(artifacts.keys())}",