fairseq2.recipe.composition¶
The documentation for this module is work in progress.
Functions¶
- fairseq2.recipe.composition.register_recipe_assets(container: DependencyContainer, rel_path: Path | str, *, stack_level: int = 1) None[source]¶
Registers asset cards located under the specified path, relative to the calling module’s path (i.e.
module.__path__).The specified path should be either a YAML file or a directory containing YAML files. If a directory is specified, it will be scanned recursively. Each YAML file must define one or more asset cards, which are used by
AssetStoreto represent assets such as models, datasets, and tokenizers.Check out the Assets concept documentation to learn more about assets and asset cards.
This function is intended to be called within the
register()method of a recipe, to register assets that should always be available alongside the recipe.from fairseq2.runtime.dependency import DependencyContainer from fairseq2.recipe import TrainRecipe from fairseq2.recipe.composition import register_recipe_assets class MyRecipe(TrainRecipe): def register(self, container: DependencyContainer) -> None: register_recipe_assets(container, "configs/assets")
stack_levelcan be used to specify the actual calling module. For example, ifregister_recipe_assetsis invoked within a wrapper helper function, settingstack_levelto 2 indicates that the caller module is the one that called the helper function.A helper function in a Python file named “my_helpers.py”¶from fairseq2.recipe.composition import register_recipe_assets from fairseq2.runtime.dependency import DependencyContainer def my_recipe_helper_function(container: DependencyContainer) -> None: # Note that `stack_level` is set to 2, so that the actual calling # module, and not "my_helpers.py", is used to resolve the path. register_recipe_assets(container, "path/to/assets", stack_level=2)
Note that this function is primarily intended for use by recipe authors. Users of a recipe can specify additional paths to search for asset cards by using the
AssetsConfig.extra_pathsconfiguration option.A YAML recipe configuration¶common: assets: extra_paths: - /path/to/extra/recipes1 - /path/to/extra/recipes2
- Raises:
ValueError – If
rel_pathspecifies an absolute pathValueError – If
rel_pathis a string and does not represent a valid pathValueError – If
stack_levelis less than 1 or larger than the size of the call stack.