Skip to content

Commit 8fa5328

Browse files
committed
fix: add comprehensive validation for ValidationInputs and ValidationLabels
The previous validation only checked for null when ValidateAfterEpoch was true. Now the validation is much stricter: - If either ValidationInputs or ValidationLabels is non-null, both must be non-null - Both arrays must have Length > 0 (not empty) - Both arrays must have the same Length - Clear error messages indicate which array is missing/empty or show length mismatch This prevents runtime errors from empty arrays or mismatched validation data.
1 parent 6b30c8c commit 8fa5328

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/Models/Options/KnowledgeDistillationOptions.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,30 @@ public void Validate()
398398
if (SelfDistillationGenerations < 1)
399399
throw new ArgumentException("SelfDistillationGenerations must be at least 1", nameof(SelfDistillationGenerations));
400400

401-
if (ValidateAfterEpoch && (ValidationInputs == null || ValidationLabels == null))
401+
// Validate validation data consistency
402+
if (ValidationInputs != null || ValidationLabels != null)
403+
{
404+
// If either is provided, both must be provided
405+
if (ValidationInputs == null)
406+
throw new ArgumentNullException(nameof(ValidationInputs), "ValidationLabels is provided but ValidationInputs is null");
407+
if (ValidationLabels == null)
408+
throw new ArgumentNullException(nameof(ValidationLabels), "ValidationInputs is provided but ValidationLabels is null");
409+
410+
// Both must be non-empty
411+
if (ValidationInputs.Length == 0)
412+
throw new ArgumentException("ValidationInputs cannot be empty", nameof(ValidationInputs));
413+
if (ValidationLabels.Length == 0)
414+
throw new ArgumentException("ValidationLabels cannot be empty", nameof(ValidationLabels));
415+
416+
// Both must have the same length
417+
if (ValidationInputs.Length != ValidationLabels.Length)
418+
throw new ArgumentException(
419+
$"ValidationInputs and ValidationLabels must have the same length. " +
420+
$"ValidationInputs.Length = {ValidationInputs.Length}, ValidationLabels.Length = {ValidationLabels.Length}");
421+
}
422+
423+
// If validation is enabled, validation data must be provided
424+
if (ValidateAfterEpoch && ValidationInputs == null)
402425
throw new ArgumentException("Validation data must be provided when ValidateAfterEpoch is true");
403426
}
404427
}

0 commit comments

Comments
 (0)