-
Notifications
You must be signed in to change notification settings - Fork 120
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(wrh): add harmony dream in unizero #255
Open
ruiheng123
wants to merge
6
commits into
opendilab:main
Choose a base branch
from
ruiheng123:dev-unizero-harmonydream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
ruiheng123
commented
Jul 31, 2024
•
edited
Loading
edited
- Add harmony dream for balancing loss weights among observation, reaward, policy, value.
- Paper reference: https://arxiv.org/abs/2310.00344
- Code reference: https://github.com/thuml/HarmonyDream/blob/main/wmlib-torch/wmlib/agents/dreamerv2.py#L117
puyuan1996
reviewed
Aug 5, 2024
@@ -164,19 +176,60 @@ def __init__(self, latent_recon_loss_weight=0, perceptual_loss_weight=0, **kwarg | |||
self.loss_total = torch.tensor(0., device=device) | |||
for k, v in kwargs.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Define a dictionary for loss weights and harmony_s variables
loss_weights = {
'loss_obs': (self.obs_loss_weight, 'loss_obs_harmony_s'),
'loss_rewards': (self.reward_loss_weight, 'loss_rewards_harmony_s'),
'loss_policy': (self.policy_loss_weight, 'loss_policy_harmony_s'),
'loss_value': (self.value_loss_weight, 'loss_value_harmony_s'),
'loss_ends': (self.ends_loss_weight, 'loss_ends_harmony_s'),
'latent_recon_loss': (self.latent_recon_loss_weight, 'latent_recon_loss_harmony_s'),
'perceptual_loss': (self.perceptual_loss_weight, 'perceptual_loss_harmony_s')
}
# Iterate through kwargs to process the losses
for k, v in kwargs.items():
if k in loss_weights:
weight, harmony_var_name = loss_weights[k]
harmony_s = globals().get(harmony_var_name) # Get the harmony_s variable by name
if harmony_s_dict is None:
self.loss_total += weight * v
elif harmony_s is not None:
self.loss_total += (v / torch.exp(harmony_s)) + torch.log(torch.exp(harmony_s) + 1)
else:
self.loss_total += weight * v
puyuan1996
reviewed
Aug 5, 2024
lzero/policy/unizero.py
Outdated
) | ||
|
||
|
||
# else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
删除
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.