renpas22 commited on
Commit ·
3024a91
1
Parent(s): d29f3e7
Fix ReasoningChain dataclass - add image field and defaults, fix collate function
Browse files
src/reasoning/step_data.py
CHANGED
|
@@ -168,6 +168,7 @@ class ReasoningChain:
|
|
| 168 |
Attributes:
|
| 169 |
chain_id: Unique identifier for this reasoning chain
|
| 170 |
image_path: Path to the input image
|
|
|
|
| 171 |
prompt: Input text prompt/question
|
| 172 |
steps: Ordered list of reasoning steps
|
| 173 |
final_answer: Final output/answer
|
|
@@ -176,10 +177,11 @@ class ReasoningChain:
|
|
| 176 |
metadata: Additional chain-level information
|
| 177 |
"""
|
| 178 |
chain_id: str
|
| 179 |
-
image_path: str
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
| 183 |
total_reward: float = 0.0
|
| 184 |
is_correct: bool = False
|
| 185 |
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
|
|
| 168 |
Attributes:
|
| 169 |
chain_id: Unique identifier for this reasoning chain
|
| 170 |
image_path: Path to the input image
|
| 171 |
+
image: PIL Image object (for streaming datasets)
|
| 172 |
prompt: Input text prompt/question
|
| 173 |
steps: Ordered list of reasoning steps
|
| 174 |
final_answer: Final output/answer
|
|
|
|
| 177 |
metadata: Additional chain-level information
|
| 178 |
"""
|
| 179 |
chain_id: str
|
| 180 |
+
image_path: str = None
|
| 181 |
+
image: Any = None
|
| 182 |
+
prompt: str = ""
|
| 183 |
+
steps: List[ReasoningStep] = field(default_factory=list)
|
| 184 |
+
final_answer: str = ""
|
| 185 |
total_reward: float = 0.0
|
| 186 |
is_correct: bool = False
|
| 187 |
metadata: Dict[str, Any] = field(default_factory=dict)
|
src/reasoning/step_level_cot.py
CHANGED
|
@@ -376,14 +376,20 @@ class StepLevelCoTTrainer:
|
|
| 376 |
# Filter out None samples
|
| 377 |
batch = [b for b in batch if b is not None]
|
| 378 |
if not batch:
|
| 379 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
|
| 381 |
# Extract text and images
|
| 382 |
texts = []
|
| 383 |
images = []
|
| 384 |
for chain in batch:
|
| 385 |
# Format: question + reasoning steps + answer
|
| 386 |
-
text = f"Question: {chain.
|
| 387 |
text += f"{SPECIAL_TOKENS['reasoning_start']}\n"
|
| 388 |
for step in chain.steps:
|
| 389 |
text += f"{SPECIAL_TOKENS['step_start']}{step.content}{SPECIAL_TOKENS['step_end']}\n"
|
|
|
|
| 376 |
# Filter out None samples
|
| 377 |
batch = [b for b in batch if b is not None]
|
| 378 |
if not batch:
|
| 379 |
+
# Return empty batch structure instead of None
|
| 380 |
+
# This prevents Accelerate DataLoader from crashing
|
| 381 |
+
return {
|
| 382 |
+
'input_ids': torch.tensor([[]]),
|
| 383 |
+
'attention_mask': torch.tensor([[]]),
|
| 384 |
+
'labels': torch.tensor([[]]),
|
| 385 |
+
}
|
| 386 |
|
| 387 |
# Extract text and images
|
| 388 |
texts = []
|
| 389 |
images = []
|
| 390 |
for chain in batch:
|
| 391 |
# Format: question + reasoning steps + answer
|
| 392 |
+
text = f"Question: {chain.prompt}\n"
|
| 393 |
text += f"{SPECIAL_TOKENS['reasoning_start']}\n"
|
| 394 |
for step in chain.steps:
|
| 395 |
text += f"{SPECIAL_TOKENS['step_start']}{step.content}{SPECIAL_TOKENS['step_end']}\n"
|