This section describes how to provision and connect to NVIDIA LLM, AI and ML optimized VM on GCP.
It will take you to the agreement page. On this page, you can change the project from the project selector on top navigator bar as shown in the below screenshot.
Accept the Terms and agreements by ticking the checkbox and clicking on the AGREE button.
It will show you the successfully agreed popup page. Click on Deploy.
Select a zone where you want to launch the VM(such as us-east1-)
Optionally change the number of cores and amount of memory. ( This defaults to 2 vCPUs and 7.5 GB ram)
The VM can only be deployed with the NVIDIA GPU instance. You can change the Type and number of GPUs from the dropdown. (This defaults to 1 NVIDIA T4 GPU )
Note: GPU availability is limited to certain zones.
A summary page displays when the compute engine is successfully deployed. Click on the Instance link to go to the instance page .
On the instance page, click on the “SSH” button, select “Open in browser window”.
sudo passwd ubuntu
Now the password for ubuntu user is set, you can connect to the VM’s desktop environment from any local windows machine using RDP or linux machine using Remmina.
To connect using RDP via Windows machine, first note the external IP of the VM from VM details page as highlighted below
Then From your local windows machine, goto “start” menu, in the search box type and select “Remote desktop connection”
In the “Remote Desktop connection” wizard, paste the external ip and click connect
To connect using RDP via Linux machine, first note the external IP of the VM from VM details page,then from your local Linux machine, goto menu, in the search box type and select “Remmina”.
Note: If you don’t have Remmina installed on your Linux machine, firstInstall Remmina as per your linux distribution.
The Notebook is available on the same public IP you used for remote desktop and accessible via any browser. Just open the browser and type the public IP address and you will get below screen for login .
The Jupyter Notebook is configured with the ubuntu as an admin user. Login with ubuntu as username and use a ubuntu user password set in the above step 6.
Note: Make sure you use “http” and not “https” in the url
Select the Input Type.
For more details on how to use Chat UI , please refer The chat interface Documentations.
%load_ext jupyter_ai_magics
To use these magic commands, open Jupyter Notebook. Run %ai help for help with syntax.
%ai help
%env OPENAI_API_KEY=Your API Key
%%ai <provider-id>:<local-model-id>
%reload_ext jupyter_ai_magics
%%ai model
Your prompt here
%ai list
Please refer The %ai and %%ai magic commands Documentations for more details.
e.g
First Install the required packages to execute the below code in jupyter notebook using.
!sudo pip3 install torch torchvision matplotlib
import torch
import torch.nn as nn
import torch.optim as optim
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
# Check if CUDA is available
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Define a simple neural network
class SimpleNN(nn.Module):
def __init__(self):
super(SimpleNN, self).__init__()
self.fc1 = nn.Linear(784, 128)
self.relu = nn.ReLU()
self.fc2 = nn.Linear(128, 10)
def forward(self, x):
x = torch.flatten(x, 1)
x = self.fc1(x)
x = self.relu(x)
x = self.fc2(x)
return x
# Load MNIST dataset
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5,), (0.5,))])
trainset = torchvision.datasets.MNIST(root='./data', train=True, download=True, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True)
# Initialize the network
net = SimpleNN().to(device)
# Define loss function and optimizer
criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(net.parameters(), lr=0.001)
# Training loop
for epoch in range(5): # loop over the dataset multiple times
running_loss = 0.0
for i, data in enumerate(trainloader, 0):
inputs, labels = data[0].to(device), data[1].to(device)
# zero the parameter gradients
optimizer.zero_grad()
# forward + backward + optimize
outputs = net(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
# print statistics
running_loss += loss.item()
if i % 100 == 99: # print every 100 mini-batches
print('[%d, %5d] loss: %.3f' % (epoch + 1, i + 1, running_loss / 100))
running_loss = 0.0
print('Finished Training')
Additional resources: