def get_instance_key(self, key_id=None):
    'Returns a new instance key for use in defining a collective op.\n\n    Args:\n      key_id: optional string. If set, key will be recorded and the same key\n        will be returned when the same key_id is provided. If not, an increasing\n        instance key will be returned.\n    '
    if key_id:
        with _lock:
            if (key_id not in self._instance_key_id_to_key_table):
                self._instance_key_with_id_counter += 1
                self._instance_key_id_to_key_table[key_id] = self._instance_key_with_id_counter
        return self._instance_key_id_to_key_table[key_id]
    else:
        v = self._get_thread_local_object().instance_key
        self._get_thread_local_object().instance_key += 1
        return v
Returns a new instance key for use in defining a collective op.

Args:
  key_id: optional string. If set, key will be recorded and the same key
    will be returned when the same key_id is provided. If not, an increasing
    instance key will be returned.
def get_instance_key(self, key_id=None):
    'Returns a new instance key for use in defining a collective op.\n\n    Args:\n      key_id: optional string. If set, key will be recorded and the same key\n        will be returned when the same key_id is provided. If not, an increasing\n        instance key will be returned.\n    '
    if key_id:
        with _lock:
            if (key_id not in self._instance_key_id_to_key_table):
                self._instance_key_with_id_counter += 1
                self._instance_key_id_to_key_table[key_id] = self._instance_key_with_id_counter
        return self._instance_key_id_to_key_table[key_id]
    else:
        v = self._get_thread_local_object().instance_key
        self._get_thread_local_object().instance_key += 1
        return v