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.
This commit is contained in:
Mr-Neutr0n 2026-02-12 00:03:24 +05:30
parent 7a1af71545
commit c54de34681

View File

@ -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())}",