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

feature(zp): add dreamerv3 algorithm #652

Merged
merged 17 commits into from
Aug 7, 2023
Merged

Conversation

zhangpaipai
Copy link
Collaborator

@zhangpaipai zhangpaipai commented Apr 25, 2023

Description

  • implement dreamerv3
  • test dreamerv3's performance on dmc2gym

cartpole_balance:
image

walker_walk:
image

Related Issue

#669

TODO

Check List

  • merge the latest version source branch/repo, and resolve all the conflicts
  • pass style check
  • pass all the tests

@zhangpaipai zhangpaipai added the algo Add new algorithm or improve old one label Apr 25, 2023
@codecov
Copy link

codecov bot commented Apr 25, 2023

Codecov Report

Merging #652 (1b3f02a) into main (6b188c9) will increase coverage by 0.41%.
Report is 9 commits behind head on main.
The diff coverage is 75.68%.

❗ Current head 1b3f02a differs from pull request most recent head efbe0e8. Consider uploading reports for the commit efbe0e8 to get more accurate results

@@            Coverage Diff             @@
##             main     #652      +/-   ##
==========================================
+ Coverage   82.06%   82.47%   +0.41%     
==========================================
  Files         586      586              
  Lines       47515    48047     +532     
==========================================
+ Hits        38991    39626     +635     
+ Misses       8524     8421     -103     
Flag Coverage Δ
unittests 82.47% <75.68%> (+0.41%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
ding/world_model/utils.py 62.56% <61.37%> (-16.01%) ⬇️
ding/world_model/model/networks.py 83.72% <83.72%> (ø)
ding/model/common/encoder.py 95.20% <100.00%> (+0.88%) ⬆️
ding/model/common/tests/test_encoder.py 100.00% <100.00%> (ø)
ding/world_model/model/tests/test_networks.py 100.00% <100.00%> (ø)
ding/world_model/tests/test_world_model_utils.py 100.00% <100.00%> (ø)

... and 271 files with indirect coverage changes

ding/world_model/utils.py Outdated Show resolved Hide resolved
return -loss


class ContDist:
Copy link
Member

Choose a reason for hiding this comment

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

polish all the class name of distributions we implemented, unify their name format

ding/world_model/utils.py Outdated Show resolved Hide resolved

class SymlogDist():

def __init__(self, mode, dist='mse', agg='sum', tol=1e-8, dim_to_reduce=[-1, -2, -3]):
Copy link
Member

Choose a reason for hiding this comment

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

add python typing lint

ding/world_model/utils.py Outdated Show resolved Hide resolved

def mode(self):
_mode = torch.round(self._dist.mean)
return _mode.detach() + self._dist.mean - self._dist.mean.detach()
Copy link
Member

Choose a reason for hiding this comment

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

why use detach here

ding/world_model/model/networks.py Outdated Show resolved Hide resolved
ding/model/common/tests/test_encoder.py Outdated Show resolved Hide resolved
ding/model/common/encoder.py Outdated Show resolved Hide resolved
ding/model/common/encoder.py Show resolved Hide resolved
class Conv2dSame(torch.nn.Conv2d):

def calc_same_pad(self, i, k, s, d):
return max((math.ceil(i / s) - 1) * s + (k - 1) * d + 1 - i, 0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add data type for i,k,s,d
Add function notation

class DreamerLayerNorm(nn.Module):

def __init__(self, ch, eps=1e-03):
super(DreamerLayerNorm, self).__init__()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add data type

import torch
from torch import nn
import torch.nn.functional as F
from torch import distributions as torchd
Copy link
Collaborator

Choose a reason for hiding this comment

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

please do not use torchd as short module name. It's not a standard coding format.
It's better to from torch.distributions import XXXXX.
Import only what you need.

ding/world_model/utils.py Outdated Show resolved Hide resolved
ding/world_model/utils.py Outdated Show resolved Hide resolved
ding/world_model/utils.py Outdated Show resolved Hide resolved

class TwoHotDistSymlog():

def __init__(self, logits=None, low=-20.0, high=20.0, device='cpu'):
Copy link
Collaborator

Choose a reason for hiding this comment

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

device is set by default. It should not be explicitly set by some argument.

ding/world_model/utils.py Outdated Show resolved Hide resolved
ding/world_model/utils.py Outdated Show resolved Hide resolved
@PaParaZz1 PaParaZz1 changed the title feature(zp): add Dreamerv3 features feature(zp): add dreamerv3 algorithm Aug 7, 2023
@PaParaZz1 PaParaZz1 merged commit 1074bab into opendilab:main Aug 7, 2023
1 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
algo Add new algorithm or improve old one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants