How do I create Deep Learning VMs on GCP?
Introduction
In this tutorial, we will create a Deep Learning VM on Google Cloud Platform (GCP) AI Platform. This involves setting up necessary resources such as a Google Compute Engine instance and specifying the Deep Learning VM image type. We’ll use an AI Platform Deep Learning VM image that comes pre-installed with popular deep learning frameworks like TensorFlow and PyTorch.
Detailed Explanation
We will perform the following steps:
- Define the project and region.
- Create a VPC network and subnetwork.
- Define a Google Compute Engine instance using the Deep Learning VM image.
- Set up necessary firewall rules for instance connectivity.
Key Points
- We use
google_compute_network
to define a VPC network. - The
google_compute_subnetwork
is set up within the VPC. - A
google_compute_instance
leverages the Deep Learning VM image in theboot_disk
. - Firewall rules ensure proper access to the instance.
import * as pulumi from "@pulumi/pulumi";
import * as gcp from "@pulumi/gcp";
// Create a VPC network
const vpcNetwork = new gcp.compute.Network("vpc_network", {
name: "dl-vpc-network",
autoCreateSubnetworks: false,
});
// Create a subnetwork
const subnetwork = new gcp.compute.Subnetwork("subnetwork", {
name: "dl-subnetwork",
network: vpcNetwork.id,
ipCidrRange: "10.0.0.0/16",
region: "us-central1",
});
// Create firewall rule for allowing SSH access
const firewallRule = new gcp.compute.Firewall("firewall_rule", {
name: "allow-ssh",
network: vpcNetwork.id,
allows: [{
protocol: "tcp",
ports: ["22"],
}],
sourceRanges: ["0.0.0.0/0"],
});
// Define the Google Compute Engine instance
const dlVmInstance = new gcp.compute.Instance("dl_vm_instance", {
networkInterfaces: [{
accessConfigs: [{}],
network: vpcNetwork.id,
subnetwork: subnetwork.id,
}],
name: "dl-vm-instance",
machineType: "n1-standard-4",
zone: "us-central1-a",
bootDisk: {
initializeParams: {
image: "projects/deeplearning-platform-release/global/images/family/tf-latest-gpu",
},
},
metadata: {
"ssh-keys": "your-ssh-keys-content",
},
});
export const instanceName = dlVmInstance.name;
export const instanceZone = dlVmInstance.zone;
export const instancePublicIp = dlVmInstance.networkInterfaces.apply(networkInterfaces => networkInterfaces[0].accessConfigs?.[0]?.natIp);
Conclusion
In this example, we’ve created a Deep Learning VM on Google Cloud Platform using code. We defined a GCP project, set up a VPC network, created a Compute Engine instance with a Deep Learning VM image, and configured firewall rules to allow SSH access to our instance. These resources combine to form a robust environment for running deep learning workloads.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.