Skip to content

Commit b8bdafb

Browse files
author
Flax Authors
committed
Merge pull request #4349 from 8bitmp3:define-model-surgery
PiperOrigin-RevId: 691593549
2 parents 917c097 + 817755f commit b8bdafb

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

docs_nnx/guides/surgery.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"source": [
77
"# Model surgery\n",
88
"\n",
9-
"In this guide, you will learn how to perform model surgery in Flax NNX using several real-world scenarios:\n",
9+
"Model surgery is an act of making modifications on an existing neural network's building blocks and parameters, such as layer replacement, parameter or state manipulation, or even \"monkey patching\". In this guide, you will learn how to perform model surgery in Flax NNX using several real-world scenarios:\n",
1010
"\n",
1111
"* __Pythonic `nnx.Module` manipulation__: Using Pythonic ways to manipulate sub-`Module`s given a model.\n",
1212
"\n",

docs_nnx/guides/surgery.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jupytext:
1010

1111
# Model surgery
1212

13-
In this guide, you will learn how to perform model surgery in Flax NNX using several real-world scenarios:
13+
Model surgery is an act of making modifications on an existing neural network's building blocks and parameters, such as layer replacement, parameter or state manipulation, or even "monkey patching". In this guide, you will learn how to perform model surgery in Flax NNX using several real-world scenarios:
1414

1515
* __Pythonic `nnx.Module` manipulation__: Using Pythonic ways to manipulate sub-`Module`s given a model.
1616

docs_nnx/nnx_basics.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
"source": [
248248
"### Model surgery\n",
249249
"\n",
250-
"Flax [`nnx.Module`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/module.html)s are mutable by default. This means that their structure can be changed at any time, which makes model surgery quite easy as any sub-`Module` attribute can be replaced with anything else, such as new `Module`s, existing shared `Module`s, `Module`s of different types, and so on. Moreover, [`nnx.Variable`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/variables.html#flax.nnx.Variable)s can also be modified or replaced/shared.\n",
250+
"Flax [`nnx.Module`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/module.html)s are mutable by default. This means that their structure can be changed at any time, which makes [model surgery](https://flax.readthedocs.io/en/latest/guides/surgery.html) quite easy, as any sub-`Module` attribute can be replaced with anything else, such as new `Module`s, existing shared `Module`s, `Module`s of different types, and so on. Moreover, [`nnx.Variable`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/variables.html#flax.nnx.Variable)s can also be modified or replaced/shared.\n",
251251
"\n",
252252
"The following example shows how to replace the `Linear` layers in the `MLP` model from the previous example with `LoraLinear` layers:"
253253
]

docs_nnx/nnx_basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ In Flax, [`nnx.Dropout`](https://flax.readthedocs.io/en/latest/api_reference/fla
143143

144144
### Model surgery
145145

146-
Flax [`nnx.Module`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/module.html)s are mutable by default. This means that their structure can be changed at any time, which makes model surgery quite easy as any sub-`Module` attribute can be replaced with anything else, such as new `Module`s, existing shared `Module`s, `Module`s of different types, and so on. Moreover, [`nnx.Variable`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/variables.html#flax.nnx.Variable)s can also be modified or replaced/shared.
146+
Flax [`nnx.Module`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/module.html)s are mutable by default. This means that their structure can be changed at any time, which makes [model surgery](https://flax.readthedocs.io/en/latest/guides/surgery.html) quite easy, as any sub-`Module` attribute can be replaced with anything else, such as new `Module`s, existing shared `Module`s, `Module`s of different types, and so on. Moreover, [`nnx.Variable`](https://flax.readthedocs.io/en/latest/api_reference/flax.nnx/variables.html#flax.nnx.Variable)s can also be modified or replaced/shared.
147147

148148
The following example shows how to replace the `Linear` layers in the `MLP` model from the previous example with `LoraLinear` layers:
149149

docs_nnx/why.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ is a simplified version of a ``BatchNorm`` layer that updates the mean and varia
279279
Model surgery
280280
^^^^^^^^^^^^^
281281

282-
In Flax Linen, model surgery has historically been challenging because of two reasons:
282+
In Flax Linen, `model surgery <https://flax.readthedocs.io/en/latest/guides/surgery.html>`_ has historically been challenging because of two reasons:
283283

284284
1. Due to lazy initialization, it is not guaranteed that you can replace a sub-``Module`` with a new one.
285285
2. The parameter structure is separated from the ``flax.linen.Module`` structure, which means you have to manually keep them in sync.

0 commit comments

Comments
 (0)