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 headings to weights table. #6139

Closed
wants to merge 19 commits into from
Closed

Conversation

abhi-glitchhg
Copy link
Contributor

@abhi-glitchhg abhi-glitchhg commented Jun 8, 2022

Related to #6126 and #6131

Here is my attempt.

fix build docs jobs
@NicolasHug
Copy link
Member

This creates the following error in the doc build:

Warning, treated as error:
/home/circleci/project/docs/source/models.rst:263:Title level inconsistent:

Table of all available quantized classification weights
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
make: *** [Makefile:42: html] Error 2

@abhi-glitchhg

This comment was marked as resolved.

@abhi-glitchhg

This comment was marked as outdated.

@NicolasHug
Copy link
Member

Thanks for the PR @abhi-glitchhg but I think the current solution adds titles below the tables: https://output.circle-artifacts.com/output/job/7b9d5b75-850e-4421-acd7-d4f7b6fa314f/artifacts/0/docs/models.html#classification-weights-table

@abhi-glitchhg

This comment was marked as outdated.

@NicolasHug
Copy link
Member

NicolasHug commented Jun 13, 2022

I think the problem is just reversed now, the title is above the table but we still have duplicated titles which is redundant:

image

Any chance we can tell the table to use the first title as its title in the search?

@abhi-glitchhg
Copy link
Contributor Author

Any chance we can tell the table to use the first title as its title in the search?

I think I can do that.

@abhi-glitchhg abhi-glitchhg marked this pull request as draft June 13, 2022 17:31
@abhi-glitchhg abhi-glitchhg marked this pull request as ready for review June 14, 2022 17:37
@abhi-glitchhg

This comment was marked as outdated.

@NicolasHug
Copy link
Member

NicolasHug commented Jun 16, 2022

I would prefer not to change the current heading levels and keep what we currently have in https://pytorch.org/vision/main/models.html

image

@datumbox
Copy link
Contributor

@NicolasHug True but is this possible? Aka if you add headings aren't those going to automatically be appeared to the heading levels?

@NicolasHug
Copy link
Member

Yes, which is why ideally we would find a way to tell the table to just use its section title as title #6139 (comment)

This way we don't have to add another heading level.

@abhi-glitchhg
Copy link
Contributor Author

I would prefer not to change the current heading levels and keep what we currently have in https://pytorch.org/vision/main/models.html

Thanks! Then I think I am done, please check the docs and let me know.

@datumbox
Copy link
Contributor

@abhi-glitchhg Push!!! :)

Comment on lines +414 to +417
table_file.write(
f"Table of all available {table_name.replace('_',' ').title()} Weights \n{(32 + len(table_name))*title_character}\n"
)
table_file.write(f"{table_description}\n\n")
Copy link
Member

Choose a reason for hiding this comment

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

IIUC this is the same as before but instead of writing these lines in the .rst file (as preferred), we're now generating it here and writing it in the table files.

Could you explain what the difference is, and why it "works"?

Copy link
Contributor Author

@abhi-glitchhg abhi-glitchhg Jun 16, 2022

Choose a reason for hiding this comment

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

IIUC this is the same as before, but instead of writing these lines in the .rst file (as preferred), we're now generating it here and writing it in the table files.

Yes, you are right!

So there was no title/headings in the generated table rst files, that is why we were getting results like below.
(notice the <no title>)

image

So to solve this, we needed to add the titles in the generated table files and not manually write them in models.rst.
And the descriptions for the tables should be written after the headings. So there was no choice but to add the description in the generated table rst.

So, I have shifted the title and description of tables from models.rst to generated table rst files. Otherwise, there is no difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NicolasHug, any updates on this?

Copy link
Member

Choose a reason for hiding this comment

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

Hi @abhi-glitchhg , sorry for the late reply

I'm a little uncomfortable with this solution because it makes our solution slightly more complex and somewhat hides the structure of the models.rst file, which now also depends on the auto-generation code in conf.py. On top of that it's not really clear why this works while the our original solution doesn't.

It feels like we're patching a limitation of sphinx's search by working around it, without addressing the actual core of the issue. Did we figure out why writing the title within the file makes the search render better?

BTW, the search still looks like this:

image

which is better because we have the title, but it still looks broken. Considering how much time we have spent on this already (especially you!), I wonder if it's worth continuing trying to fix this. It seems to me like a benign issue to begin with.

Copy link
Contributor Author

@abhi-glitchhg abhi-glitchhg Aug 11, 2022

Choose a reason for hiding this comment

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

It feels like we're patching a limitation of sphinx's search by working around it without addressing the actual core of the issue. Did we figure out why writing the title within the file makes the search render better?

Yeah maybe!

which is better because we have the title, but it still looks broken.

Agree! Closing this pr as it doesn't properly solve the issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe someone with a good understanding of the sphinx theme could have a look at this!

maybe @ain-soph (sorry for shameless tagging, i really liked how you modified the theme for your project) If you have spare time ;-;

@datumbox
Copy link
Contributor

datumbox commented Aug 8, 2022

@abhi-glitchhg I am very sorry that none of our team got back to you. Many of us had our annual leaves this period and your PR fell through the cracks. :( Let me ping Nicolas tomorrow internally and try to get you some feedback.

@abhi-glitchhg
Copy link
Contributor Author

abhi-glitchhg commented Aug 8, 2022 via email

@abhi-glitchhg abhi-glitchhg reopened this Aug 8, 2022
@ain-soph
Copy link
Contributor

ain-soph commented Aug 11, 2022

@abhi-glitchhg Thanks for getting me involved. I just went through the PR, and it seems the current problem is that we prefer table context/titles coded in .rst files rather than conf.py. (I agree this as well. Furthermore, it seems strange to me that we call this generate_weights_table method to create tables in conf.py since this file should only contains configurations and utility functions.)

I think a better idea might be to register a new sphinx directive to parse tables in setup()? It shall be doable in conf.py without touching theme package. Later we can apply the new directive in .rst files and pass content-related arguments there. (The same process as autosummary)

In current architecture, it's a python method rather than a sphinx directive, which forces it to be called in conf.py.

@abhi-glitchhg abhi-glitchhg deleted the docs branch August 11, 2022 18:42
@NicolasHug
Copy link
Member

I think a better idea might be to register a new sphinx domain to parse tables in setup()? It shall be doable in conf.py without touching theme package. Later we can apply the new domain in .rst files and pass content-related arguments there. (The same process as autosummary)

Thanks for your insights @ain-soph . I'm happy to refactor our implementation to something more standard / canonical, as long as it's not too complex or overkill. Out of curiosity, do you believe this would solve our "table title in search rendering issue" ?

@ain-soph
Copy link
Contributor

ain-soph commented Aug 12, 2022

@NicolasHug

Here is how to set the table title (very simple):

I see you already tried that in previous PR.

https://stackoverflow.com/questions/53191945/how-can-i-add-a-caption-to-a-restructuredtext-table

And for the <no-title> shown in the search page, that’s actually because section name of the generated rst page is not set. (Not related to the table directive name. Therefore, @NicolasHug ‘s previous PR doesn’t solve the no title issue.)

@abhi-glitchhg has already solved that correctly by setting the section name of the generated page.

<section name>
—————————————————————

@abhi-glitchhg abhi-glitchhg restored the docs branch August 12, 2022 22:33
@abhi-glitchhg
Copy link
Contributor Author

Ok ill give this one more try!
Thanks a lot, @ain-soph for the directions!

@abhi-glitchhg abhi-glitchhg reopened this Aug 12, 2022
@ain-soph
Copy link
Contributor

ain-soph commented Aug 12, 2022

@abhi-glitchhg Nah, I think adding the table title won’t help anything. You have already solved the no title issue in your previous commits.

I think the current issue from maintainers is that: those content-related texts are put into conf.py, which violates the initial purpose of this configuration file. (Actually they call this generation method in this file already violated the convention.)

My suggestion is to implement a new small plugin which contains a new sphinx directive and register it in conf.py. The plug-in will be highly similar to autosummary that preprocess your auto rst files and generate the real table rst files.

@abhi-glitchhg
Copy link
Contributor Author

oh I misunderstood your previous message. Thanks for pointing it out.

My suggestion is to implement a new small plugin which contains a new sphinx directive and register it in conf.py. The plug-in will be highly similar to autosummary that preprocess your auto rst files and generate the real table rst files.

I do not have much knowledge of implementing this, So closing this pr [I promise wont open this pr again 🤭 ]

If anyone wants to resolve this, feel free to supersede me. Thanks.

@ain-soph
Copy link
Contributor

I shall be available to work on this after finishing the issue at #6224

Maybe 1 month later?

@abhi-glitchhg abhi-glitchhg deleted the docs branch January 27, 2023 20:32
@abhi-glitchhg abhi-glitchhg restored the docs branch January 27, 2023 20:40
@abhi-glitchhg abhi-glitchhg deleted the docs branch July 12, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants