Skip to content

Commit 84d3b32

Browse files
authored
Merge branch 'main' into compute_snapshot_schedule_attach
2 parents 307b652 + cf8e417 commit 84d3b32

File tree

12 files changed

+658
-0
lines changed

12 files changed

+658
-0
lines changed

.github/workflows/tpu.yaml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: tpu
16+
on:
17+
push:
18+
branches:
19+
- main
20+
paths:
21+
- 'tpu/**'
22+
- '.github/workflows/tpu.yaml'
23+
- '.github/workflows/test.yaml'
24+
pull_request:
25+
types:
26+
- opened
27+
- reopened
28+
- synchronize
29+
- labeled
30+
paths:
31+
- 'tpu/**'
32+
- '.github/workflows/tpu.yaml'
33+
- '.github/workflows/test.yaml'
34+
schedule:
35+
- cron: '0 0 * * 0'
36+
jobs:
37+
test:
38+
# Ref: https://github.com/google-github-actions/auth#usage
39+
permissions:
40+
contents: 'read'
41+
id-token: 'write'
42+
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
43+
uses: ./.github/workflows/test.yaml
44+
with:
45+
name: 'tpu'
46+
path: 'tpu'
47+
flakybot:
48+
# Ref: https://github.com/google-github-actions/auth#usage
49+
permissions:
50+
contents: 'read'
51+
id-token: 'write'
52+
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
53+
uses: ./.github/workflows/flakybot.yaml
54+
needs: [test]

.github/workflows/utils/workflows.json

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"speech",
9191
"talent",
9292
"texttospeech",
93+
"tpu",
9394
"translate",
9495
"video-intelligence",
9596
"vision/productSearch",

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ recaptcha_enterprise @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-
2424
recaptcha_enterprise/demosite @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/recaptcha-customer-obsession-reviewers @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2525
secret-manager @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-secrets-team
2626
service-directory @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
27+
tpu @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2728
webrisk @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
2829

2930
# SoDa teams

tpu/createVM.js

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(tpuClient) {
20+
// [START tpu_vm_create]
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2;
24+
const {Node, NetworkConfig} =
25+
require('@google-cloud/tpu').protos.google.cloud.tpu.v2;
26+
27+
// Instantiate a tpuClient
28+
// TODO(developer): Uncomment below line before running the sample.
29+
// tpuClient = new TpuClient();
30+
31+
// TODO(developer): Update below line before running the sample.
32+
// Project ID or project number of the Google Cloud project you want to create a node.
33+
const projectId = await tpuClient.getProjectId();
34+
35+
// The name of the network you want the TPU node to connect to. The network should be assigned to your project.
36+
const networkName = 'compute-tpu-network';
37+
38+
// The region of the network, that you want the TPU node to connect to.
39+
const region = 'europe-west4';
40+
41+
// The name for your TPU.
42+
const nodeName = 'node-name-1';
43+
44+
// The zone in which to create the TPU.
45+
// For more information about supported TPU types for specific zones,
46+
// see https://cloud.google.com/tpu/docs/regions-zones
47+
const zone = 'europe-west4-a';
48+
49+
// The accelerator type that specifies the version and size of the Cloud TPU you want to create.
50+
// For more information about supported accelerator types for each TPU version,
51+
// see https://cloud.google.com/tpu/docs/system-architecture-tpu-vm#versions.
52+
const tpuType = 'v2-8';
53+
54+
// Software version that specifies the version of the TPU runtime to install. For more information,
55+
// see https://cloud.google.com/tpu/docs/runtimes
56+
const tpuSoftwareVersion = 'tpu-vm-tf-2.14.1';
57+
58+
async function callCreateTpuVM() {
59+
// Create a node
60+
const node = new Node({
61+
name: nodeName,
62+
zone,
63+
acceleratorType: tpuType,
64+
runtimeVersion: tpuSoftwareVersion,
65+
// Define network
66+
networkConfig: new NetworkConfig({
67+
enableExternalIps: true,
68+
network: `projects/${projectId}/global/networks/${networkName}`,
69+
subnetwork: `projects/${projectId}/regions/${region}/subnetworks/${networkName}`,
70+
}),
71+
});
72+
73+
const parent = `projects/${projectId}/locations/${zone}`;
74+
const request = {parent, node, nodeId: nodeName};
75+
76+
const [operation] = await tpuClient.createNode(request);
77+
78+
// Wait for the create operation to complete.
79+
const [response] = await operation.promise();
80+
81+
console.log(`TPU VM: ${nodeName} created.`);
82+
return response;
83+
}
84+
return await callCreateTpuVM();
85+
// [END tpu_vm_create]
86+
}
87+
88+
module.exports = main;
89+
90+
// TODO(developer): Uncomment below lines before running the sample.
91+
// main(...process.argv.slice(2)).catch(err => {
92+
// console.error(err);
93+
// process.exitCode = 1;
94+
// });

tpu/deleteVM.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(tpuClient) {
20+
// [START tpu_vm_delete]
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2;
24+
25+
// Instantiate a tpuClient
26+
// TODO(developer): Uncomment below line before running the sample.
27+
// tpuClient = new TpuClient();
28+
29+
// TODO(developer): Update these variables before running the sample.
30+
// Project ID or project number of the Google Cloud project you want to delete a node.
31+
const projectId = await tpuClient.getProjectId();
32+
33+
// The name of TPU to delete.
34+
const nodeName = 'node-name-1';
35+
36+
// The zone, where the TPU is created.
37+
const zone = 'europe-west4-a';
38+
39+
async function callDeleteTpuVM() {
40+
const request = {
41+
name: `projects/${projectId}/locations/${zone}/nodes/${nodeName}`,
42+
};
43+
44+
const [operation] = await tpuClient.deleteNode(request);
45+
46+
// Wait for the delete operation to complete.
47+
const [response] = await operation.promise();
48+
49+
console.log(`Node: ${nodeName} deleted.`);
50+
return response;
51+
}
52+
53+
return await callDeleteTpuVM();
54+
// [END tpu_vm_delete]
55+
}
56+
57+
module.exports = main;
58+
59+
// TODO(developer): Uncomment below lines before running the sample.
60+
// main(...process.argv.slice(2)).catch(err => {
61+
// console.error(err);
62+
// process.exitCode = 1;
63+
// });

tpu/getVM.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(tpuClient) {
20+
// [START tpu_vm_get]
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2;
24+
25+
// Instantiate a tpuClient
26+
// TODO(developer): Uncomment below line before running the sample.
27+
// tpuClient = new TpuClient();
28+
29+
// TODO(developer): Update these variables before running the sample.
30+
// Project ID or project number of the Google Cloud project you want to retrive a node.
31+
const projectId = await tpuClient.getProjectId();
32+
33+
// The name of TPU to retrive.
34+
const nodeName = 'node-name-1';
35+
36+
// The zone, where the TPU is created.
37+
const zone = 'europe-west4-a';
38+
39+
async function callGetTpuVM() {
40+
const request = {
41+
name: `projects/${projectId}/locations/${zone}/nodes/${nodeName}`,
42+
};
43+
44+
const [response] = await tpuClient.getNode(request);
45+
46+
console.log(`Node: ${nodeName} retrived.`);
47+
return response;
48+
}
49+
50+
return await callGetTpuVM();
51+
// [END tpu_vm_get]
52+
}
53+
54+
module.exports = main;
55+
56+
// TODO(developer): Uncomment below lines before running the sample.
57+
// main(...process.argv.slice(2)).catch(err => {
58+
// console.error(err);
59+
// process.exitCode = 1;
60+
// });

tpu/getVMList.js

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main(tpuClient) {
20+
// [START tpu_vm_list]
21+
// Import the TPUClient
22+
// TODO(developer): Uncomment below line before running the sample.
23+
// const {TpuClient} = require('@google-cloud/tpu').v2;
24+
25+
// Instantiate a tpuClient
26+
// TODO(developer): Uncomment below line before running the sample.
27+
// tpuClient = new TpuClient();
28+
29+
// TODO(developer): Update these variables before running the sample.
30+
// Project ID or project number of the Google Cloud project you want to retrive a list of TPU nodes.
31+
const projectId = await tpuClient.getProjectId();
32+
33+
// The zone from which the TPUs are retrived.
34+
const zone = 'europe-west4-a';
35+
36+
async function callTpuVMList() {
37+
const request = {
38+
parent: `projects/${projectId}/locations/${zone}`,
39+
};
40+
41+
const [response] = await tpuClient.listNodes(request);
42+
43+
return response;
44+
}
45+
46+
return await callTpuVMList();
47+
// [END tpu_vm_list]
48+
}
49+
50+
module.exports = main;
51+
52+
// TODO(developer): Uncomment below lines before running the sample.
53+
// main(...process.argv.slice(2)).catch(err => {
54+
// console.error(err);
55+
// process.exitCode = 1;
56+
// });

tpu/package.json

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "nodejs-docs-samples-tpu",
3+
"license": "Apache-2.0",
4+
"author": "Google Inc.",
5+
"engines": {
6+
"node": ">=16.0.0"
7+
},
8+
"repository": "googleapis/nodejs-tpu",
9+
"private": true,
10+
"files": [
11+
"*.js"
12+
],
13+
"scripts": {
14+
"test": "c8 mocha -p -j 2 test --timeout 1200000"
15+
},
16+
"dependencies": {
17+
"@google-cloud/tpu": "^3.5.0",
18+
"sinon": "^19.0.2"
19+
},
20+
"devDependencies": {
21+
"c8": "^10.0.0",
22+
"mocha": "^10.0.0"
23+
}
24+
}

0 commit comments

Comments
 (0)