-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revamp RunContext and add gpu_name (#143)
- Loading branch information
1 parent
4cef656
commit 38e65a5
Showing
3 changed files
with
33 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,35 @@ | ||
# get contextual information about a training run | ||
|
||
from dataclasses import dataclass | ||
import os | ||
|
||
import torch | ||
import transformers | ||
|
||
import delphi | ||
|
||
|
||
def get_auto_device_str() -> str: | ||
if torch.cuda.is_available(): | ||
return "cuda" | ||
if torch.backends.mps.is_available(): | ||
return "mps" | ||
return "cpu" | ||
|
||
|
||
@dataclass | ||
class RunContext: | ||
device: torch.device | ||
torch_version: str | ||
delphi_version: str | ||
transformers_version: str | ||
os: str | ||
def __init__(self, device_str: str): | ||
if device_str == "auto": | ||
device_str = get_auto_device_str() | ||
self.device = torch.device(device_str) | ||
if self.device.type == "cuda": | ||
assert torch.cuda.is_available() | ||
self.gpu_name = torch.cuda.get_device_name(self.device) | ||
elif self.device.type == "mps": | ||
assert torch.backends.mps.is_available() | ||
self.torch_version = torch.__version__ | ||
self.delphi_version = delphi.__version__ | ||
self.transformers_version = transformers.__version__ | ||
self.os = os.uname().version | ||
|
||
def asdict(self) -> dict: | ||
asdict = self.__dict__.copy() | ||
asdict["device"] = str(self.device) | ||
return asdict |
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