Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

louisfaury
Copy link
Contributor

Description

Composite value networks are fairly common in multi-objective environments. They can pair well with value-estimators due to the modularity of the latter, but the PPO losses won't let them pass. This PR fixes this – mainly by allowing the distance_loss to handle TensorDicts.

Afacs this is the only fix (famous last words) needed to allow composite value networks with the classical PPO stack.

Types of changes

What types of changes does your code introduce? Remove all that do not 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)
  • Example (update in the folder of examples)

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.

@pytorch-bot
Copy link

pytorch-bot bot commented Jul 1, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/rl/3031

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 1, 2025
Louis Faury added 2 commits July 1, 2025 23:55
Copy link
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

I can register torch.var / l1_loss etc in tensordict augmented funcs if you want?

Comment on lines 760 to 761
resid = tree_map(partial(torch.var, unbiased=False, dim=0), tgt - pred)
total = tree_map(partial(torch.var, unbiased=False, dim=0), tgt)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a tree_map over the tensordict leaves?
Not sure we want to keep that in the long-term (it's 50/50 as of today) because it kind of messes up the vmap integration to have TD as a pytree.

I see that torch.overrides.get_overridable_functions() has var registered so we could simply do that such that torch.var() executes var over each leaf?

v2,
reduction="none",
)
return tree_map(lambda a, b: F.mse_loss(a, b, reduction="none"), v1, v2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

mse_loss is registered in get_overridable_functions

reduction="none",
)
if loss_function == "l1":
return tree_map(lambda a, b: F.l1_loss(a, b, reduction="none"), v1, v2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

l1_loss is in get_overridable_functions too

raise NotImplementedError(f"Unknown loss {loss_function}")
return value_loss
if loss_function == "smooth_l1":
return tree_map(lambda a, b: F.smooth_l1_loss(a, b, reduction="none"), v1, v2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

@vmoens
Copy link
Collaborator

vmoens commented Jul 2, 2025

@louisfaury have a look at pytorch/tensordict#1361

@louisfaury louisfaury force-pushed the lf/ppo-can-handle-tensordict-value-preds branch from f9e47f5 to 85e4fcc Compare July 2, 2025 15:55
Copy link
Collaborator

@vmoens vmoens left a comment

Choose a reason for hiding this comment

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

LGTM thanks!

@vmoens vmoens added the enhancement New feature or request label Jul 2, 2025
@vmoens vmoens merged commit c8a3eeb into pytorch:main Jul 2, 2025
16 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants