Skip to content

Commit 562389b

Browse files
authored
Update for building document site (#12)
* update uv files * update to add docstrings * update for typehint * add fles for docs * update .gitignore * update * update for CI * update * update README.md
1 parent 329022a commit 562389b

File tree

21 files changed

+750
-18
lines changed

21 files changed

+750
-18
lines changed

.github/workflows/gh-pages.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Document
2+
3+
on: push
4+
5+
# Allow one concurrent deployment
6+
concurrency:
7+
group: "pages"
8+
cancel-in-progress: true
9+
10+
jobs:
11+
build-and-deploy:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: Typo check
20+
uses: crate-ci/typos@v1.29.0
21+
22+
- name: Setup python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: "3.10"
26+
27+
- name: Install dependencies
28+
run: |
29+
make setup
30+
make install
31+
32+
- name: Build HTML
33+
run: |
34+
make html
35+
36+
- name: Deploy
37+
uses: peaceiris/actions-gh-pages@v4
38+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
39+
with:
40+
github_token: ${{ secrets.GITHUB_TOKEN }}
41+
publish_dir: ./public
42+
publish_branch: gh-pages

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Created by https://www.toptal.com/developers/gitignore/api/python
22
# Edit at https://www.toptal.com/developers/gitignore?templates=python
33

4+
*.bk
45
*.png
6+
*.gif
57
*.json
68
*.safetensors
79

Makefile

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,34 @@
66
setup:
77
pip install -U uv
88

9-
.PHONY: install
9+
.PHONY: install-training
1010
install:
1111
uv sync --extra training
1212

13+
.PHONY: install-doc
14+
install-doc:
15+
uv sync --extra doc
16+
1317
#
1418
# linter/formatter/typecheck
1519
#
1620

1721
.PHONY: lint
18-
lint: install
22+
lint: install-training
1923
uv run ruff check --output-format=github .
2024

2125
.PHONY: format
22-
format: install
26+
format: install-training
2327
uv run ruff format --check --diff .
2428

2529
.PHONY: typecheck
2630
typecheck: install
2731
uv run mypy --cache-dir=/dev/null .
2832

2933
.PHONY: test
30-
test: install
34+
test: install-training
3135
uv run pytest -vsx --log-cli-level=INFO
36+
37+
.PHONY: html
38+
html: install-doc
39+
uv run sphinx-build -M html docs/source docs/build

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# 🤗 Noise Conditional Score Networks
22

33
[![CI](https://github.com/py-img-gen/diffusers-ncsn/actions/workflows/ci.yaml/badge.svg)](https://github.com/py-img-gen/diffusers-ncsn/actions/workflows/ci.yaml)
4-
[![](https://img.shields.io/badge/Official_code-GitHub-green)](https://github.com/ermongroup/ncsn)
4+
[![Document](https://github.com/py-img-gen/diffusers-ncsn/actions/workflows/gh-pages.yaml/badge.svg)](https://github.com/py-img-gen/diffusers-ncsn/actions/workflows/gh-pages.yaml)
5+
[![ermongroup/ncsn](https://img.shields.io/badge/Official_code-GitHub-green)](https://github.com/ermongroup/ncsn)
56
[![Model on HF](https://img.shields.io/badge/🤗%20Model%20on%20HF-py--img--gen/ncsn--mnist-D4AA00)](https://huggingface.co/py-img-gen/ncsn-mnist)
67

78
[`🤗 diffusers`](https://github.com/huggingface/diffusers) implementation of the paper ["Generative Modeling by Estimating Gradients of the Data Distribution" [Yang+ NeurIPS'19]](https://arxiv.org/abs/1907.05600).

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/make.bat

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@ECHO OFF
2+
3+
pushd %~dp0
4+
5+
REM Command file for Sphinx documentation
6+
7+
if "%SPHINXBUILD%" == "" (
8+
set SPHINXBUILD=sphinx-build
9+
)
10+
set SOURCEDIR=source
11+
set BUILDDIR=build
12+
13+
%SPHINXBUILD% >NUL 2>NUL
14+
if errorlevel 9009 (
15+
echo.
16+
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
17+
echo.installed, then set the SPHINXBUILD environment variable to point
18+
echo.to the full path of the 'sphinx-build' executable. Alternatively you
19+
echo.may add the Sphinx directory to PATH.
20+
echo.
21+
echo.If you don't have Sphinx installed, grab it from
22+
echo.https://www.sphinx-doc.org/
23+
exit /b 1
24+
)
25+
26+
if "%1" == "" goto help
27+
28+
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29+
goto end
30+
31+
:help
32+
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33+
34+
:end
35+
popd

docs/source/api/pipeline/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Pipeline
2+
3+
```{toctree}
4+
:maxdepth: 2
5+
:caption: Pipeline:
6+
7+
pipeline-ncsn
8+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Pipeline for NCSN
2+
3+
{py:class}`~ncsn.pipeline_ncsn.NCSNPipeline` is a pipeline for training and inference of Noise Conditional Score Networks (NCSN) proposed by by Yang Song and Stefano Ermon in the paper [Generative Modeling by Estimating Gradients of the Data Distribution](https://arxiv.org/abs/1907.05600). The pipeline is designed to be used with the
4+
{py:class}`~ncsn.unet.UNet2DModelForNCSN` model and the {py:class}`~ncsn.scheduler.AnnealedLangevinDynamicsScheduler` scheduler.
5+
6+
The abstract of the paper is the following:
7+
8+
> We introduce a new generative model where samples are produced via Langevin dynamics using gradients of the data distribution estimated with score matching. Because gradients can be ill-defined and hard to estimate when the data resides on low-dimensional manifolds, we perturb the data with different levels of Gaussian noise, and jointly estimate the corresponding scores, i.e., the vector fields of gradients of the perturbed data distribution for all noise levels. For sampling, we propose an annealed Langevin dynamics where we use gradients corresponding to gradually decreasing noise levels as the sampling process gets closer to the data manifold. Our framework allows flexible model architectures, requires no sampling during training or the use of adversarial methods, and provides a learning objective that can be used for principled model comparisons. Our models produce samples comparable to GANs on MNIST, CelebA and CIFAR-10 datasets, achieving a new state-of-the-art inception score of 8.87 on CIFAR-10. Additionally, we demonstrate that our models learn effective representations via image inpainting experiments.
9+
10+
## NCSNPipeline
11+
12+
```{eval-rst}
13+
.. autoclass:: ncsn.pipeline_ncsn.NCSNPipeline
14+
:members:
15+
:special-members:
16+
```

docs/source/api/scheduler/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Scheduler
2+
3+
```{toctree}
4+
:maxdepth: 2
5+
:caption: Scheduler:
6+
7+
scheduling-ncsn
8+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Annealed Langevin Dynamics Scheduler
2+
3+
{py:class}`~ncsn.scheduler.AnnealedLangevinDynamicsScheduler` is a scheduler that uses Langevin dynamics to sample from the posterior distribution of the model parameters. The scheduler anneals the temperature of the Langevin dynamics over time, starting from a high temperature and gradually decreasing it to a low temperature. The scheduler is based on the paper [Generative Modeling by Estimating Gradients of the Data Distribution](https://arxiv.org/abs/1907.05600) by Yang Song and Stefano Ermon. Stanford AI Lab.
4+
5+
The abstract of the paper is the following:
6+
> We introduce a new generative model where samples are produced via Langevin dynamics using gradients of the data distribution estimated with score matching. Because gradients can be ill-defined and hard to estimate when the data resides on low-dimensional manifolds, we perturb the data with different levels of Gaussian noise, and jointly estimate the corresponding scores, i.e., the vector fields of gradients of the perturbed data distribution for all noise levels. For sampling, we propose an annealed Langevin dynamics where we use gradients corresponding to gradually decreasing noise levels as the sampling process gets closer to the data manifold. Our framework allows flexible model architectures, requires no sampling during training or the use of adversarial methods, and provides a learning objective that can be used for principled model comparisons. Our models produce samples comparable to GANs on MNIST, CelebA and CIFAR-10 datasets, achieving a new state-of-the-art inception score of 8.87 on CIFAR-10. Additionally, we demonstrate that our models learn effective representations via image inpainting experiments.
7+
8+
## AnnealedLangevinDynamicsScheduler
9+
10+
```{eval-rst}
11+
.. autoclass:: ncsn.scheduler.AnnealedLangevinDynamicsScheduler
12+
:members:
13+
:special-members:
14+
```
15+
16+
## AnnealedLangevinDynamicsOutput
17+
18+
```{eval-rst}
19+
.. autoclass:: ncsn.scheduler.AnnealedLangevinDynamicsOutput
20+
:members:
21+
```

docs/source/api/unet/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# UNet
2+
3+
```{toctree}
4+
:maxdepth: 2
5+
:caption: UNet:
6+
7+
unet-2d-ncsn
8+
```

docs/source/api/unet/unet-2d-ncsn.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# UNet2DModel for NCSN
2+
3+
{py:class}`~ncsn.unet.UNet2DModelForNCSN` is a 2D U-Net model suitable for Noise Conditional Score Networks (NCSN) proposed by by Yang Song and Stefano Ermon in the paper [Generative Modeling by Estimating Gradients of the Data Distribution](https://arxiv.org/abs/1907.05600). The model inherits from the diffuser's {py:class}`~diffusers.UNet2DModel` and is designed to be used with the {py:class}`~ncsn.scheduler.AnnealedLangevinDynamicsScheduler` scheduler.
4+
5+
The abstract of the paper is the following:
6+
7+
> We introduce a new generative model where samples are produced via Langevin dynamics using gradients of the data distribution estimated with score matching. Because gradients can be ill-defined and hard to estimate when the data resides on low-dimensional manifolds, we perturb the data with different levels of Gaussian noise, and jointly estimate the corresponding scores, i.e., the vector fields of gradients of the perturbed data distribution for all noise levels. For sampling, we propose an annealed Langevin dynamics where we use gradients corresponding to gradually decreasing noise levels as the sampling process gets closer to the data manifold. Our framework allows flexible model architectures, requires no sampling during training or the use of adversarial methods, and provides a learning objective that can be used for principled model comparisons. Our models produce samples comparable to GANs on MNIST, CelebA and CIFAR-10 datasets, achieving a new state-of-the-art inception score of 8.87 on CIFAR-10. Additionally, we demonstrate that our models learn effective representations via image inpainting experiments.
8+
9+
## UNet2DModelForNCSN
10+
11+
```{eval-rst}
12+
.. autoclass:: ncsn.unet.UNet2DModelForNCSN
13+
:members:
14+
:special-members:
15+
```

docs/source/conf.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Configuration file for the Sphinx documentation builder.
2+
#
3+
# For the full list of built-in configuration values, see the documentation:
4+
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
6+
# -- Project information -----------------------------------------------------
7+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8+
9+
import os
10+
import sys
11+
12+
# -- Path setup --------------------------------------------------------------
13+
14+
# If extensions (or modules to document with autodoc) are in another directory,
15+
# add these directories to sys.path here. If the directory is relative to the
16+
# documentation root, use os.path.abspath to make it absolute, like shown here.
17+
18+
sys.path.insert(0, os.path.abspath("../../../src"))
19+
20+
from datetime import datetime
21+
22+
from sphinx_pyproject import SphinxConfig
23+
24+
config = SphinxConfig(pyproject_file="../../pyproject.toml")
25+
26+
27+
project = config.name
28+
copyright = f"{datetime.today().year}, {config.author}"
29+
30+
author = config.author
31+
release = config.version
32+
33+
# -- General configuration ---------------------------------------------------
34+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
35+
36+
extensions = [
37+
"sphinx.ext.autodoc",
38+
"sphinx.ext.napoleon",
39+
"myst_parser",
40+
"sphinx.ext.intersphinx",
41+
"sphinx.ext.viewcode",
42+
"sphinx_autodoc_typehints",
43+
]
44+
45+
templates_path = ["_templates"]
46+
exclude_patterns = ["build"]
47+
48+
source_suffix = [".rst", ".md"]
49+
50+
# -- Extension configuration -------------------------------------------------
51+
52+
intersphinx_mapping = {
53+
"python": ("https://docs.python.org/3", None),
54+
"torch": ("https://pytorch.org/docs/stable", None),
55+
"transformers": ("https://huggingface.co/docs/transformers/master/en", None),
56+
"diffusers": ("https://huggingface.co/docs/diffusers/main/en", None),
57+
}
58+
59+
# Tell myst-parser to assign header anchors for h1-h3.
60+
myst_heading_anchors = 3
61+
62+
# By default, sort documented members by type within classes and modules.
63+
autodoc_member_order = "groupwise"
64+
65+
python_use_unqualified_type_names = True
66+
67+
# Include default values when documenting parameter types.
68+
typehints_defaults = "comma"
69+
70+
# -- Options for HTML output -------------------------------------------------
71+
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
72+
73+
html_theme = "furo"
74+
html_static_path = ["_static"]
75+
html_favicon = "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"

docs/source/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```{include} ../../README.md
2+
```
3+
4+
```{toctree}
5+
:maxdepth: 2
6+
:hidden:
7+
:caption: API Reference:
8+
9+
api/unet/index
10+
api/scheduler/index
11+
api/pipeline/index
12+
```

pyproject.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
name = "diffusers-ncsn"
33
version = "0.1.0"
44
description = "Diffusers implementation of Noise Conditional Score Networks (NCSN) [Yang+ NeuriPS'19]"
5+
authors = [
6+
{ name = "Shunsuke Kitada", email = "shunsuke.kitada.0831@gmail.com" },
7+
{ name = "Image Generation with Python", email = "python.image.generation@gmail.com" },
8+
]
59
readme = "README.md"
610
requires-python = ">=3.10"
711
dependencies = [
@@ -14,6 +18,13 @@ dependencies = [
1418

1519
[project.optional-dependencies]
1620
training = ["matplotlib>=3.10.0"]
21+
doc = [
22+
"sphinx-pyproject>=0.3.0",
23+
"sphinx>=8.1.3",
24+
"furo>=2024.8.6",
25+
"myst-parser>=4.0.0",
26+
"sphinx-autodoc-typehints>=3.0.0",
27+
]
1728

1829
[dependency-groups]
1930
dev = ["mypy>=1.0.0", "pytest>=6.0.0", "ruff>=0.1.5"]

src/ncsn/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from importlib.metadata import version
2+
3+
from ncsn.pipeline_ncsn import NCSNPipeline
4+
5+
__version__ = version("diffusers-ncsn")
6+
7+
8+
__all__ = [
9+
"NCSNPipeline",
10+
]

0 commit comments

Comments
 (0)