Skip to content

Commit

Permalink
configure and initialize mkdocstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent2916 committed Jan 31, 2024
1 parent ab63a01 commit afd7d4e
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 11 deletions.
13 changes: 7 additions & 6 deletions docs/concepts/adapters.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class MyAdapter(Sum, Adapter[Conv2d]):

Let us take a simple example to see how this works. Consider this model:

![before](assets/adapters/linear-before.png)
![before](../assets/adapters/linear-before.png)

In pseudo-code, it could look like this:

Expand All @@ -39,7 +39,7 @@ adapter = MyAdapter(target)

The result is now this:

![ejected](assets/adapters/linear-ejected.png)
![ejected](../assets/adapters/linear-ejected.png)

Note that the original chain is unmodified. You can still run inference on it as if the adapter did not exist. To use the adapter, you must inject it into the chain:

Expand All @@ -49,7 +49,7 @@ adapter.inject(parent)

The result will be:

![injected](assets/adapters/linear-injected.png)
![injected](../assets/adapters/linear-injected.png)

Now if you run inference it will go through the Adapter. You can go back to the previous situation by calling `adapter.eject()`.

Expand All @@ -76,7 +76,7 @@ adapter = MyAdapter(my_model.Chain_1) # Chain A in the diagram

We end up with this:

![chain-ejected](assets/adapters/chain-ejected.png)
![chain-ejected](../assets/adapters/chain-ejected.png)

We can now inject it into the original graph. It is not even needed to pass the parent this time, since Chains know their parents.

Expand All @@ -86,12 +86,13 @@ adapter.inject()

We obtain this:

![chain-injected](assets/adapters/chain-injected.png)
![chain-injected](../assets/adapters/chain-injected.png)

Note that the Linear is in the Chain twice now, but that does not matter as long as you really want it to be the same Linear layer with the same weights.

As before, we can call eject the adapter to go back to the original model.

## A real-world example: LoraAdapter

A popular example of adaptation is [LoRA](https://arxiv.org/abs/2106.09685). You can check out [how we implement it in Refiners](../src/refiners/fluxion/adapters/lora.py).
A popular example of adaptation is [LoRA](https://arxiv.org/abs/2106.09685).
You can check out [how we implement it in Refiners][refiners.fluxion.adapters].
12 changes: 12 additions & 0 deletions docs/reference/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
* <code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Fluxion
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Adapters](fluxion/adapters.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Context](fluxion/context.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Layers](fluxion/layers.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Model Converter](fluxion/model_converter.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Utils](fluxion/utils.md)
* <code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Foundationals Models
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> CLIP](foundationals/clip.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> DINOv2](foundationals/dinov2.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Latent Diffusion](foundationals/latent_diffusion.md)
* [<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code> Segment Anything](foundationals/segment_anything.md)

1 change: 1 addition & 0 deletions docs/reference/fluxion/adapters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.fluxion.adapters
1 change: 1 addition & 0 deletions docs/reference/fluxion/context.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.fluxion.context
1 change: 1 addition & 0 deletions docs/reference/fluxion/layers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.fluxion.layers
1 change: 1 addition & 0 deletions docs/reference/fluxion/model_converter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.fluxion.model_converter
1 change: 1 addition & 0 deletions docs/reference/fluxion/utils.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.fluxion.utils
1 change: 1 addition & 0 deletions docs/reference/foundationals/clip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.foundationals.clip
1 change: 1 addition & 0 deletions docs/reference/foundationals/dinov2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.foundationals.dinov2
1 change: 1 addition & 0 deletions docs/reference/foundationals/latent_diffusion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.foundationals.latent_diffusion
1 change: 1 addition & 0 deletions docs/reference/foundationals/segment_anything.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: refiners.foundationals.segment_anything
27 changes: 24 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,34 @@ theme:
- navigation.expand
- navigation.path
- toc.follow
- toc.integrate
- navigation.tabs.sticky
- content.code.copy
plugins:
- mkdocstrings
- search
- tags
- literate-nav:
nav_file: SUMMARY.md
- mkdocstrings:
handlers:
python:
import:
- https://docs.python.org/3/objects.inv
- https://pytorch.org/docs/master/objects.inv
options:
show_bases: true
show_source: true
show_root_toc_entry: false
show_symbol_type_heading: true
show_symbol_type_toc: true
show_if_no_docstring: false
filters:
- "!^_"
docstring_options:
ignore_init_summary: true
merge_init_into_class: true
separate_signature: true
show_signature_annotations: true
signature_crossrefs: true
extra_css:
- stylesheets/extra.css
nav:
Expand All @@ -39,7 +60,7 @@ nav:
- concepts/index.md
- concepts/adapters.md
- API Reference:
- index.md
- Refiners: reference/
extra:
social:
- icon: fontawesome/brands/discord
Expand Down
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ dev-dependencies = [
"ruff>=0.1.15",
"docformatter>=1.7.5",
"pytest>=8.0.0",
"mkdocs-material>=9.5.6",
"coverage>=7.4.1",
"mkdocs-material>=9.5.6",
"mkdocstrings[python]>=0.24.0",
"mkdocs-literate-nav>=0.6.1",
]


Expand All @@ -71,7 +72,10 @@ test-cov = "coverage run -m pytest"
# Work around for "Couldn't parse" errors due to e.g. opencv-python:
# https://github.com/nedbat/coveragepy/issues/1653
build-html-cov = { cmd = "coverage html", env = { PYTHONWARNINGS = "ignore:Couldn't parse::coverage.report_core" } }
serve-cov-report = { chain = ["build-html-cov", "python -m http.server 8080 -b 127.0.0.1 -d htmlcov"]}
serve-cov-report = { chain = [
"build-html-cov",
"python -m http.server 8080 -b 127.0.0.1 -d htmlcov",
] }

[tool.black]
line-length = 120
Expand Down

0 comments on commit afd7d4e

Please sign in to comment.