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] GAIL #2273

Merged
merged 35 commits into from
Aug 6, 2024
Merged

[Algorithm] GAIL #2273

merged 35 commits into from
Aug 6, 2024

Conversation

BY571
Copy link
Contributor

@BY571 BY571 commented Jul 8, 2024

Description

Add the algorithm Generative Adversarial Imitation Learning GAIL

Motivation and Context

Why is this change required? What problem does it solve?
If it fixes an open issue, please link to the issue here.
You can use the syntax close #15213 if this solves the issue #15213

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

Copy link

pytorch-bot bot commented Jul 8, 2024

🔗 Helpful Links

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

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

❌ 5 New Failures, 1 Cancelled Job, 7 Unrelated Failures

As of commit c488bcd with merge base 788710f (image):

NEW FAILURES - The following jobs have failed:

CANCELLED JOB - The following job was cancelled. Please retry:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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 8, 2024
@vmoens vmoens added the new algo New algorithm request or PR label Jul 8, 2024
@BY571 BY571 marked this pull request as ready for review July 11, 2024 09:40
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.

Let's just add the device in the config and we're good to go!
Thanks for this, fab work

sota-implementations/gail/gail.py Outdated Show resolved Hide resolved
@vmoens
Copy link
Contributor

vmoens commented Jul 30, 2024

@BY571 The examples fail with:

100% 48/48 [00:00<00:00, 53.31it/s]
  python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/gail/gail.py \
  collector.total_frames=48 \
  loss.mini_batch_size=10 \
  collector.frames_per_batch=16 \
  logger.mode=offline \
  logger.backend=
/pytorch/rl/sota-implementations/gail/gail.py:31: UserWarning: 
The version_base parameter is not specified.
Please specify a compatability version level, or None.
Will assume defaults for version 1.1
  @hydra.main(config_path="", config_name="config")
omegaconf.errors.ConfigAttributeError: Key 'collector' is not in struct

@BY571
Copy link
Contributor Author

BY571 commented Jul 31, 2024

@BY571 The examples fail with:

100% 48/48 [00:00<00:00, 53.31it/s]
  python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/gail/gail.py \
  collector.total_frames=48 \
  loss.mini_batch_size=10 \
  collector.frames_per_batch=16 \
  logger.mode=offline \
  logger.backend=
/pytorch/rl/sota-implementations/gail/gail.py:31: UserWarning: 
The version_base parameter is not specified.
Please specify a compatability version level, or None.
Will assume defaults for version 1.1
  @hydra.main(config_path="", config_name="config")
omegaconf.errors.ConfigAttributeError: Key 'collector' is not in struct

should be fixed also the device selection @vmoens.

@vmoens
Copy link
Contributor

vmoens commented Aug 3, 2024

@BY571 I think we need to tell that the backend is gymansium, not gym:

  python .github/unittest/helpers/coverage_run_parallel.py sota-implementations/gail/gail.py \
  ppo.collector.total_frames=48 \
  ppo.loss.mini_batch_size=10 \
  ppo.collector.frames_per_batch=16 \
  logger.mode=offline \
  logger.backend=
/pytorch/rl/sota-implementations/gail/gail.py:31: UserWarning: 
The version_base parameter is not specified.
Please specify a compatability version level, or None.
Will assume defaults for version 1.1
  @hydra.main(config_path="", config_name="config")
/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/hydra.py:119: UserWarning: Future Hydra versions will no longer change working directory at job runtime by default.
See https://hydra.cc/docs/1.2/upgrades/1.1_to_1.2/changes_to_job_working_dir/ for more information.
  ret = run_job(
Error executing job with overrides: ['ppo.collector.total_frames=48', 'ppo.loss.mini_batch_size=10', 'ppo.collector.frames_per_batch=16', 'logger.mode=offline', 'logger.backend=']
Traceback (most recent call last):
  File "/pytorch/rl/sota-implementations/gail/gail.py", line 281, in <module>
    main()
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/main.py", line 94, in decorated_main
    _run_hydra(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
    _run_app(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 457, in _run_app
    run_and_report(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
    raise ex
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
    lambda: hydra.run(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/hydra.py", line 132, in run
    _ = ret.return_value
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/core/utils.py", line 260, in return_value
    raise self._return_value
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/core/utils.py", line 186, in run_job
    ret.return_value = task_function(task_cfg)
  File "/pytorch/rl/sota-implementations/gail/gail.py", line 72, in main
    actor, critic = make_ppo_models(cfg.env.env_name)
  File "/pytorch/rl/sota-implementations/gail/ppo_utils.py", line 121, in make_ppo_models
    proof_environment = make_env(env_name, device="cpu")
  File "/pytorch/rl/sota-implementations/gail/ppo_utils.py", line 31, in make_env
    env = GymEnv(env_name, device=device, from_pixels=from_pixels, pixels_only=False)
  File "/pytorch/rl/torchrl/envs/libs/gym.py", line 571, in __call__
    instance: GymWrapper = super().__call__(*args, **kwargs)
  File "/pytorch/rl/torchrl/envs/common.py", line 176, in __call__
    instance: EnvBase = super().__call__(*args, **kwargs)
  File "/pytorch/rl/torchrl/envs/libs/gym.py", line 1371, in __init__
    super().__init__(**kwargs)
  File "/pytorch/rl/torchrl/envs/libs/gym.py", line 784, in __init__
    super().__init__(**kwargs)
  File "/pytorch/rl/torchrl/envs/common.py", line 3047, in __init__
    self._env = self._build_env(**kwargs)  # writes the self._env attribute
  File "/pytorch/rl/torchrl/envs/libs/gym.py", line 1423, in _build_env
    env = self.lib.make(env_name, **kwargs)
  File "/pytorch/rl/env/lib/python3.9/site-packages/gym/envs/registration.py", line 676, in make
    return registry.make(id, **kwargs)
  File "/pytorch/rl/env/lib/python3.9/site-packages/gym/envs/registration.py", line 518, in make
    spec = self.spec(path)
  File "/pytorch/rl/env/lib/python3.9/site-packages/gym/envs/registration.py", line 540, in spec
    return self.env_specs[id]
  File "/pytorch/rl/env/lib/python3.9/site-packages/gym/envs/registration.py", line 376, in __getitem__
    self._assert_version_exists(namespace, name, version)
  File "/pytorch/rl/env/lib/python3.9/site-packages/gym/envs/registration.py", line 369, in _assert_version_exists
    raise error.VersionNotFound(message)
gym.error.VersionNotFound: Environment version `v4` for `HalfCheetah` could not be found. `HalfCheetah` provides the versioned environments: [ `v2`, `v3` ].

@vmoens
Copy link
Contributor

vmoens commented Aug 5, 2024

Still an error in the CI

  File "/pytorch/rl/sota-implementations/gail/gail.py", line 281, in <module>
    main()
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/main.py", line 94, in decorated_main
    _run_hydra(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 394, in _run_hydra
    _run_app(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 457, in _run_app
    run_and_report(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 223, in run_and_report
    raise ex
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/utils.py", line 458, in <lambda>
    lambda: hydra.run(
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/_internal/hydra.py", line 132, in run
    _ = ret.return_value
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/core/utils.py", line 260, in return_value
    raise self._return_value
  File "/pytorch/rl/env/lib/python3.9/site-packages/hydra/core/utils.py", line 186, in run_job
    ret.return_value = task_function(task_cfg)
  File "/pytorch/rl/sota-implementations/gail/gail.py", line 168, in main
    expert_data.set(
  File "/pytorch/rl/env/lib/python3.9/site-packages/tensordict/base.py", line 4294, in set
    return self._set_tuple(
  File "/pytorch/rl/env/lib/python3.9/site-packages/tensordict/_td.py", line 2216, in _set_tuple
    return self._set_str(
  File "/pytorch/rl/env/lib/python3.9/site-packages/tensordict/_td.py", line 2164, in _set_str
    value = self._validate_value(
  File "/pytorch/rl/env/lib/python3.9/site-packages/tensordict/base.py", line 8553, in _validate_value
    raise RuntimeError(
RuntimeError: batch dimension mismatch, got self.batch_size=torch.Size([256]) and value.shape=torch.Size([16, 6]).

I will try to patch it

@vmoens vmoens merged commit 4348c84 into pytorch:main Aug 6, 2024
59 of 68 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