Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] #364

Open
3 tasks done
Eureka725 opened this issue Jan 1, 2025 · 1 comment
Open
3 tasks done

[Question] #364

Eureka725 opened this issue Jan 1, 2025 · 1 comment
Labels
question Further information is requested

Comments

@Eureka725
Copy link

Eureka725 commented Jan 1, 2025

Required prerequisites

Questions

`"""Example of training a policy from exp-x config with OmniSafe."""

import warnings

import torch

from omnisafe.common.experiment_grid import ExperimentGrid
from omnisafe.utils.exp_grid_tools import train
if name == 'main':
eg = ExperimentGrid(exp_name='TEST')

# set up the algorithms.
naive_lagrange_policy = ['PPOLag']
first_order_policy = [
    'P3O',
    #'CUP',
    #'FOCOPS',
    ]
second_order_policy = ['PCPO',
                       'RCPO']
saute_policy = ['PPOSaute']
simmer_policy = ['CRPO']
early_mdp_policy = ['PPOEarlyTerminated']

eg.add(
    'algo',
    naive_lagrange_policy
    +
    first_order_policy 
    +
    second_order_policy 
    +
    saute_policy 
    +
    simmer_policy 
    +
    early_mdp_policy
)

# you can use wandb to monitor the experiment.
eg.add('logger_cfgs:use_wandb', [False])
# you can use tensorboard to monitor the experiment.
eg.add('logger_cfgs:use_tensorboard', [True])

# the default configs here are as follows:
# eg.add('algo_cfgs:steps_per_epoch', [20000])
# eg.add('train_cfgs:total_steps', [20000 * 500])
# which can reproduce results of 1e7 steps.

# if you want to reproduce results of 1e6 steps, using
# eg.add('algo_cfgs:steps_per_epoch', [2048])
# eg.add('train_cfgs:total_steps', [2048 * 500])

# set the device.
avaliable_gpus = list(range(torch.cuda.device_count()))
# if you want to use GPU, please set gpu_id like follows:
# gpu_id = [0, 1, 2, 3]
# if you want to use CPU, please set gpu_id = None
# we recommends using CPU to obtain results as consistent
# as possible with our publicly available results,
# since the performance of all on-policy algorithms
# in OmniSafe is tested on CPU.
gpu_id = [0,1,2,3]

if gpu_id and not set(gpu_id).issubset(avaliable_gpus):
    warnings.warn('The GPU ID is not available, use CPU instead.', stacklevel=1)
    gpu_id = None

# set up the environment.
eg.add('env_id', [
    #'SafetyCarGoal2-v0',#1
    #'SafetyRacecarCircle2-v0',#2
    'SafetyHopperVelocity-v1',
    #'SafetyCarButton2-v0',#3
    'SafetyAntVelocity-v1',
    'SafetyHalfCheetahVelocity-v1',#4
    #'SafetyPointGoal1-v0',
    #'SafetyPointButton1-v0',
    #'SafetyCarCircle1-v0',
    #'SafetyCarButton1-v0',
    'SafetyHumanoidVelocity-v1',#5
    #'SafetyCarGoal1-v0'#6
    ])
eg.add('seed', [0,5,10])#1,5,10,15,20
#eg.add('seed', [8])

# total experiment num must can be divided by num_pool.
# meanwhile, users should decide this value according to their machine.
eg.run(train, num_pool=3, gpu_id=gpu_id)`
Thank you for your work! Hello, I would like to ask a question about why I use CPU instead of GPU when running this code?
@Eureka725 Eureka725 added the question Further information is requested label Jan 1, 2025
@Eureka725
Copy link
Author

Sorry, there is an issue with my presentation. I modified the use of CUDA in the config, but it also requires a lot of CPU usage. Is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant