""" Training Tokenizer Fix Plugin Fixes: 'TrainingResearcher' object has no attribute 'tokenizer' Problem: TrainingResearcher wraps BackgroundResearcher but doesn't expose the tokenizer attribute needed by LoRADataset during training. Solution: Add tokenizer property that delegates to EVE's tokenizer. """ def register(orchestrator): """Register the tokenizer fix plugin.""" eve = orchestrator.eve print("🔧 Training Tokenizer Fix Plugin loaded") # Find all TrainingResearchers training_researchers = [ r for r in eve.researchers if r.__class__.__name__ == 'TrainingResearcher' ] if not training_researchers: print(" ⚠️ No TrainingResearchers found - plugin not needed") return # Add tokenizer property to each TrainingResearcher for researcher in training_researchers: # Add tokenizer as property that delegates to EVE's tokenizer researcher.tokenizer = eve.tokenizer print(f" ✅ Fixed tokenizer access for {len(training_researchers)} TrainingResearchers") # Also fix the LoRADataset issue by patching the class try: from torch.utils.data import Dataset # Get reference to LoRADataset class import sys if hasattr(sys.modules['__main__'], 'LoRADataset'): LoRADataset = sys.modules['__main__'].LoRADataset # Store original __getitem__ original_getitem = LoRADataset.__getitem__ def fixed_getitem(self, idx): """Fixed __getitem__ that handles both data formats safely.""" item = self.data[idx] # Safely extract text fields user_text = '' assistant_text = '' # Try multiple possible keys if isinstance(item, dict): # For training data format user_text = item.get('input', item.get('topic', '')) assistant_text = item.get('target', item.get('content', '')) # Handle None values if user_text is None: user_text = '' if assistant_text is None: assistant_text = '' # Ensure strings user_text = str(user_text) assistant_text = str(assistant_text) # Build prompt text = f"User: {user_text}\nAssistant: {assistant_text}" else: # Fallback for unexpected format text = str(item) # Tokenize encodings = self.tokenizer( text, truncation=True, max_length=self.max_length, padding="max_length", return_tensors="pt" ) return { "input_ids": encodings["input_ids"].squeeze(), "attention_mask": encodings["attention_mask"].squeeze(), "labels": encodings["input_ids"].squeeze() } # Monkey-patch the method LoRADataset.__getitem__ = fixed_getitem print(" ✅ Patched LoRADataset.__getitem__ for safer data handling") except Exception as e: print(f" ⚠️ Could not patch LoRADataset: {e}") print(" 🎯 Plugin ready - training should work now\n")