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

API management and documentation mechanisms #1701

Merged
merged 23 commits into from
Apr 27, 2023

Conversation

vshampor
Copy link
Contributor

@vshampor vshampor commented Apr 12, 2023

Changes

Added a decorator for marking entities as API and a set of Github actions to check whether a PR changes API (if so, then the PR will be automatically labeled as such) and to generate and push API documentation automatically to Github pages using Sphinx, AutoAPI (by readthedocs) and custom API name collection code.

Reason for changes

Both devs and users will finally have an understanding of what is considered API and what is not, and have an opportunity to browse API documentation without having to look into source code.

Related tickets

99696

Tests

N/A

@github-actions github-actions bot added documentation Improvements or additions to documentation NNCF Common Pull request that updates NNCF Common NNCF ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch NNCF TF Pull requests that updates NNCF TensorFlow labels Apr 12, 2023
@vshampor vshampor force-pushed the api_doc_gen branch 6 times, most recently from b668f1c to e686418 Compare April 13, 2023 15:16
@github-actions github-actions bot removed the NNCF OpenVINO Pull requests that updates NNCF OpenVINO label Apr 13, 2023
@vshampor vshampor changed the title Api doc gen API management and documentation mechanisms Apr 13, 2023
@vshampor vshampor marked this pull request as ready for review April 13, 2023 16:11
@vshampor
Copy link
Contributor Author

I had to experiment on my fork to properly debug the Github actions. The end result on Github pages would look like this:
https://vshampor.github.io/nncf/

(It used to be that this page contained only the schema, and now it has been extended to API docs. The schema is still there at https://vshampor.github.io/nncf/schema)

The page contains only the description of entities that were decorated with @api() and of the containing Python modules in the import path. The module descriptions are currently licenses, because we actually currently use the module docstrings to store licenses (will fix this by moving license content to comments and setting up proper docstrings for API-impacted modules). The class and function descriptions may have invalid formatting in HTML and missing descriptions - all this is fixable by adding or reformatting corresponding docstrings which will be done in a follow-up PR.

For demo of auto PR labeling, see:
vshampor#6 - modification of an API function signature, PR was marked as API automatially
vshampor#7 - addition of an API entity when compared to the develop state, PR was marked as API automatically
vshampor#8 - a change inside an API function that does not explicitly impact API as seen by the external user, PR was not marked as API automatically - it is up to reviewers to determine whether such PR changes API behaviour or not.

NB: automatic PR labeling basically works by comparing API reference HTML content between develop and the state in a given PR.

@andrey-churkin
Copy link
Contributor

andrey-churkin commented Apr 17, 2023

I think we should also include

  • nncf.parameters.TargetDevice
  • nncf.parameters.ModelType
  • nncf.scopes.IgnoredScope
  • nncf.data.dataset.Dataset

@vshampor
Copy link
Contributor Author

I think we should also include

  • nncf.parameters.TargetDevice
  • nncf.parameters.ModelType
  • nncf.scopes.IgnoredScope
  • nncf.data.dataset.Dataset

Done

@@ -0,0 +1 @@
{% extends "python/data.rst" %}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These and other .rst files control the layout of the documentation and are copy-and-pasted from defaults, for future adjustments if necessary.

@@ -0,0 +1,114 @@
import importlib
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file controls the documentation build process that is executed during sphinx-build.



with mock(['torch', 'torchvision', 'onnx', 'onnxruntime', 'openvino', 'tensorflow', 'tensorflow_addons']):
api_fqns = collect_api_entities()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code allows to collect API entities without having to install all backends at once.

@AlexKoff88
Copy link
Contributor

It looks great really, thanks @vshampor . I have three major comments:

  • Can we remove the license from every page? It reduces the useful screen space and you need to scroll every time.
  • It would be great to have examples of configs along with descriptions of the features. For example, if we look at the KD description here, having a snippet of the config that enables this increases the usefulness of this page a lot, IMO.
  • The pages do not reflect the fact that some of the APIs are exposed at the top level of the "nncf" namespace. For example, if to look at the quantize API here, it is mentioned that it is a part of the "nncf.quantization.quantize" namespace but it can be imported directly from the "nncf". One way to work around it is to provide more documentation.

I think some follow up issues and PRs should be merged to address the last two issues.

@vshampor
Copy link
Contributor Author

@AlexKoff88

  • Can we remove the license from every page? It reduces the useful screen space and you need to scroll every time.

Sure, will do this in a follow-up PR along with docstring formatting adjustments.

  • It would be great to have examples of configs along with descriptions of the features. For example, if we look at the KD description here, having a snippet of the config that enables this increases the usefulness of this page a lot, IMO.

Basically everything that can be written in a docstring will be rendered, so there should be no problem to add config snippets and even code snippets via doctest later.

  • The pages do not reflect the fact that some of the APIs are exposed at the top level of the "nncf" namespace. For example, if to look at the quantize API here, it is mentioned that it is a part of the "nncf.quantization.quantize" namespace but it can be imported directly from the "nncf". One way to work around it is to provide more documentation.

I'll see if I can add another wrapper function to do this via code, maybe in this PR even.

@@ -26,6 +27,7 @@
from nncf.parameters import TargetDevice


@api(canonical_alias="nncf.quantize")
Copy link
Contributor Author

@vshampor vshampor Apr 19, 2023

Choose a reason for hiding this comment

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

@AlexKoff88 check this out - in this way it can be specified that the canonical import name should be "nncf.quantize", and the docs will be generated with the canonical import name in mind. Note that this also requires that the symbol itself is imported in corresponding __init__.py file (in this case, nncf/__init__.py), otherwise the doc build will fail and the doc build check will be red. I regenerated the page at https://vshampor.github.io/nncf/index.html so that you can see the effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot find quantize() in the latest version of the API build, only quantize_with_accuracy_control().

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 - make sure to reload the page with Ctrl-Shift-R so that you don't get a cached version.

One of the reasons was that had a function quantize exposed in __init__.py in the same subpackage that also contained the module called quantize.py. This meant that the quantize.py file was effectively impossible to import from, apart from the exposed quantize and quantize_with_accuracy_control functions, and this broke down the doc search mechanism, and is anyway considered to be bad practice (since the imported name shadows the subpackage name). Had to rename the quantize.py to quantize_fns.py, if you have suggestions for a better name, please post them.

Copy link
Contributor

@alexsu52 alexsu52 Apr 25, 2023

Choose a reason for hiding this comment

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

@vshampor I would recommend to rename quantize.py -> quantize_model.py because torch has already quantize_functions.py https://github.com/openvinotoolkit/nncf/blob/develop/nncf/torch/quantization/quantize_functions.py

Copy link
Contributor

@alexsu52 alexsu52 left a comment

Choose a reason for hiding this comment

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

please, rebase PR.

@vshampor vshampor force-pushed the api_doc_gen branch 2 times, most recently from 9cb5ecf to 6956f04 Compare April 26, 2023 12:06
@alexsu52 alexsu52 merged commit 211a8a5 into openvinotoolkit:develop Apr 27, 2023
@vshampor vshampor deleted the api_doc_gen branch January 9, 2024 13:59
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 experimental NNCF Common Pull request that updates NNCF Common NNCF ONNX Pull requests that updates NNCF ONNX NNCF OpenVINO Pull requests that updates NNCF OpenVINO NNCF PT Pull requests that updates NNCF PyTorch NNCF TF Pull requests that updates NNCF TensorFlow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants