1616
1717'use strict' ;
1818
19- async function main ( nodeName , zone , tpuSoftwareVersion ) {
19+ async function main ( tpuClient ) {
2020 // [START tpu_vm_create_topology]
21- // Import the TPU library
22- const { TpuClient} = require ( '@google-cloud/tpu' ) . v2 ;
21+ // Import the TPUClient
22+ // TODO(developer): Uncomment below line before running the sample.
23+ // const {TpuClient} = require('@google-cloud/tpu').v2;
24+
2325 const { Node, NetworkConfig, AcceleratorConfig} =
2426 require ( '@google-cloud/tpu' ) . protos . google . cloud . tpu . v2 ;
2527
2628 // Instantiate a tpuClient
27- const tpuClient = new TpuClient ( ) ;
29+ // TODO(developer): Uncomment below line before running the sample.
30+ // tpuClient = new TpuClient();
2831
2932 /**
30- * TODO(developer): Update/uncomment these variables before running the sample.
33+ * TODO(developer): Update these variables before running the sample.
3134 */
3235 // Project ID or project number of the Google Cloud project you want to create a node.
3336 const projectId = await tpuClient . getProjectId ( ) ;
@@ -39,16 +42,16 @@ async function main(nodeName, zone, tpuSoftwareVersion) {
3942 const region = 'europe-west4' ;
4043
4144 // The name for your TPU.
42- // nodeName = 'node-name-1';
45+ const nodeName = 'node-name-1' ;
4346
4447 // The zone in which to create the TPU.
4548 // For more information about supported TPU types for specific zones,
4649 // see https://cloud.google.com/tpu/docs/regions-zones
47- // zone = 'europe-west4-a';
50+ const zone = 'europe-west4-a' ;
4851
4952 // Software version that specifies the version of the TPU runtime to install. For more information,
5053 // see https://cloud.google.com/tpu/docs/runtimes
51- // tpuSoftwareVersion = 'tpu-vm-tf-2.17.0-pod-pjrt';
54+ const tpuSoftwareVersion = 'tpu-vm-tf-2.17.0-pod-pjrt' ;
5255
5356 // The version of the Cloud TPU you want to create.
5457 // Available options: TYPE_UNSPECIFIED = 0, V2 = 2, V3 = 4, V4 = 7
@@ -74,7 +77,7 @@ async function main(nodeName, zone, tpuSoftwareVersion) {
7477 } ) ,
7578 acceleratorConfig : new AcceleratorConfig ( {
7679 type : tpuVersion ,
77- topology : topology ,
80+ topology,
7881 } ) ,
7982 } ) ;
8083
@@ -87,12 +90,16 @@ async function main(nodeName, zone, tpuSoftwareVersion) {
8790 const [ response ] = await operation . promise ( ) ;
8891
8992 console . log ( JSON . stringify ( response ) ) ;
93+ return response ;
9094 }
91- await callCreateTpuVMTopology ( ) ;
95+ return await callCreateTpuVMTopology ( ) ;
9296 // [END tpu_vm_create_topology]
9397}
9498
95- main ( ...process . argv . slice ( 2 ) ) . catch ( err => {
96- console . error ( err ) ;
97- process . exitCode = 1 ;
98- } ) ;
99+ module . exports = main ;
100+
101+ // TODO(developer): Uncomment below lines before running the sample.
102+ // main(...process.argv.slice(2)).catch(err => {
103+ // console.error(err);
104+ // process.exitCode = 1;
105+ // });
0 commit comments