-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DistNetworkError when using multiprocessing_context parameter in pytorch dataloader #20516
Comments
A week has passed, where are you? @lantiga |
🎄 |
Hey @forestbat, thanks for your patience. The issue here is that calling import torch
import torch.nn as nn
import torch.optim as optim
from torch.utils.data import DataLoader
from torch.utils.data import TensorDataset
import lightning
class LinearModel(nn.Module):
def __init__(self):
super().__init__()
self.linear = nn.Linear(10, 2)
def forward(self, x):
return self.linear(x)
if __name__ == '__main__':
x = torch.randn(100, 10)
y = torch.rand(100, 2)
dataset = TensorDataset(x, y)
fabric = lightning.Fabric(devices=[0, 2], num_nodes=1, strategy='ddp')
fabric.launch()
# crashed because of multiprocessing_context='spawn', 'forkserver' has same problem
train_loader = fabric.setup_dataloaders(DataLoader(dataset, batch_size=10, shuffle=True,
num_workers=1, multiprocessing_context='spawn'))
model = LinearModel()
crit = nn.MSELoss()
model, optimizer = fabric.setup(model, optim.Adam(model.parameters(), lr=0.01))
for epoch in range(0, 10):
print(f'Epoch {epoch}')
for xs, ys in train_loader:
output = model(xs)
loss = crit(output, ys)
fabric.backward(loss)
optimizer.step() |
Thanks for your reply,now I‘m fighting with mysterious deadlock but I will probably open a new issue. |
Bug description
Because of some special reasons I want to use
spawn
method to create worker inDataLoader
of Pytorch, but it crashed with this error in topic.Port 55733 is listened by training processes before so it will crash. But I want to know, why port will be bind repeatedly when
multiprocessing_context
isspawn
?Update: when I use #pytorch only, the problem disappeared. It occurs in lightning.Fabric.
Hope for your reply.
What version are you seeing the problem on?
v2.4
How to reproduce the bug
Error messages and logs
Environment
Current environment
More info
No response
The text was updated successfully, but these errors were encountered: