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

Restructure the minimal examples section [DOC-144] #200

Merged
merged 24 commits into from
Aug 7, 2023

Conversation

lebrice
Copy link
Contributor

@lebrice lebrice commented Jul 5, 2023

Les autres PR d'exemples minimalistes devraient être rebase sur ces changements (ou bien merge ces commits). Cette PR-là change un peu la structure de la section d'exemples minimalistes:

  • le nom des fichiers passe de _index.rst --> index.rst
  • Les exemples ne se trouvent plus tous dans la même page
  • Améliore l'auto-génération des README.rst pour voir les exemples sur GitHub:
    • Ajoute un header dans le fichier README.rst auto-généré pour dire que le contenu ne devrait pas être modifié, et indiquer la source
    • Force chaque exemple a contenir un lien vers le code source sur GitHub.
    • Fix l'indentation à trois espaces

@lebrice lebrice changed the title Restructuring the minimal examples section Restructure the minimal examples section Jul 5, 2023
@lebrice lebrice marked this pull request as ready for review July 5, 2023 18:17
@lebrice lebrice requested a review from gyom July 5, 2023 18:18
@lebrice lebrice force-pushed the lebrice/fix_examples_structure branch 2 times, most recently from 93cbb86 to 68e20f3 Compare July 5, 2023 19:16
@lebrice lebrice mentioned this pull request Jul 6, 2023
@lebrice lebrice force-pushed the lebrice/fix_examples_structure branch 2 times, most recently from 60ee7db to 1b3fbb7 Compare July 7, 2023 19:11
Copy link
Member

@satyaog satyaog left a comment

Choose a reason for hiding this comment

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

If you don't agree with the suggestions I'll change my review to approved ;)

(you can batch all the changes you would like in a single commit btw)

.gitignore Outdated Show resolved Hide resolved
docs/Minimal_examples.rst Outdated Show resolved Hide resolved
docs/Minimal_examples.rst Outdated Show resolved Hide resolved
Comment on lines 18 to 22
.. toctree::
:maxdepth: 1

examples/frameworks/index
examples/distributed/index
examples/good_practices/index
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this go in doc/index.rst instead so we can see all of the sections from the home page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting idea, I'll try it out.

Copy link
Contributor Author

@lebrice lebrice Jul 31, 2023

Choose a reason for hiding this comment

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

I'm unable to make this work locally. Perhaps I'm doing something wrong. Did you mean to remove the toctree here instead have something like this in the index.rst?

.. toctree::
   :caption: Minimal Examples
   :maxdepth: 2

   Minimal_examples
   examples/frameworks/index
   examples/distributed/index
   examples/good_practices/index

If so, this doesn't seem to work correctly, there is still only "Minimal Examples" under the "MINIMAL EXAMPLES" section in the left navbar.
Perhaps we could check this out together sometime this week if you don't mind? (I'm pretty bad at this)

Copy link
Contributor Author

@lebrice lebrice Jul 31, 2023

Choose a reason for hiding this comment

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

Oh also: I think that using .. include would make them all end up in the same page, right? (Not sure if that would be part of the potential solution, but I wouldn't want that to happen here with the examples)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 0f5ddd0

docs/examples/distributed/multi_gpu/index.rst Outdated Show resolved Hide resolved
docs/examples/good_practices/index.rst Outdated Show resolved Hide resolved
docs/examples/frameworks/index.rst Outdated Show resolved Hide resolved
docs/examples/frameworks/pytorch_setup/README.rst Outdated Show resolved Hide resolved
docs/examples/distributed/index.rst Show resolved Hide resolved
docs/examples/frameworks/pytorch_setup/index.rst Outdated Show resolved Hide resolved
docs/Minimal_examples.rst Outdated Show resolved Hide resolved
@lebrice lebrice force-pushed the lebrice/fix_examples_structure branch from 10c220b to f3d940c Compare July 24, 2023 17:08
@lebrice lebrice requested a review from obilaniu July 24, 2023 21:03
@lebrice lebrice mentioned this pull request Jul 27, 2023
Merged
docs/Minimal_examples.rst Outdated Show resolved Hide resolved
docs/Minimal_examples.rst Outdated Show resolved Hide resolved
@lebrice lebrice changed the title Restructure the minimal examples section Restructure the minimal examples section [DOC-144] Aug 1, 2023
@lebrice lebrice requested a review from breuleux August 1, 2023 16:00
Comment on lines 156 to 157
elif line.startswith(".. literalinclude:: ") or not line:
break
Copy link
Member

Choose a reason for hiding this comment

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

This seems a bit brittle as a way to figure out where the block ends, compared to simply checking if the (non-stripped) line starts with a non-space character.

Copy link
Contributor Author

@lebrice lebrice Aug 2, 2023

Choose a reason for hiding this comment

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

Fixed in 4bc0bae

docs/examples/preprocess.py Outdated Show resolved Hide resolved
Comment on lines +27 to +40
generate_diff distributed/single_gpu/job.sh distributed/multi_gpu/job.sh
generate_diff distributed/single_gpu/main.py distributed/multi_gpu/main.py

# multi_gpu -> multi_node
generate_diff distributed/002_multi_gpu/job.sh distributed/003_multi_node/job.sh
generate_diff distributed/002_multi_gpu/main.py distributed/003_multi_node/main.py
generate_diff distributed/multi_gpu/job.sh distributed/multi_node/job.sh
generate_diff distributed/multi_gpu/main.py distributed/multi_node/main.py

# single_gpu -> checkpointing
generate_diff distributed/001_single_gpu/job.sh good_practices/checkpointing/job.sh
generate_diff distributed/001_single_gpu/main.py good_practices/checkpointing/main.py
generate_diff distributed/single_gpu/job.sh good_practices/checkpointing/job.sh
generate_diff distributed/single_gpu/main.py good_practices/checkpointing/main.py

# single_gpu -> hpo_with_orion
generate_diff distributed/001_single_gpu/job.sh good_practices/hpo_with_orion/job.sh
generate_diff distributed/001_single_gpu/main.py good_practices/hpo_with_orion/main.py
generate_diff distributed/single_gpu/job.sh good_practices/hpo_with_orion/job.sh
generate_diff distributed/single_gpu/main.py good_practices/hpo_with_orion/main.py
Copy link
Member

Choose a reason for hiding this comment

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

Could we loop over **/job.sh and **/main.py instead, so we don't have to remember to update this file whenever we add a new example?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps I don't understand, but here we need to define the from-to relationship between examples. How do you suggest we do that automatically?

Copy link
Member

Choose a reason for hiding this comment

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

Ah yeah I had a brain fart here, sorry.

Although, one way to do this automatically would be to represent the examples as a Git arborescence: you write the code for single_gpu, then you create a multi_gpu branch that has one commit that is the difference, and so on, each example being its own branch. Then you can run a series of checkouts and cp to populate the examples directory in the actual docs repo. With this method you can also update the whole set of examples more easily by changing the base and looping on git rebase. But in any case this is out of scope for this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's interesting!

I also played around with the idea of us editing the .diff files directly instead of the example files, and re-generating the derived examples if something changes in the base.

For now, with this limited number example dependencies, it's pretty manageable to make a change in the base example and then copy-paste it to the 5-6 derived examples. However there is potentially a better solution in the long run for sure.
I agree with you, I don't think it's worth it to spend too much time working on that right now.

f" {_l}".rstrip(" ")
for _l in (docs_root / path).read_text().split("\n")
]
content_lines = content_lines[:i] + insert + content_lines[i + 1 :]
Copy link
Member

Choose a reason for hiding this comment

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

This drops content_lines[i], is this what we want? We already removed the literalinclude lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 4bc0bae

@lebrice lebrice force-pushed the lebrice/fix_examples_structure branch from 71f5b94 to cd154ff Compare August 2, 2023 18:10
Comment on lines 190 to 198
def _get_block_length() -> int:
length = 1
while (
line_index + length < len(content_lines)
and content_lines[line_index + length]
and not content_lines[line_index + length].isspace()
):
length += 1
return length
Copy link
Member

Choose a reason for hiding this comment

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

I haven't tested so maybe I'm following the code wrong, but you only stop on empty/whitespace lines, so it seems to me that the function will return 4 on the following block:

.. literalinclude:: x.py
  :language: python
.. important::
  Don't run vscode on the login nodes you guys.

And 1 on this one, which I'm not certain is legal or not:

.. literalinclude:: x.py

  :language: python

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: 806c59d

@lebrice lebrice merged commit 6c4797b into mila-iqia:master Aug 7, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Aug 16, 2023
satyaog added a commit to satyaog/mila-docs that referenced this pull request Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants