-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix-exception-chaining
- Loading branch information
Showing
23 changed files
with
247 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from pytorch_lightning.distributed.dist import LightningDistributed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import io | ||
import torch | ||
from typing import Any | ||
from torch import distributed as torch_distrib | ||
|
||
|
||
class LightningDistributed: | ||
|
||
def __init__(self, rank=None, device=None): | ||
self.rank = rank | ||
self.device = device | ||
|
||
def broadcast(self, obj: Any): | ||
if self.rank == 0: | ||
self._emit(obj) | ||
else: | ||
obj = self._receive() | ||
return obj | ||
|
||
def _emit(self, obj): | ||
buffer = io.BytesIO() | ||
torch.save(obj, buffer) | ||
data = bytearray(buffer.getbuffer()) | ||
length_tensor = torch.tensor([len(data)]).long().to(self.device) | ||
length_tensor = torch_distrib.broadcast(length_tensor, src=0) | ||
data_tensor = torch.ByteTensor(data).to(self.device) | ||
data_tensor = torch_distrib.broadcast(data_tensor, src=0) | ||
|
||
def _receive(self): | ||
length_tensor = torch.tensor([0]).long().to(self.device) | ||
torch_distrib.broadcast(length_tensor, src=0) | ||
data_tensor = torch.empty([length_tensor.item()], dtype=torch.uint8).to(self.device) | ||
torch_distrib.broadcast(data_tensor, src=0) | ||
buffer = io.BytesIO(data_tensor.cpu().numpy()) | ||
obj = torch.load(buffer) | ||
return obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.