Refer to Getting Started on Aurora for additional information. In particular, you need to set the environment variables that provide access to the proxy host.
Note
The instructions below should be run directly from a compute node.
Explicitly, to request an interactive job (from aurora-uan):
importtorchimportgpytorch# 1. Setup Device (will use GPU if available, else CPU)iftorch.cuda.is_available():device=torch.device('cuda')eliftorch.xpu.is_available():device=torch.device('xpu')else:device=torch.device('cpu')print(f"Using device: {device}")# 2. Define the GP ModelclassSimpleGPModel(gpytorch.models.ExactGP):def__init__(self,train_x,train_y,likelihood):super(SimpleGPModel,self).__init__(train_x,train_y,likelihood)self.mean_module=gpytorch.means.ConstantMean()self.covar_module=gpytorch.kernels.ScaleKernel(gpytorch.kernels.RBFKernel())defforward(self,x):mean_x=self.mean_module(x)covar_x=self.covar_module(x)returngpytorch.distributions.MultivariateNormal(mean_x,covar_x)# 3. Generate synthetic data and move to devicetrain_x=torch.linspace(0,1,100).to(device)train_y=torch.sin(train_x*(2*3.1415))+torch.randn(train_x.size()).to(device)*0.1# 4. Initialize model/likelihood and move to devicelikelihood=gpytorch.likelihoods.GaussianLikelihood().to(device)model=SimpleGPModel(train_x,train_y,likelihood).to(device)# 5. Training Loopmodel.train()likelihood.train()optimizer=torch.optim.Adam(model.parameters(),lr=0.1)mll=gpytorch.mlls.ExactMarginalLogLikelihood(likelihood,model)print("Starting training...")foriinrange(50):optimizer.zero_grad()output=model(train_x)loss=-mll(output,train_y)loss.backward()optimizer.step()if(i+1)%10==0:print(f"Iter {i+1}/50 - Loss: {loss.item():.3f}")# 6. Prediction (Inference)model.eval()likelihood.eval()test_x=torch.linspace(0,1,50).to(device)withtorch.no_grad(),gpytorch.settings.fast_pred_var():observed_pred=likelihood(model(test_x))# Move back to CPU for standard operations like printing/plottingmean=observed_pred.mean.cpu()print(f"\nPrediction complete. Mean of first 5 points: {mean[:5]}")