Skip to content

Fix PyTorch Lightning warning when using torchCPUTrainer#391

Merged
Demirrr merged 3 commits intodevelopfrom
fix/better-error-missing-path-single-kg
Mar 11, 2026
Merged

Fix PyTorch Lightning warning when using torchCPUTrainer#391
Demirrr merged 3 commits intodevelopfrom
fix/better-error-missing-path-single-kg

Conversation

@Demirrr
Copy link
Copy Markdown
Member

@Demirrr Demirrr commented Mar 10, 2026

This PR fixes the PyTorch Lightning warning that appeared when using custom trainers like torchCPUTrainer.

Changes:

  • Modified dicee/models/base_model.py to check for _trainer attribute before calling self.log()
  • Modified dicee/models/transformers.py with the same fix
  • Prevents RuntimeError when accessing the trainer property on models not attached to PyTorch Lightning trainer

Issue Fixed:
Previously, when using torchCPUTrainer, the following warning appeared:

/home/cdemir/anaconda3/envs/dice/lib/python3.11/site-packages/lightning/pytorch/core/module.py:451: You are trying to `self.log()` but the `self.trainer` reference is not registered on the model yet. This is most likely because the model hasn't been passed to the `Trainer`

Testing:
Tested with:

dicee --dataset_dir "KGs/UMLS" --trainer "torchCPUTrainer" --scoring_technique KvsAll --model "Keci" --eval_model "train_val_test"

The warning no longer appears and training completes successfully.

Demirrr added 3 commits March 10, 2026 15:57
- Replace silent failure (print + return None) with proper FileNotFoundError
- Provide clear error message when the specified file does not exist
- Bump library version
- Check for _trainer attribute before calling self.log() to avoid RuntimeError
- Prevents warning: 'self.trainer reference is not registered on the model yet'
- Fixes issue when using custom trainers that don't attach PyTorch Lightning trainer
- Add random seed initialization (Python, NumPy, PyTorch) at module and test level
- Adjust test_all_vs_all assertion bounds to reflect reproducible behavior (0.15-0.25)
- Set deterministic behavior for PyTorch backends
- All 4 tests now pass consistently
@Demirrr Demirrr merged commit f38d9b7 into develop Mar 11, 2026
3 checks passed
@Demirrr Demirrr deleted the fix/better-error-missing-path-single-kg branch March 11, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant