Skip to content

Commit d03705e

Browse files
YosuaMichaelfacebook-github-bot
authored andcommitted
[fbsync] Add docs for SomeWeight.DEFAULT fields (#5831)
Summary: * First PR for model doc revamp * Deactivating fail on warning, temporarily * Remove commnet * Minor changes * Typos * Added TODO in Makefile * Keep old models.rst file intact, move new docs into new models_new.rst file * Added docs LOL Reviewed By: jdsgomes, NicolasHug Differential Revision: D36095660 fbshipit-source-id: d0df99cc20418a15754ac65e4b731ac155d5fc22
1 parent b1c84ce commit d03705e

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/source/conf.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,33 @@ def inject_minigalleries(app, what, name, obj, options, lines):
297297

298298

299299
def inject_weight_metadata(app, what, name, obj, options, lines):
300+
"""This hook is used to generate docs for the models weights.
301+
302+
Objects like ResNet18_Weights are enums with fields, where each field is a Weight object.
303+
Enums aren't easily documented in Python so the solution we're going for is to:
304+
305+
- add an autoclass directive in the model's builder docstring, e.g.
306+
307+
```
308+
.. autoclass:: torchvision.models.ResNet34_Weights
309+
:members:
310+
```
311+
312+
(see resnet.py for an example)
313+
- then this hook is called automatically when building the docs, and it generates the text that gets
314+
used within the autoclass directive.
315+
"""
300316

301317
if obj.__name__.endswith("_Weights"):
302-
lines[:] = ["The model builder above accepts the following values as the ``weights`` parameter:"]
318+
lines[:] = [
319+
"The model builder above accepts the following values as the ``weights`` parameter.",
320+
f"``{obj.__name__}.DEFAULT`` is equivalent to ``{obj.DEFAULT}``.",
321+
]
303322
lines.append("")
304323
for field in obj:
305324
lines += [f"**{str(field)}**:", ""]
325+
if field == obj.DEFAULT:
326+
lines += [f"This weight is also available as ``{obj.__name__}.DEFAULT``.", ""]
306327

307328
table = []
308329
for k, v in field.meta.items():

0 commit comments

Comments
 (0)