-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --tf32 device arg for transparent float32 acceleration (#1066)
- --tf32 0|1 bool device (torch.backends.cuda.matmul.allow_tf32) enabling 10-bit precision (19 bit total) transparent float32 acceleration. default true for backward compat with torch < 1.12. allow different --tf32 training continuation - device.init_device called by train, translate, and score - allow torch 1.12 in requirements.txt
- Loading branch information
Showing
10 changed files
with
58 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
torch>=1.10.0,<1.12.0 | ||
torch>=1.10.0,<1.13.0 | ||
pyyaml>=5.1 | ||
numpy>1.16.0,<2.0.0 | ||
sacrebleu>=2.3.0 |
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,25 @@ | ||
import torch | ||
import argparse | ||
from typing import Optional | ||
|
||
def init_device(args: argparse.Namespace, logger=None, local_rank : Optional[int] = None): | ||
""" | ||
return requested torch device, optionally enabling tf32 | ||
:param args "Device Parameters". args.use_cpu will be set if cuda is not available | ||
:param logger optional logger.info(msg) | ||
:param local_rank optional int LOCAL_RANK env for multiple GPU training | ||
""" | ||
if not torch.cuda.is_available(): | ||
if logger is not None: | ||
logger.info("CUDA not available, using cpu") | ||
args.use_cpu = True | ||
device = torch.device('cpu') if args.use_cpu else torch.device('cuda', args.device_id if local_rank is None else local_rank) | ||
if not args.use_cpu: | ||
# Ensure that GPU operations use the correct device by default | ||
torch.cuda.set_device(device) | ||
if args.tf32: | ||
if logger is not None: | ||
logger.info("CUDA: allow tf32 (float32 but with 10 bits precision)") | ||
torch.backends.cuda.matmul.allow_tf32 = True | ||
return device |
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