-
Notifications
You must be signed in to change notification settings - Fork 240
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
Add tutorials for using the training script and #196
Conversation
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.
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): |
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.
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: |
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.
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
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.
@Cadene I made my sentence less apologetic, leaving just one "might".
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.
I dont think we should use "might". We should tell exactly what is expected. No?
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.
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`). |
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.
I would suggest to first give one or more examples, before delving into this complex details.
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.
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.
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). |
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.
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.
"""
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.
Done, with some further tweaks.
@@ -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. |
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.
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
...
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.
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.
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.
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.
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.
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.
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.
@alexander-soare Yes! Should we do this in this PR?
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.
@alexander-soare A thought: ideally we should have a script to push model card in a standardize format to the hub
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.
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?
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.
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.
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.
Ah for the README. Yeah that's a good idea :)
@@ -0,0 +1,62 @@ | |||
In this tutorial we will adapt the default configuration for ACT to be compatible with the PushT environment and dataset. |
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.
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.
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.
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?
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.
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 ^^'
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.
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).
68ee968
to
43ebb30
Compare
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.
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. |
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.
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.
@@ -0,0 +1,62 @@ | |||
In this tutorial we will adapt the default configuration for ACT to be compatible with the PushT environment and dataset. |
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.
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 ^^'
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.
Nice work! Left some suggestions. Approve to unblock as this PR only needs minor changes.
@@ -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. |
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.
@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. |
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.
@alexander-soare A thought: ideally we should have a script to push model card in a standardize format to the hub
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: |
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.
I would simplify
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: |
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.
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). |
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.
I would simplify
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`.
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.
@alexander-soare why is there a default for dataset_repo_id?
https://github.com/huggingface/lerobot/blob/main/lerobot/configs/default.yaml#L19
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.
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).
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.
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.
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. | ||
|
||
--- |
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.
@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.
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.
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.
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.
It would be nice to be able to reproduce an experiments by loading its config yaml inside its experiment directory.
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.
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. |
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.
Could we do:
Could we have this?
advanced/0_train_act_pusht.md
advanced/1_calculate_validation_loss.py
advanced/ressources/act_pusht.yaml
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.
- 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?
- 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)
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.
I dont think our examples are the same as in transformers. I would prefer to keep the indices at the begining.
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.
Done.
|
||
_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. |
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.
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:
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.
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).
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.
It's much clearer than "copy this to this directory". We will need to add unit tests to these tutorials anyway.
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.
Fair enough. Done.
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.
Really cool, back to you and we are good.
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. | ||
|
||
--- |
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.
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. |
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.
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. |
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.
It's much clearer than "copy this to this directory". We will need to add unit tests to these tutorials anyway.
@@ -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. |
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.
@@ -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. |
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.
Co-authored-by: Remi <re.cadene@gmail.com>
What this does