-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
loggingRelated to the `LoggerConnector` and `log()`Related to the `LoggerConnector` and `log()`questionFurther information is requestedFurther information is requestedver: 1.9.xver: 2.0.xver: 2.1.x
Description
Bug description
When you call
self.log("integer", 1)
you get the warning:
/Users/adrian/repositories/lightning/src/lightning/pytorch/trainer/connectors/logger_connector/result.py:232: UserWarning: You called
self.log('integer', ...)
in yourtraining_step
but the value needs to be floating point. Converting it to torch.float32.
Is this intentional?
What version are you seeing the problem on?
v1.9, v2.0, master
How to reproduce the bug
import torch
from lightning.pytorch import LightningModule, Trainer
from torch.utils.data import DataLoader, Dataset
class RandomDataset(Dataset):
def __init__(self, size, length):
self.len = length
self.data = torch.randn(length, size)
def __getitem__(self, index):
return self.data[index]
def __len__(self):
return self.len
class BoringModel(LightningModule):
def __init__(self):
super().__init__()
self.layer = torch.nn.Linear(32, 2)
def training_step(self, batch, batch_idx):
loss = self.layer(batch).sum()
self.log("integer", 1)
return {"loss": loss}
def configure_optimizers(self):
return torch.optim.SGD(self.layer.parameters(), lr=0.1)
train_data = DataLoader(RandomDataset(32, 64), batch_size=2)
model = BoringModel()
trainer = Trainer(max_steps=1)
trainer.fit(model, train_data)
Error messages and logs
/Users/adrian/repositories/lightning/src/lightning/pytorch/trainer/connectors/logger_connector/result.py:232: UserWarning: You called
self.log('integer', ...)
in yourtraining_step
but the value needs to be floating point. Converting it to torch.float32.
Environment
Current environment
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0): 1.9+
#- Lightning App Version (e.g., 0.5.2): -
#- PyTorch Version (e.g., 2.0): 2.1
#- Python version (e.g., 3.9): 3.11
#- OS (e.g., Linux): MacOs
#- CUDA/cuDNN version: -
#- GPU models and configuration: -
#- How you installed Lightning(`conda`, `pip`, source): source
#- Running environment of LightningApp (e.g. local, cloud): -
More info
The question was raised here #18723 (comment), I'm not sure if there is a good reason for it.
Metadata
Metadata
Assignees
Labels
loggingRelated to the `LoggerConnector` and `log()`Related to the `LoggerConnector` and `log()`questionFurther information is requestedFurther information is requestedver: 1.9.xver: 2.0.xver: 2.1.x