renpas22 commited on
Commit
d29f3e7
·
1 Parent(s): 9e7779a

Fix None image handling in collate function

Browse files
Files changed (1) hide show
  1. src/reasoning/step_level_cot.py +10 -2
src/reasoning/step_level_cot.py CHANGED
@@ -391,7 +391,11 @@ class StepLevelCoTTrainer:
391
  text += f"Answer: {chain.final_answer}"
392
 
393
  texts.append(text)
394
- images.append(chain.image)
 
 
 
 
395
 
396
  # Tokenize with processor
397
  if hasattr(self.tokenizer, 'tokenizer'):
@@ -401,9 +405,13 @@ class StepLevelCoTTrainer:
401
 
402
  # Use processor for vision-language models
403
  if hasattr(self.tokenizer, '__call__'):
 
 
 
 
404
  inputs = self.tokenizer(
405
  text=texts,
406
- images=images,
407
  return_tensors="pt",
408
  padding=True,
409
  truncation=True,
 
391
  text += f"Answer: {chain.final_answer}"
392
 
393
  texts.append(text)
394
+ # Handle missing images - append None which the processor should handle
395
+ if hasattr(chain, 'image'):
396
+ images.append(chain.image if chain.image is not None else None)
397
+ else:
398
+ images.append(None)
399
 
400
  # Tokenize with processor
401
  if hasattr(self.tokenizer, 'tokenizer'):
 
405
 
406
  # Use processor for vision-language models
407
  if hasattr(self.tokenizer, '__call__'):
408
+ # Filter out None images - if all are None, pass None instead of list
409
+ valid_images = [img for img in images if img is not None]
410
+ images_param = valid_images if valid_images else None
411
+
412
  inputs = self.tokenizer(
413
  text=texts,
414
+ images=images_param,
415
  return_tensors="pt",
416
  padding=True,
417
  truncation=True,