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

[Algorithm] Simpler IQL example #998

Merged
merged 83 commits into from
Dec 14, 2023
Merged

Conversation

BY571
Copy link
Contributor

@BY571 BY571 commented Mar 28, 2023

Description

Rewrites the IQL online example and adds an offline training example for IQL.

Motivation and Context

Updates the online IQL example similar to #967. Fixes the "correct_for_frame_skip" function for the nested config and adds a simple offline IQL example.

  • I have raised an issue to propose this change (required for new features and bug fixes)

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.

@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 Mar 28, 2023
Copy link
Contributor

@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 for this!
Can you merge main into this?
I will try to launch them once you do!

examples/iql/iql_online.py Outdated Show resolved Hide resolved
@vmoens
Copy link
Contributor

vmoens commented Jun 15, 2023

@BY571 I forgot: Can you add the scripts in the tests too?

@BY571
Copy link
Contributor Author

BY571 commented Jun 15, 2023

Updated online and added offline example tests for IQL and also added them for CQL as they were still missing.
Also had to do some fixes here and there.

Copy link
Contributor

@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.

Wonderful, thanks a mil!
Just a couple of housekeeping comments

examples/cql/cql_offline.py Show resolved Hide resolved
examples/cql/offline_config.yaml Show resolved Hide resolved
examples/iql/iql_online.py Outdated Show resolved Hide resolved


def make_offline_replay_buffer(rb_cfg):
data = D4RLExperienceReplay(
Copy link
Contributor

Choose a reason for hiding this comment

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

in our examples, we could default to the version that does not require the d4rl library, wdyt?
It's pretty annoying to install and the dataset works without it.

test/test_cost.py Show resolved Hide resolved
pred_q2: NestedKey = "pred_q2"
priority: NestedKey = "td_error"
cql_q1_loss: NestedKey = "cql_q1_loss"
cql_q2_loss: NestedKey = "cql_q2_loss"
priority: NestedKey = "td_error"
Copy link
Contributor

Choose a reason for hiding this comment

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

duplicate

torchrl/objectives/cql.py Outdated Show resolved Hide resolved
torchrl/objectives/cql.py Outdated Show resolved Hide resolved

td_error = abs(q_pred - target_value)
alpha_prime = torch.clamp(self.log_alpha_prime.exp(), min=0.0, max=1000000.0)
Copy link
Contributor

Choose a reason for hiding this comment

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

is 1000000.0 a magic number? What is the purpose of this clamp (to understand how we can code this in a more grounded way)?
No need to clamp an exp to 0 below, we can just do clamp_max

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed the number seems quite random, I took it directly from the official implementation 1.
As far as I could see it in some tests the alpha_prime value can become quite big I guess this is just to make sure its not exploding. But I'll have a look at the paper if they mention something more specific.

torchrl/objectives/iql.py Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Good one minor thing to edit and we're good I think

examples/iql/iql_online.py Show resolved Hide resolved
Copy link
Contributor

@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.

Awesome let's proceed!

@vmoens vmoens merged commit bc4a72f into pytorch:main Dec 14, 2023
50 of 63 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. new algo New algorithm request or PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants