GPU未在D3rlpy上使用

发布于 2025-02-12 08:47:10 字数 2186 浏览 3 评论 0 原文

我是使用D3RLPY进行离线RL训练的新手,并使用Pytorch。因此,我按照 pytorch doc pip> pip3安装torch torchvision torchvision torchvision torchvision torchvoush torchvision torm =“ - Extra-index-url https://download.pytorch.org/whl/cu116 。我在之后安装了D3RLPY并运行以下示例代码:

from d3rlpy.algos import BC,DDPG,CRR,PLAS,PLASWithPerturbation,TD3PlusBC,IQL
import d3rlpy
import numpy as np
import glob
import time

#models
continuous_models = {
                      "BehaviorCloning": BC,
                      "DeepDeterministicPolicyGradients": DDPG,
                      "CriticRegularizedRegression": CRR,
                      "PolicyLatentActionSpace": PLAS,
                      "PolicyLatentActionSpacePerturbation": PLASWithPerturbation,
                      "TwinDelayedPlusBehaviorCloning": TD3PlusBC,
                      "ImplicitQLearning": IQL,
                    }
#load dataset data_batch is created as a*.h5 file with d3rlpy
dataset = d3rlpy.dataset.MDPDataset.load(data_batch)
        
# preprocess
mean = np.mean(dataset.observations, axis=0, keepdims=True)
std = np.std(dataset.observations, axis=0, keepdims=True)
scaler = d3rlpy.preprocessing.StandardScaler(mean=mean, std=std)

# test models
for _model in continuous_models:
    the_model = continuous_models[_model](scaler = scaler)
    the_model.use_gpu = True
    the_model.build_with_dataset(dataset)

    the_model.fit(dataset = dataset.episodes,
                  n_steps_per_epoch = 10800, 
                  n_steps = 54000,
                  logdir = './logs', 
                  experiment_name = f"{_model}", 
                  tensorboard_dir = 'logs',
                  save_interval = 900, # we don't want to save intermediate parameters
                 )
    #save model
    the_timestamp = int(time.time())
    the_model.save_model(f"./models/{_model}/{_model}_{the_timestamp}.pt")  

问题是,尽管设置了 use_gpu = true ,但没有一个模型实际上使用了GPU。使用pytotch和Testing torch.cuda.current_device()的示例代码,我可以看到Pytorch已正确设置并检测GPU。有什么想法在哪里解决这个问题?我不确定这是d3rlpy的错误,所以我会在github上打扰:)

I am new to using d3rlpy for offline RL training and makes use of pytorch. So I installed cuda 1.16 as recommended from PYtorch doc: pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116. I installed d3rlpy after and run the following sample code:

from d3rlpy.algos import BC,DDPG,CRR,PLAS,PLASWithPerturbation,TD3PlusBC,IQL
import d3rlpy
import numpy as np
import glob
import time

#models
continuous_models = {
                      "BehaviorCloning": BC,
                      "DeepDeterministicPolicyGradients": DDPG,
                      "CriticRegularizedRegression": CRR,
                      "PolicyLatentActionSpace": PLAS,
                      "PolicyLatentActionSpacePerturbation": PLASWithPerturbation,
                      "TwinDelayedPlusBehaviorCloning": TD3PlusBC,
                      "ImplicitQLearning": IQL,
                    }
#load dataset data_batch is created as a*.h5 file with d3rlpy
dataset = d3rlpy.dataset.MDPDataset.load(data_batch)
        
# preprocess
mean = np.mean(dataset.observations, axis=0, keepdims=True)
std = np.std(dataset.observations, axis=0, keepdims=True)
scaler = d3rlpy.preprocessing.StandardScaler(mean=mean, std=std)

# test models
for _model in continuous_models:
    the_model = continuous_models[_model](scaler = scaler)
    the_model.use_gpu = True
    the_model.build_with_dataset(dataset)

    the_model.fit(dataset = dataset.episodes,
                  n_steps_per_epoch = 10800, 
                  n_steps = 54000,
                  logdir = './logs', 
                  experiment_name = f"{_model}", 
                  tensorboard_dir = 'logs',
                  save_interval = 900, # we don't want to save intermediate parameters
                 )
    #save model
    the_timestamp = int(time.time())
    the_model.save_model(f"./models/{_model}/{_model}_{the_timestamp}.pt")  

The issue is that None of the models, despite being set with use_gpu =True are actually using the GPU. With a sample code of pytotch and testing torch.cuda.current_device() I can see that pytorch is properly set and detecting the gpu. Any idea where to look for solving this issue? I am not sure this is a bug from the d3rlpy so I would bother creating an issue on github yet :)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

单身情人 2025-02-19 08:47:10

您可以尝试将 use_gpu = true 作为参数以及 scaleer = safleer the_model 对象没有称为 use_gpu 的方法,例如 build_with_dataset

You can try passing use_gpu = True as an argument along with scaler = scaler. the_model object has no method called use_gpu like build_with_dataset.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文