1717package tpu ;
1818
1919//[START tpu_vm_create_spot]
20- import com .google .api .gax .longrunning .OperationTimedPollAlgorithm ;
21- import com .google .api .gax .retrying .RetrySettings ;
2220import com .google .cloud .tpu .v2 .CreateNodeRequest ;
2321import com .google .cloud .tpu .v2 .Node ;
2422import com .google .cloud .tpu .v2 .SchedulingConfig ;
2523import com .google .cloud .tpu .v2 .TpuClient ;
26- import com .google .cloud .tpu .v2 .TpuSettings ;
2724import java .io .IOException ;
2825import java .util .concurrent .ExecutionException ;
29- import org .threeten .bp .Duration ;
3026
3127public class CreateSpotTpuVm {
3228 public static void main (String [] args )
@@ -37,7 +33,7 @@ public static void main(String[] args)
3733 // The zone in which to create the TPU.
3834 // For more information about supported TPU types for specific zones,
3935 // see https://cloud.google.com/tpu/docs/regions-zones
40- String zone = "europe-west4-a " ;
36+ String zone = "us-central1-f " ;
4137 // The name for your TPU.
4238 String nodeName = "YOUR_TPY_NAME" ;
4339 // The accelerator type that specifies the version and size of the Cloud TPU you want to create.
@@ -55,27 +51,9 @@ public static void main(String[] args)
5551 public static Node createSpotTpuVm (
5652 String projectId , String zone , String nodeName , String tpuType , String tpuSoftwareVersion )
5753 throws IOException , ExecutionException , InterruptedException {
58- // With these settings the client library handles the Operation's polling mechanism
59- // and prevent CancellationException error
60- TpuSettings .Builder clientSettings =
61- TpuSettings .newBuilder ();
62- clientSettings
63- .createNodeOperationSettings ()
64- .setPollingAlgorithm (
65- OperationTimedPollAlgorithm .create (
66- RetrySettings .newBuilder ()
67- .setInitialRetryDelay (Duration .ofMillis (5000L ))
68- .setRetryDelayMultiplier (1.5 )
69- .setMaxRetryDelay (Duration .ofMillis (45000L ))
70- .setInitialRpcTimeout (Duration .ZERO )
71- .setRpcTimeoutMultiplier (1.0 )
72- .setMaxRpcTimeout (Duration .ZERO )
73- .setTotalTimeout (Duration .ofHours (24L ))
74- .build ()));
75-
7654 // Initialize client that will be used to send requests. This client only needs to be created
7755 // once, and can be reused for multiple requests.
78- try (TpuClient tpuClient = TpuClient .create (clientSettings . build () )) {
56+ try (TpuClient tpuClient = TpuClient .create ()) {
7957 String parent = String .format ("projects/%s/locations/%s" , projectId , zone );
8058 // TODO: Wait for update of library to change preemptible to spot=True
8159 SchedulingConfig schedulingConfig = SchedulingConfig .newBuilder ()
0 commit comments