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

refactor(wrapper): refactor the cuda setting #176

Merged
merged 6 commits into from
Mar 26, 2023

Conversation

Gaiejj
Copy link
Member

@Gaiejj Gaiejj commented Mar 25, 2023

Description

refactor the cuda setting

Types of changes

What types of changes does your code introduce? Put an x in all the boxes that apply:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds core functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

Go over all the following points, and put an x in all the boxes that apply.
If you are unsure about any of these, don't hesitate to ask. We are here to help!

  • I have read the CONTRIBUTION guide. (required)
  • My change requires a change to the documentation.
  • I have updated the tests accordingly. (required for a bug fix or a new feature)
  • I have updated the documentation accordingly.
  • I have reformatted the code using make format. (required)
  • I have checked the code using make lint. (required)
  • I have ensured make test pass. (required)

@codecov
Copy link

codecov bot commented Mar 25, 2023

Codecov Report

Patch coverage: 72.15% and project coverage change: -0.12 ⚠️

Comparison is base (68b9be8) 86.44% compared to head (064a216) 86.32%.

❗ Current head 064a216 differs from pull request most recent head e358c3e. Consider uploading reports for the commit e358c3e to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #176      +/-   ##
==========================================
- Coverage   86.44%   86.32%   -0.12%     
==========================================
  Files          80       80              
  Lines        3762     3760       -2     
==========================================
- Hits         3252     3246       -6     
- Misses        510      514       +4     
Impacted Files Coverage Δ
omnisafe/adapter/saute_adapter.py 32.35% <0.00%> (ø)
omnisafe/algorithms/on_policy/second_order/cpo.py 70.94% <33.33%> (-2.49%) ⬇️
omnisafe/evaluator.py 59.49% <66.66%> (ø)
omnisafe/envs/wrapper.py 97.65% <92.30%> (+0.01%) ⬆️
omnisafe/adapter/offpolicy_adapter.py 100.00% <100.00%> (ø)
omnisafe/adapter/online_adapter.py 100.00% <100.00%> (ø)
omnisafe/algorithms/on_policy/second_order/pcpo.py 100.00% <100.00%> (ø)
omnisafe/envs/core.py 89.81% <100.00%> (+1.02%) ⬆️
omnisafe/envs/safety_gymnasium_env.py 97.56% <100.00%> (+0.06%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Gaiejj Gaiejj requested review from rockmagma02 and zmsn-2077 and removed request for rockmagma02 March 25, 2023 11:07
@Gaiejj Gaiejj requested a review from rockmagma02 March 25, 2023 11:27

for _ in range(roll_out_step):
act = act_fn()
next_obs, reward, cost, terminated, truncated, info = self.step(act)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in all loop of roll_out_step, use same act? it seem like a bug, we must consider the situation roll_out_step != 1

@@ -92,7 +92,7 @@ def __init__(self, env_id: str, num_envs: int = 1, **kwargs) -> None:
def step(
self, action: torch.Tensor
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, Dict]:
obs, reward, cost, terminated, truncated, info = self._env.step(action)
obs, reward, cost, terminated, truncated, info = self._env.step(action.cpu().numpy())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use action.detach().cpu().numpy()

@@ -217,16 +218,25 @@ def __getattr__(self, name: str) -> Any:
def step(
self, action: torch.Tensor
) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor, Dict]:
return self._env.step(action)
obs, reward, cost, terminated, truncated, info = self._env.step(action)
return (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change device only in safety_gymnasium_env.py please, changing device in Wrapper could cause multi-calculating in reset and step

@Gaiejj Gaiejj added enhancement New feature or request codestyle update codestyple labels Mar 25, 2023
@zmsn-2077 zmsn-2077 added bug Something isn't working feature Something related to new features and removed codestyle update codestyple labels Mar 25, 2023
@Gaiejj Gaiejj requested a review from rockmagma02 March 26, 2023 02:48
@@ -75,7 +75,9 @@ class SafetyGymnasiumEnv(CMDP):
need_auto_reset_wrapper = False
need_time_limit_wrapper = False

def __init__(self, env_id: str, num_envs: int = 1, **kwargs) -> None:
def __init__(
self, env_id: str, num_envs: int = 1, device: torch.device = 'cpu', **kwargs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device: torch.device = torch.device('cpu')

Copy link
Member

@zmsn-2077 zmsn-2077 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@Gaiejj Gaiejj merged commit 8628ca6 into PKU-Alignment:dev Mar 26, 2023
zmsn-2077 pushed a commit that referenced this pull request Mar 26, 2023
* refactor(wrapper): refactor the cuda setting

* chore: revert train_policy.py

* chore: set device in safety_gymnasium_env.py

* fix: [pre-commit.ci] auto fixes [...]

* fix(safety_gymnasium_env.py): fix device interface

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@Gaiejj Gaiejj deleted the dev-cuda branch March 29, 2023 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request feature Something related to new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants