def METHOD_NAME(self, num_workers, num_ps):
    """Creates and starts local servers and returns the cluster_resolver."""
    worker_ports = [
        portpicker.pick_unused_port() for _ in range(num_workers)
    ]
    ps_ports = [portpicker.pick_unused_port() for _ in range(num_ps)]
    cluster_dict = {}
    cluster_dict["worker"] = [f"localhost:{port}" for port in worker_ports]
    if num_ps > 0:
        cluster_dict["ps"] = [f"localhost:{port}" for port in ps_ports]
    cluster_spec = tf.train.ClusterSpec(cluster_dict)
    # Workers need some inter_ops threads to work properly.
    worker_config = tf.compat.v1.ConfigProto()
    if multiprocessing.cpu_count() < num_workers + 1:
        worker_config.inter_op_parallelism_threads = num_workers + 1
    for i in range(num_workers):
        tf.distribute.Server(
            cluster_spec,
            job_name="worker",
            task_index=i,
            config=worker_config,
            protocol="grpc",
        )
    for i in range(num_ps):
        tf.distribute.Server(
            cluster_spec, job_name="ps", task_index=i, protocol="grpc"
        )
    return cluster_spec