返回介绍

GPU Cluster

发布于 2024-06-23 17:58:49 字数 1564 浏览 0 评论 0 收藏 0

Author: wuzewu@baidu.com

This tutorial demonstrates how to set up a GPU cluster.

First we run the following command to launch a GPU cluster with the port 8002.

xparl start --port 8002 --gpu_cluster

Then we add GPU resource of the computation server to the cluster. Users should specify the GPUs added to the cluster with the argument --gpu.

The following command is an example that adds the first 4 GPUs into the cluster.

xparl connect --address ${CLUSTER_IP}:${CLUSTER_PORT} --gpu 0,1,2,3

Once the GPU cluster based on xparl has been established, we can leverage the parl.remote_class decorator to execute parallel computations. The number of GPUs to be utilized can be specified by the n_gpu argument.

Here is an entry level example to test the GPU cluster we have set up.

import parl
import os

# connect to the Cluster. replace the ip and port with the actual IP address.
parl.connect("localhost:8002")

# Use a decorator to decorate a local class, which will be sent to a remote instance.
# n_gpu=2 means that this Actor will be allocated two GPU cards.
@parl.remote_class(n_gpu=2)
class Actor:
    def get_device(self):
        return os.environ['CUDA_VISIBLE_DEVICES']

    def step(self, a, b):
        return a + b

actor = Actor()
# execute remotely and return the value of the CUDA_VISIBLE_DEVICES environment variable.
print(actor.get_device())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文