3

Im trying to create a Google Cloud TPU node using TPU client API and I cannot figure out the parent resource name of a TPU node in Google Cloud.

Below you can find the full code I'm using to create the node and I'm struggling to understand wht should be the value of the parent attribute of the CreateNodeRequest class:

def create_tpu_node(parent_resource_name, node_name, accelerator_type, runtime_version):
# Create a client
client = tpu_v2alpha1.TpuClient()

# Initialize request argument(s)
node = tpu_v2alpha1.Node()
node.name = node_name
node.accelerator_type = accelerator_type
node.runtime_version = runtime_version

request = tpu_v2alpha1.CreateNodeRequest(
    parent=parent_resource_name,
    node=node,
)

# Make the request
operation = client.create_node(request=request)

print("Waiting for operation to complete...")

response = operation.result()

# Handle the response
return response

I have tried these parent resource names, among other combinations:

  1. projects/my-project-id/zones/europe-west4-a/tpus
  2. my-project-id/zones/europe-west4-a/tpus

And I always get, respectively, one of the following errors:

google.api_core.exceptions.InvalidArgument: 400 Malformed name: 'projects/my-project-id/zones/europe-west4-a/tpus/nodes/'

or

google.api_core.exceptions.InvalidArgument: 400 Invalid resource field value in the request.

I really have no clue how to get the TPU node parent resource name, or even a TPU node resource name. Any help would be much appreciated!

EDIT: I also tried with the following parent resource name projects/my-project-id/locations/europe-west4-a, and I still get the gRPC error below:

status = StatusCode.INVALID_ARGUMENT details = "Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'" debug_error_string = "{"created":"@1645875905.514000000","description":"Error received from peer ipv4:142.251.36.42:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'","grpc_status":3}
TheDude
  • 51
  • 1
  • 4
  • Try this string modified for your project and location: **projects/example-project/locations/us-east1** – John Hanley Feb 22 '22 at 00:14
  • Hi @John Hanley, I tried that but I get the error: google.api_core.exceptions.InvalidArgument: 400 Malformed name. I also tried other combinations (see my edited post). Any other suggestions? – TheDude Feb 22 '22 at 21:34

1 Answers1

1

You can find the expected format of parent in the documentation for the underlying API method: projects.locations.nodes.create.

parent should be formatted as projects/*/locations/*. That is, change zones to locations and remove the /tpus from the end.

Edit: adding some example code below

I tried exactly the following (except for project and TPU names) on a Cloud Shell:

from google.cloud import tpu_v2alpha1

req = tpu_v2alpha1.CreateNodeRequest(
  parent='projects/my-project-id/locations/europe-west4-a', 
  node_id='test-tpu',
  node=tpu_v2alpha1.Node(
    accelerator_type='v2-8',
    runtime_version='v2-alpha',
    network_config=tpu_v2alpha1.NetworkConfig(
      enable_external_ips=True)))

op = client.create_node(req)
# Shows TPU created successfully
op.result()

I ran this example with the google-cloud-tpu package at 1.3.2

Will Cromar
  • 179
  • 1
  • 7
  • Hi, I tried also with that format, and I still get the error below (btw, Im using conda virtual env) `status = StatusCode.INVALID_ARGUMENT details = "Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'" debug_error_string = "{"created":"@1645875905.514000000","description":"Error received from peer ipv4:142.251.36.42:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"Malformed name: 'projects/my-project-id/locations/europe-west4-a/nodes/'","grpc_status":3}"` – TheDude Feb 26 '22 at 11:48
  • It looks like you need to remove `nodes` from the path. i.e. change `projects/my-project-id/locations/europe-west4-a/nodes/` to `projects/my-project-id/locations/europe-west4-a/` – Will Cromar Feb 28 '22 at 18:35
  • 1
    Hi, I have the exact same issue. To be clear, the author and I are *not* adding the trailing /nodes in the parent string, simply `parent="projects/*/locations/*"`, as requested in the responses to this issue. But we can still see /nodes in the "Malformed name" error. Maybe it is added by the library? – Rémi Debette Mar 03 '22 at 22:57
  • Thanks for clarifying. Can you try the example code I added to my answer and tell me if that works? – Will Cromar Mar 07 '22 at 18:53
  • 1
    Hi, with your example code, it now works for me in 1.3.1 too. Thanks a lot – Rémi Debette Mar 08 '22 at 11:08