Skip to content

Commit

Permalink
0.9.12
Browse files Browse the repository at this point in the history
  • Loading branch information
divideconcept authored Oct 11, 2022
1 parent 6815d55 commit ff78b5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions torchstudio/datasets/randomgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RandomGenerator(Dataset):
Size of the dataset (number of samples)
tensors:
A list of tuples defining tensor properties: shape, type, range
All properties are optionals. Defaults are null, float, [0,1]
All properties are optionals. Defaults are null, torch.float, [0,1]
"""

def __init__(self, size:int=256, tensors=[(3,64,64), (int,[0,9])]):
Expand All @@ -29,12 +29,12 @@ def __getitem__(self, idx):
sample = []
for properties in self.tensors:
shape=[]
dtype=float
dtype=torch.float
drange=[0,1]
for property in properties:
if type(property)==int:
shape.append(property)
elif inspect.isclass(property):
elif type(property)==type or type(property)==torch.dtype:
dtype=property
elif type(property) is list:
drange=property
Expand Down
7 changes: 6 additions & 1 deletion torchstudio/modeltrain.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ def deepcopy_cpu(value):
scaler = torch.cuda.amp.GradScaler()
if mode=='BF16':
os.environ["TORCH_CUDNN_V8_API_ENABLED"] = "1" #https://discuss.pytorch.org/t/bfloat16-has-worse-performance-than-float16-for-conv2d/154373
train_type=None
if mode=='FP16':
train_type=torch.float16
if mode=='BF16':
train_type=torch.bfloat16
print("Training... epoch "+str(scheduler.last_epoch)+"\n", file=sys.stderr)

if msg_type == 'TrainOneEpoch' and modules_valid:
Expand All @@ -252,7 +257,7 @@ def deepcopy_cpu(value):
targets = [tensors[i].to(device) for i in output_tensors_id]
optimizer.zero_grad()

with torch.autocast(device_type='cuda' if 'cuda' in device_id else 'cpu', dtype=torch.bfloat16 if mode=='BF16' else torch.float16, enabled=True if '16' in mode else False):
with torch.autocast(device_type='cuda' if 'cuda' in device_id else 'cpu', dtype=train_type, enabled=True if train_type else False):
outputs = model(*inputs)
outputs = outputs if type(outputs) is not torch.Tensor else [outputs]
loss = 0
Expand Down

0 comments on commit ff78b5e

Please sign in to comment.