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

Add tutorials for using the training script and #196

Merged
merged 15 commits into from
May 21, 2024

Conversation

alexander-soare
Copy link
Collaborator

What this does

  • Adds a 4th basic tutorial that explains the training script, and particularly how to navigate the Hydra config system
  • Adds an advanced tutorial for training policies with different environments/datsets
  • Updates Makefile to test the advanced tutorial
  • Side mission: Some tweaks in the main README

@alexander-soare alexander-soare added the 📝 Documentation Improvements or additions to documentation label May 17, 2024
@Cadene Cadene requested review from aliberts and Cadene and removed request for aliberts May 17, 2024 17:05
Copy link
Collaborator

@Cadene Cadene left a comment

Choose a reason for hiding this comment

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

Will continue review tonight


Explaining the ins and outs of [Hydra](https://hydra.cc/docs/intro/) is beyond the scope of this document, but here we'll share the main points you need to know.

First, consider that `lerobot/configs` might have a directory structure like this (this is the case at the time of writing):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
First, consider that `lerobot/configs` might have a directory structure like this (this is the case at the time of writing):
First, `lerobot/configs` has a directory structure like this:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd like this to be more concrete as well. But being a little vague allows room for error as this is a very not-maintainable bit of documentation.

@aliberts do you think we can use a tool like this in CI? https://github.com/UmbrellaDocs/linkspector. That might help a little bit, and we can make it that all things like lerobot/configs have to include a link

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Cadene I made my sentence less apologetic, leaving just one "might".

Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think we should use "might". We should tell exactly what is expected. No?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Did might -> will (everywhere), and used "like" or "something like". There may be minor refactors that have no bearing on the essentials that this document tries to convey, so I don't want the language to overly-commit.


**_For brevity, in the rest of this document we'll drop the leading `lerobot/configs` path. So `default.yaml` really refers to `lerobot/configs/default.yaml`._**

When you run the training script, Hydra takes over via the `@hydra.main` decorator. If you take a look at the `@hydra.main`'s arguments you will see `config_path="../configs", config_name="default"`. This means Hydra looks for `default.yaml` in `../configs` (which resolves to `lerobot/configs`).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would suggest to first give one or more examples, before delving into this complex details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure what examples to add that would build the reader up to understanding this point any better. I've added a couple of lines that might help with train-of-thought. Let me know if you have a better approach.

Comment on lines 36 to 45
Among regular configuration hyperparameters like `device: cuda`, `default.yaml` has a `defaults` section. It might look like this.

```yaml
defaults:
- _self_
- env: pusht
- policy: diffusion
```

So, Hydra will grab `env/pusht.yaml` and `policy/diffusion.yaml` and incorporate their configuration parameters (any configuration parameters already present in `default.yaml` are overriden).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion
"""
default.yaml is always the entry point. It begins by a defaults section likes this:

defaults:
  - _self_
  - env: pusht
  - policy: diffusion

It means that Hydra will grab env/pusht.yaml and policy/diffusion.yaml and incorporate their configuration parameters (any configuration parameters already present in default.yaml are overriden).

After this defaults section, default.yaml also contains regular configuration hyperparameters like device: cuda, or .... TODO.
"""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done, with some further tweaks.

examples/4_train_policy_with_script.md Outdated Show resolved Hide resolved
examples/4_train_policy_with_script.md Outdated Show resolved Hide resolved
examples/4_train_policy_with_script.md Outdated Show resolved Hide resolved
examples/4_train_policy_with_script.md Outdated Show resolved Hide resolved
@@ -0,0 +1,157 @@
This tutorial will explain the training script, how to use it, and particularly the use of Hydra to configure everything needed for the training run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This in-depth tutorial is important, but it would be nice to have a specific markdown file called: 5_reproduce_sota.md with a structured list of training commands + pointers to our model page on the hub + evaluation commands of the pretrained models.

# Table of results

TODO Table with link to model page on the hub + link to section in the markdown file

## Diffusion policy on Pusht

Model card on the hub:

Training command:

TODO


Eval Command

TODO


## Aloha

...


Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think this is a good idea. It adds more not-maintainable documentation. These details live with the model cards and I don't think they should be repeated elsewhere. IMO, we should just have a zoo.md style file that points to the model cards.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think of adding a 5_reproduce_sota.md which would be a tutorial on how to access the model card list, and how from the model card, access the training command?

Maybe long term with can avoid this maintainable documentation, but right now I have no idea how to access these training commands.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How about I put the commands on the model cards. Then you have command, configuration, and commit hash all in one place. Then I can add a section in the main README to talk about the model cards.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@alexander-soare Yes! Should we do this in this PR?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@alexander-soare A thought: ideally we should have a script to push model card in a standardize format to the hub

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added to this PR.

On your thought: I suppose... it's a one-liner right now, so a script doesn't add much value right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

How to have a script that generates this:

Screenshot 2024-05-21 at 16 49 39

Copy link
Collaborator

Choose a reason for hiding this comment

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

For your info, I will add a logic to automatically populate and tag the dataset card as well. For now they are empty

Screenshot 2024-05-21 at 16 50 44

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah for the README. Yeah that's a good idea :)

examples/advanced/train_act_pusht/train_act_pusht.sh Outdated Show resolved Hide resolved
@@ -0,0 +1,62 @@
In this tutorial we will adapt the default configuration for ACT to be compatible with the PushT environment and dataset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this tutorial is too difficult to follow. It's a good start, but we should iterate to simplify as much as possible.

Ideally we should just provide the script to train act on pusht, and comment as much as possible.
And also to provide the script to train diffusion policy on aloha.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unfortunately, the yaml file is necessary because the observation key changes via the CLI are challenging due to the "." separator and the nested lists. So we'd need two files at least.

I like the MD file as it allows for a more tutorial style voice and structure.

What do you think we could do to make it easier to follow?

Why should we also provide the script for DP / Aloha? What value does it add over one example that gets the point across?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont know exactly know, but we should try to compress the information.
When it's too long, people dont read.

I am just sharing high level thoughts sorry ^^'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've had a read through again and couldn't find any obvious ways to cut it. How about we leave it to user testing (aka merge it and see how people interact with it).

Copy link
Collaborator

@Cadene Cadene left a comment

Choose a reason for hiding this comment

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

Thanks for iterating on this! it's super important :)

@@ -0,0 +1,157 @@
This tutorial will explain the training script, how to use it, and particularly the use of Hydra to configure everything needed for the training run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think of adding a 5_reproduce_sota.md which would be a tutorial on how to access the model card list, and how from the model card, access the training command?

Maybe long term with can avoid this maintainable documentation, but right now I have no idea how to access these training commands.

examples/4_train_policy_with_script.md Outdated Show resolved Hide resolved
@@ -0,0 +1,62 @@
In this tutorial we will adapt the default configuration for ACT to be compatible with the PushT environment and dataset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont know exactly know, but we should try to compress the information.
When it's too long, people dont read.

I am just sharing high level thoughts sorry ^^'

Copy link
Collaborator

@Cadene Cadene left a comment

Choose a reason for hiding this comment

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

Nice work! Left some suggestions. Approve to unblock as this PR only needs minor changes.

examples/4_train_policy_with_script.md Show resolved Hide resolved
@@ -0,0 +1,157 @@
This tutorial will explain the training script, how to use it, and particularly the use of Hydra to configure everything needed for the training run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alexander-soare Yes! Should we do this in this PR?

@@ -0,0 +1,157 @@
This tutorial will explain the training script, how to use it, and particularly the use of Hydra to configure everything needed for the training run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alexander-soare A thought: ideally we should have a script to push model card in a standardize format to the hub

Comment on lines 40 to 42
Hydra takes over via the `@hydra.main` decorator. If you take a look at the `@hydra.main`'s arguments you will see `config_path="../configs", config_name="default"`. This means Hydra looks for `default.yaml` in `../configs` (which resolves to `lerobot/configs`).

Therefore, `default.yaml` is the first configuration file that Hydra considers. At the top of the file, is a `defaults` section which looks likes this:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would simplify

Suggested change
Hydra takes over via the `@hydra.main` decorator. If you take a look at the `@hydra.main`'s arguments you will see `config_path="../configs", config_name="default"`. This means Hydra looks for `default.yaml` in `../configs` (which resolves to `lerobot/configs`).
Therefore, `default.yaml` is the first configuration file that Hydra considers. At the top of the file, is a `defaults` section which looks likes this:
Hydra is setup to read the `default.yaml` (through the `@hydra.main` decorator in [`train.py`](https://github.com/huggingface/lerobot/blob/main/lerobot/scripts/train.py#L143)). At the top of the yaml file, is a `defaults` section which looks likes this:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

- policy: diffusion
```

So, Hydra then grabs `env/pusht.yaml` and `policy/diffusion.yaml` and incorporates their configuration parameters as well (any configuration parameters already present in `default.yaml` are overriden).
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would simplify

Suggested change
So, Hydra then grabs `env/pusht.yaml` and `policy/diffusion.yaml` and incorporates their configuration parameters as well (any configuration parameters already present in `default.yaml` are overriden).
This logic tells Hydra to incorporate configuration parameters from `env/pusht.yaml` and `policy/diffusion.yaml`.

I am hesitating to add this with an example but it should be self explanatory. When you see training.offline_steps: ??? you can guess it should be overriden. And besides this use case, which explicitly indicates an inheritance, we want to avoid override as much as possible.

Note: Be aware of the order as any configuration parameters with the same name will be overidden. Thus, `default.yaml` is overriden by `env/pusht.yaml`  which is overidden by `policy/diffusion.yaml`.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a default for dataset_repo_id in order to match the policy and env defaults (I'm assuming... I didn't actually set this up).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will take your suggestions including the override disclaimer.

we want to avoid override as much as possible.

We can do this by removing a bunch of params in default.yaml. Let's make that a different PR though, this one's gone on long enough.

examples/4_train_policy_with_script.md Show resolved Hide resolved
Comment on lines +151 to +153
There's one new thing here: `hydra.run.dir=outputs/train/act_aloha_sim_transfer_cube_human`, which specifies where to save the training output.

---
Copy link
Collaborator

Choose a reason for hiding this comment

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

@alexander-soare Could we have a section on how to load from a config yaml file inside an experiment checkpoint?
Is such a thing even possible?

This would justify why we prefer to have these multi lines commands.

We might want to say that when we diverge too much from the original parameters from the yaml files, then it can be handy to write them down in a new yaml files.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by "load from a config yaml file inside an experiment checkpoint". I do have a PR in the works that does checkpointing and training resumption, and I plan to add a section here on how to resume training.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to be able to reproduce an experiments by loading its config yaml inside its experiment directory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh, yeah that's a pain with Hydra because of the way that hydra.main decorator works. Maybe there's a way...

@@ -0,0 +1,64 @@
In this tutorial we will learn how to adapt a policy configuration to be compatible with a new environment and dataset. As a concrete example, we will adapt the default configuration for ACT to be compatible with the PushT environment and dataset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we do:

Could we have this?
advanced/0_train_act_pusht.md
advanced/1_calculate_validation_loss.py
advanced/ressources/act_pusht.yaml

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. I prefer not to number the advanced tutorials as they don't need to be done in any specific order. On the other hand, I think the basic tutorials have a nice order. What do you think?
  2. I think it's clearer to bundle everything needed for one example into one directory (ptal at transformers https://github.com/huggingface/transformers/tree/main/examples/pytorch/audio-classification)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think our examples are the same as in transformers. I would prefer to keep the indices at the begining.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

examples/4_train_policy_with_script.md Show resolved Hide resolved

_Side note: technically we could override these via the CLI, but with many changes it gets a bit messy, and we also have a bit of a challenge in that we're using `.` in our observation keys which is treated by Hydra as a hierarchical separator_.

For your convenience, we provide [`act_pusht.yaml`](./act_pusht.yaml) in this directory. It contains the diff above, plus some other (optional) ones that are explained within. Please copy it into `lerobot/configs/policy` (remember from a [previous tutorial](../4_train_policy_with_script.md) that Hydra will look in the `lerobot/configs` directory). Now try running the following.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion:

"""
For your convenience, we provide act_pusht.yaml in the ressources directory. It contains the diff above, plus some other (optional) ones that are explained within. Please copy it into lerobot/configs/policy with:

cp examples/advanced/ressources/act_pusht.yaml lerobot/configs/policy/act_pusht.yaml

Note: We need to perform this copy because Hydra is set to look in the lerobot/configs directory (see previous tutorial if needed).

Now try running the following:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought you wanted to cut this file down :P I prefer not to add a copy command (especially one that needs maintenance because of the paths in it).

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's much clearer than "copy this to this directory". We will need to add unit tests to these tutorials anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair enough. Done.

Copy link
Collaborator

@Cadene Cadene left a comment

Choose a reason for hiding this comment

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

Really cool, back to you and we are good.

README.md Outdated Show resolved Hide resolved
Comment on lines +151 to +153
There's one new thing here: `hydra.run.dir=outputs/train/act_aloha_sim_transfer_cube_human`, which specifies where to save the training output.

---
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to be able to reproduce an experiments by loading its config yaml inside its experiment directory.

@@ -0,0 +1,64 @@
In this tutorial we will learn how to adapt a policy configuration to be compatible with a new environment and dataset. As a concrete example, we will adapt the default configuration for ACT to be compatible with the PushT environment and dataset.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I dont think our examples are the same as in transformers. I would prefer to keep the indices at the begining.


_Side note: technically we could override these via the CLI, but with many changes it gets a bit messy, and we also have a bit of a challenge in that we're using `.` in our observation keys which is treated by Hydra as a hierarchical separator_.

For your convenience, we provide [`act_pusht.yaml`](./act_pusht.yaml) in this directory. It contains the diff above, plus some other (optional) ones that are explained within. Please copy it into `lerobot/configs/policy` (remember from a [previous tutorial](../4_train_policy_with_script.md) that Hydra will look in the `lerobot/configs` directory). Now try running the following.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's much clearer than "copy this to this directory". We will need to add unit tests to these tutorials anyway.

examples/4_train_policy_with_script.md Show resolved Hide resolved
@@ -0,0 +1,157 @@
This tutorial will explain the training script, how to use it, and particularly the use of Hydra to configure everything needed for the training run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

How to have a script that generates this:

Screenshot 2024-05-21 at 16 49 39

@@ -0,0 +1,157 @@
This tutorial will explain the training script, how to use it, and particularly the use of Hydra to configure everything needed for the training run.
Copy link
Collaborator

Choose a reason for hiding this comment

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

For your info, I will add a logic to automatically populate and tag the dataset card as well. For now they are empty

Screenshot 2024-05-21 at 16 50 44

alexander-soare and others added 3 commits May 21, 2024 15:54
Co-authored-by: Remi <re.cadene@gmail.com>
@alexander-soare alexander-soare merged commit e67da1d into huggingface:main May 21, 2024
5 checks passed
@alexander-soare alexander-soare deleted the tutorial_act_pusht branch May 21, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants