Skip to content

Commit 0f85cbc

Browse files
committed
recipe can be a file or a directory
Signed-off-by: Shengliang Xu <shengliangx@nvidia.com>
1 parent 3f9f709 commit 0f85cbc

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

docs/source/guides/_recipes.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
Recipes
44
#######
55

6-
A **recipe** is a declarative YAML specification that fully describes how to optimize a model.
6+
A **recipe** is a declarative specification that fully describes how to optimize a model.
7+
A recipe can be a single YAML file or a directory containing YAML configs and other files
8+
that together define a model optimization workflow.
79
Recipes decouple optimization settings from Python code, enabling reuse, sharing, version
810
control, and reproducibility. Instead of editing Python scripts to change quantization
9-
parameters, you author (or select) a recipe file and pass it to the ModelOpt tooling.
11+
parameters, you author (or select) a recipe and pass it to the ModelOpt tooling.
1012

1113
.. contents:: On this page
1214
:local:
@@ -26,7 +28,7 @@ constants, and ad-hoc code edits. This makes it difficult to:
2628
settings to tweak.
2729

2830
Recipes solve these problems by capturing **all** the configuration needed to optimize a
29-
model in a single YAML file (or a small directory of files).
31+
model in a single, portable artifact -- either a YAML file or a directory of files.
3032

3133

3234
Design overview
@@ -35,19 +37,20 @@ Design overview
3537
The recipe system is part of the :mod:`modelopt.recipe` package and consists of three
3638
layers:
3739

38-
1. **Recipe files** -- YAML documents stored in the ``modelopt_recipes/`` directory (shipped
39-
with the package) or on the user's filesystem.
40+
1. **Recipe sources** -- YAML files or directories stored in the ``modelopt_recipes/``
41+
directory (shipped with the package) or on the user's filesystem.
4042
2. **Config loader** -- :func:`~modelopt.recipe.load_config` reads YAML files, resolves
4143
paths, and performs automatic ``ExMy`` floating-point notation conversion.
42-
3. **Recipe loader** -- :func:`~modelopt.recipe.load_recipe` validates the YAML against
43-
Pydantic models and returns a typed recipe object ready for use.
44+
3. **Recipe loader** -- :func:`~modelopt.recipe.load_recipe` validates the loaded
45+
configuration against Pydantic models and returns a typed recipe object ready for use.
4446

4547

46-
Recipe file format
47-
==================
48+
Recipe format
49+
=============
4850

49-
A recipe is a YAML file with two top-level sections: ``metadata`` and a
50-
type-specific configuration section (currently ``quantize`` for PTQ recipes).
51+
A recipe contains two top-level sections: ``metadata`` and a type-specific
52+
configuration section (for example, ``quantize`` for PTQ recipes). These can live
53+
in a single YAML file or be split across files in a directory.
5154

5255
Single-file format
5356
------------------
@@ -122,7 +125,7 @@ quantization configuration, use a directory with two files:
122125
Metadata section
123126
================
124127

125-
Every recipe file must contain a ``metadata`` mapping with at least a ``recipe_type`` field:
128+
Every recipe must contain a ``metadata`` mapping with at least a ``recipe_type`` field:
126129

127130
.. list-table::
128131
:header-rows: 1
@@ -166,7 +169,7 @@ For PTQ recipes (``recipe_type: ptq``), the ``quantize`` mapping contains:
166169
ExMy floating-point notation
167170
=============================
168171

169-
Recipe files support a convenient shorthand for floating-point bit formats in
172+
Recipe YAML files support a convenient shorthand for floating-point bit formats in
170173
``num_bits`` and ``scale_bits`` fields. Instead of writing a Python tuple, you
171174
write the format name directly:
172175

@@ -271,8 +274,9 @@ against the built-in library first, then the filesystem:
271274
272275
.. code-block:: python
273276
274-
# Load a custom recipe from the filesystem
277+
# Load a custom recipe from the filesystem (file or directory)
275278
recipe = load_recipe("/path/to/my_custom_recipe.yml")
279+
# or: recipe = load_recipe("/path/to/my_recipe_dir/")
276280
model = mtq.quantize(model, recipe.quantize, forward_loop)
277281
278282
Command-line usage
@@ -315,8 +319,9 @@ resolve paths using the same strategy:
315319

316320
1. If the path is absolute, use it directly.
317321
2. If relative, check the **built-in recipes library** first
318-
(``modelopt_recipes/``), probing ``.yml`` and ``.yaml`` suffixes.
319-
3. Then check the **filesystem**, probing the same suffixes.
322+
(``modelopt_recipes/``), probing ``.yml`` and ``.yaml`` suffixes as well as
323+
directories.
324+
3. Then check the **filesystem**, probing the same suffixes and directories.
320325

321326
This means built-in recipes can be referenced without any prefix:
322327

@@ -336,7 +341,7 @@ To create a custom recipe:
336341
2. Copy it and modify the ``quant_cfg`` entries as needed (see :ref:`quant-cfg`
337342
for entry format details).
338343
3. Update the ``metadata.description`` to describe your changes.
339-
4. Save the file and pass its path to ``load_recipe()`` or ``--recipe``.
344+
4. Save the file (or directory) and pass its path to ``load_recipe()`` or ``--recipe``.
340345

341346
Example -- creating an INT8 per-channel recipe:
342347

0 commit comments

Comments
 (0)