Hi ptrblck i am facing an error while importing autocast.
My code is as follows:
from tqdm import tqdm_notebook, tnrange
import torch.nn.functional as F
import torch
from torch.cuda.amp import autocast 
class Train:
  def __init__(self, model, dataloader, optimizer, stats, scheduler=None, L1lambda = 0,criterion=None,use_amp=True):
    self.model = model
    self.dataloader = dataloader
    self.optimizer = optimizer
    self.scheduler = scheduler
    self.stats = stats
    self.L1lambda = L1lambda
    self.criterion=criterion
    self.loss1=0.0
    self.loss2=0.0
    self.loss=0.0
    self.use_amp=True
  def run(self):
    self.model.train()
    torch.cuda.empty_cache()
    pbar = tqdm_notebook(self.dataloader)
    for data1,data2,target1,target2 in pbar:
      # get samples
      data1,data2 = data1.to(self.model.device), data2.to(self.model.device)
      target1, target2 = target2.to(self.model.device), target2.to(self.model.device)
      self.optimizer.zero_grad()
      with autocast():
        output1,output2 = self.model(data1,data2)
        #print(target.shape)
        target1=target1.unsqueeze(1)
        target2=target2.unsqueeze(1)
        self.loss1=self.criterion[0](output1.float(), target1.half())
        self.loss2=self.criterion[1](output2.float(), target2.half())
        #print("loss1 {}".format(self.loss1))
        #print("loss2 {}".format(self.loss2))
        self.loss=(self.loss1+self.loss2)/2.0
    
      # In PyTorch, we need to set the gradients to zero before starting to do backpropragation because PyTorch accumulates the gradients on subsequent backward passes. 
      # Because of this, when you start your training loop, ideally you should zero out the gradients so that you do the parameter update correctly.

      # Predict
      
      #Implementing L1 regularization
      #print(self.loss)
      if self.L1lambda > 0:
        reg_loss = 0.
        for param in self.model.parameters():
          reg_loss += torch.sum(param.abs())
        self.loss += self.L1lambda * reg_loss

      #print(self.loss)
      # Backpropagation
      self.loss.backward()
      #self.loss.backward()
      #self.optimizer.step()
Error is as follows:
ImportError: cannot import name 'autocast'

'''