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+
```

0 commit comments

Comments
 (0)