Unverified Commit 070c45bb authored by Muyang Li's avatar Muyang Li Committed by GitHub
Browse files

docs: add the docstrings for v1.0.0 (#656)

* add v2 flux examples

* add the docs

* add docs

* update

* finished ops

* add ops

* update

* update

* update

* update

* update

* update

* update

* update docstrings

* update

* update

* update

* update

* update

* update

* update

* finished the api docs

* update

* update
parent e0392e42
Writing Docstrings
==================
Use this guide to write clear, consistent Python docstrings for Nunchaku.
Follow the `NumPy style guide <https://numpydoc.readthedocs.io/en/latest/format.html>`__, and always specify variable shapes, dtypes, and notation.
The docstring should be concise and informative.
Docstring Format
----------------
A standard docstring should look like:
.. code-block:: python
"""
Short summary of what the function or class does.
(Optional) Extended description.
Parameters
----------
param1 : type
Description.
param2 : type, optional
Description. Default is ...
param3 : array-like, shape (n, m), dtype float
Example of shape and dtype notation.
Returns
-------
out1 : type
Description.
out2 : type
Description.
Raises
------
ValueError
When this exception is raised.
See Also
--------
other_function : brief description
Notes
-----
Additional details or references.
Examples
--------
>>> result = func(1, 2)
>>> print(result)
3
"""
Guidelines
----------
- Use triple double quotes (``"""``) for all docstrings.
- Every public module, class, method, and function must have a docstring.
- The first line is a concise summary.
- Use sections in this order (as needed): ``Parameters``, ``Returns``, ``Raises``, ``See Also``, ``Notes``, ``Examples``.
Shapes, Dtypes, and Notation
----------------------------
- Always specify expected shape and dtype for tensors/arrays.
- Use plain text for shapes (not LaTeX/math symbols).
- Use clear, single-letter or descriptive names for shape dimensions (e.g., `B` for batch size).
- Define all shape symbols in a `Notes` section.
**Example:**
.. code-block:: python
def forward(
self,
x: torch.Tensor,
mask: Optional[torch.Tensor] = None,
) -> torch.Tensor:
"""
Forward pass of the model.
Parameters
----------
x : torch.Tensor, shape (B, C, H, W), dtype float32
Input image tensor.
mask : Optional[torch.Tensor], shape (B, 1, H, W), dtype bool
Optional mask.
Returns
-------
out : torch.Tensor, shape (B, num_classes), dtype float32
Output logits.
Raises
------
ValueError
If input shapes are incompatible.
Notes
-----
Notations:
- B: batch size
- C: channels
- H: height
- W: width
- num_classes: number of output classes
Examples
--------
>>> x = torch.randn(8, 3, 224, 224)
>>> out = model.forward(x)
"""
...
Best Practices
--------------
Writing Tips
~~~~~~~~~~~~
- **Be concise and clear.** Start with a short summary describing what the function or class does.
- **Document all parameters and return values.** Indicate if a parameter can be `None`.
- **Include an** ``Examples`` **section** to demonstrate typical usage.
- **List all possible exceptions in a** ``Raises`` **section.**
- **Use a** ``Notes`` **section** to define shape symbols and explain special behaviors.
- **Add a** ``See Also`` **section** for related functions or methods.
Useful Prompts
~~~~~~~~~~~~~~
.. code-block:: text
Improve the writing of the docstring according to this guide. Be concise. Organize my comments clearly.
Write the docstring for this module (every class and functions) according to this guide. Each function and class that can be shwon properly and beautifully in sphinx html. Be concise. Organize my comments clearly.
For further questions or formatting help, refer to existing Nunchaku code or ask in the developer chat.
......@@ -16,6 +16,7 @@ Check out `DeepCompressor <github_deepcompressor_>`_ for the quantization librar
:caption: Usage Tutorials
usage/basic_usage.rst
usage/qwenimage.rst
usage/lora.rst
usage/kontext.rst
usage/controlnet.rst
......@@ -48,3 +49,4 @@ Check out `DeepCompressor <github_deepcompressor_>`_ for the quantization librar
faq/faq.rst
developer/contribution_guide.rst
developer/docstring.rst
......@@ -9,3 +9,5 @@
.. _hf_depth_anything: https://huggingface.co/LiheYoung/depth-anything-large-hf
.. _hf_nunchaku_wheels: https://huggingface.co/nunchaku-tech/nunchaku
.. _hf_ip-adapterv2: https://huggingface.co/XLabs-AI/flux-ip-adapter-v2
.. _hf_qwen-image: https://huggingface.co/Qwen/Qwen-Image
.. _hf_qwen-image-lightning: https://huggingface.co/lightx2v/Qwen-Image-Lightning
.. _paper_svdquant: http://arxiv.org/abs/2411.05007
.. _paper_pulid: https://arxiv.org/abs/2404.16022
.. _paper_awq: https://arxiv.org/abs/2306.00978
nunchaku.models.attention
=============================
.. automodule:: nunchaku.models.attention
:members:
:undoc-members:
:show-inheritance:
:private-members:
nunchaku.models.attention_processors.flux
=========================================
.. automodule:: nunchaku.models.attention_processors.flux
:members:
:undoc-members:
:show-inheritance:
nunchaku.models.attention_processors.qwenimage
==============================================
.. automodule:: nunchaku.models.attention_processors.qwenimage
:members:
:undoc-members:
:show-inheritance:
nunchaku.models.attention_processors
====================================
.. toctree::
:maxdepth: 4
nunchaku.models.attention_processors.flux
nunchaku.models.attention_processors.qwenimage
nunchaku.models.embeddings
==========================
.. automodule:: nunchaku.models.embeddings
:members:
:undoc-members:
:show-inheritance:
:private-members:
nunchaku.models.linear
======================
.. automodule:: nunchaku.models.linear
:members:
:undoc-members:
:show-inheritance:
:private-members:
nunchaku.models.normalization
=============================
.. automodule:: nunchaku.models.normalization
:members:
:undoc-members:
:show-inheritance:
:private-members:
......@@ -6,6 +6,12 @@ nunchaku.models
nunchaku.models.transformers
nunchaku.models.text_encoders
nunchaku.models.linear
nunchaku.models.attention
nunchaku.models.attention_processors
nunchaku.models.normalization
nunchaku.models.embeddings
nunchaku.models.pulid
nunchaku.models.ip_adapter
nunchaku.models.safety_checker
nunchaku.models.utils
......@@ -5,5 +5,7 @@ nunchaku.models.transformers
:maxdepth: 4
nunchaku.models.transformers.transformer_flux
nunchaku.models.transformers.transformer_flux_v2
nunchaku.models.transformers.transformer_qwenimage
nunchaku.models.transformers.transformer_sana
nunchaku.models.transformers.utils
nunchaku.models.transformers.transformer\_flux\_v2
==================================================
.. automodule:: nunchaku.models.transformers.transformer_flux_v2
:members:
:undoc-members:
:show-inheritance:
nunchaku.models.transformers.transformer\_qwenimage
===================================================
.. automodule:: nunchaku.models.transformers.transformer_qwenimage
:members:
:undoc-members:
:show-inheritance:
nunchaku.models.utils
=====================
.. automodule:: nunchaku.models.utils
:members:
:undoc-members:
:show-inheritance:
nunchaku.ops.fused
==================
.. automodule:: nunchaku.ops.fused
:members:
:undoc-members:
:private-members:
:show-inheritance:
nunchaku.ops.gemm
=================
.. automodule:: nunchaku.ops.gemm
:members:
:undoc-members:
:private-members:
:show-inheritance:
nunchaku.ops.gemv
=================
.. automodule:: nunchaku.ops.gemv
:members:
:undoc-members:
:private-members:
:show-inheritance:
nunchaku.ops.quantize
=====================
.. automodule:: nunchaku.ops.quantize
:members:
:undoc-members:
:private-members:
:show-inheritance:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment