-
Notifications
You must be signed in to change notification settings - Fork 8
finn.interface
This page contains the complete API reference for all modules in the finn.interface package.
- finn.interface.interface_utils
- finn.interface.manage_deps
- finn.interface.manage_tests
- finn.interface.run_finn
- finn.interface.settings
Utilities for the FINN command line interface.
def resolve_module_path(name: str) -> strResolve the path to modules which are not part of the FINN package hierarchy.
class NullablePath(click.ParamType)If the passed parameter is an empty string return None, otherwise a Path.
def __init__(expand_user: bool = True) -> NoneInitialize a NullablePath.
def convert(value: str, param: Any, ctx: Any) -> Path | NoneConvert a string value into a Path or None, depending on the contents.
def error(msg: str) -> NonePrint an error.
def warning(msg: str, critical: bool = False) -> NonePrint a warning.
def status(msg: str) -> NonePrint a status message.
def success(msg: str) -> NonePrint a success message.
def debug(msg: str, with_rich: bool = True) -> NonePrint a debug message. Only done when the flag is set.
def table(data: dict[Any, Any], key_header: str, value_header: str) -> NonePrint the data as a table.
def assert_path_valid(p: Path) -> NoneCheck if the path exists, if not print an error message and exit with an error code.
def set_synthesis_tools_paths() -> NoneCheck that all synthesis tools can be found. If not, give a warning.
Manage dependencies. Called by run_finn.py.
class Dependency()Baseclass for all dependencies.
class GitDependency(BaseModel, Dependency)Data model for a Git-based dependency.
url: Git repository URL. commit: Commit to checkout. pip_install: Whether to install the repository using pip.
@model_validator(mode="after")
def editable_install_requires_pip() -> GitDependencyValidate that editable installs can only be done on pip installed repos.
class BoardfileDependency(BaseModel, Dependency)Data model for a Boardfile dependency.
url: Git repository URL. commit: Commit to checkout. subdirectory: Path inside the repository from which to copy to the boardfiles directoty.
class DirectDownloadDependency(BaseModel, Dependency)Data model for a direct download dependency.
url: URL to download from. do_unzip: Whether to unzip the downloaded data. target_directory: Where to place the downloaded (uncompressed) data.
class CustomDependency(BaseModel, Dependency)Data model for a custom dependency.
installation_function: Name of the function that should be implemented in the DependencyUpdater to install this dependency. outdated_function: Name of function that returns whether this dependency is outdated.
class DependencyData(BaseModel)Data model that stores all dependencies.
def get_all_dependencies() -> list[str]Return a list of all packages, across dependency types.
def get_dependency_count() -> intReturn the total number of dependencies.
def assert_unique_dependency_names() -> NoneAssert that all dependencies across categories have unique names. Raise AssertionError otherwise.
def dependency_type_str(package_name: str) -> strReturn a string to tell which type this dependency is.
def get_dependency_data(package_name: str) -> Dependency | NoneReturn the dependency data for the given package. If no such package exists return None.
def get_fields(package_name: str, *field_names: str) -> tupleReturn a tuple with all required fields from the data. If one of the fields does not exist, raise an exception.
class _StatusTracker()Small helper class to thread-safely organize status data.
def __init__(names_types: list[tuple[str, str]],
live: Live | contextlib.nullcontext) -> NoneCreate a status tracker.
Arguments:
-
names_types- List of tuples that associate dependency names with their type. -
live- The rich.live.Live object that is used to display the status data.
def update_status(name: str, status: str, color: str) -> NoneUpdate the status dict. If name doesnt exist, do nothing.
def update_live() -> NoneUpdate the associated live rich display. Also refreshes it.
def set_updating(name: str) -> NoneSet the package to updating and update the live display. If name doesnt exist, do nothing.
def set_finish(name: str, successful: bool) -> NoneSet the package to finished and update the live display. If name doesnt exist, do nothing.
class DependencyUpdater()Manage non-python dependencies.
def __init__(dependency_location: Path,
dependency_definition_file: Path,
git_timeout_s: float,
non_interactive: bool = False) -> NoneCreate a new updater.
Boardfiles will be downloaded to the specified location at /boardfiles_downloads/. This is used to check whether they are outdated.
Arguments:
-
dependency_location- Path to the directory where all files are placed / checked. -
dependency_definition_file- This points to the yaml file containing all dependencies. -
git_timeout_s- Timeout for git requests in seconds. -
non_interactive- If set, don't generate a live status report.
def install_dependency(package_name: str) -> boolInstall the dependency in the dependency location. If no definition for this dependency exists or the installation failed, return False. If the installation was successful return true.
def is_outdated(package_name: str, installed: bool = False) -> boolReturn whether the a package is outdated. If no such package exist return False too.
def get_outdated_dependencies() -> list[str]Return a list of the names of all outdated packages. For Git dependencies this means an outdated commit hash, for the others a different URL or target directory.
def update() -> NoneWith a live display and multithreading update all dependencies that are outdated.
Manage FINNs testsuite.
def run_doctests(num_workers: int) -> boolRun all doctests in FINN and report if any failed.
def run_test(variant: str, num_workers: str, name: str = "") -> NoneRun a given test variant with the given number of workers.
Run FINN+.
def edit_file(p: Path) -> NoneTry to open the given file in the editor of choice. If none is found exit.
def output(f: Callable) -> Callable[..., Any]Add a click parameter named --output (-o) that defaults to None if the param is empty, and a path otherwise.
def finn_deps(f: Callable) -> Callable[..., Any]Add a click parameter named --dependency-path (-d) (finn_deps) that defaults to None if the param is empty, and a path otherwise.
def finn_deps_definitions(f: Callable) -> Callable[..., Any]Add a click parameter named --dependency-definitions (-D) (finn_deps_definitions) that defaults to None if the param is empty, and a path otherwise.
def finn_build_dir(f: Callable) -> Callable[..., Any]Add a click parameter named --build-path (-b) (finn_build_dir) that defaults to None if the param is empty, and a path otherwise.
def flow_config(f: Callable) -> Callable[..., Any]Add a click parameter named config (type pathlib.Path).
def model(f: Callable) -> Callable[..., Any]Add a click parameter named model (type pathlib.Path).
def verify_input(f: Callable) -> Callable[..., Any]Add a click parameter named verify_input (type NullablePath).
def verify_output(f: Callable) -> Callable[..., Any]Add a click parameter named verify_output (type NullablePath).
def num_default_workers(f: Callable) -> Callable[..., Any]Add a click parameter called --num-workers (-n) (num_default_workers). Defaults to -1.
def skip_dep_update(f: Callable) -> Callable[..., Any]Add a click parameter called --skip-dep-update (-s). Defaults to False.
def accept_defaults(f: Callable) -> Callable[..., Any]Add a click parameter called --accept-defaults. Defaults to False.
def batch(f: Callable) -> Callable[..., Any]Add a click parameter called --batch. Defaults to False.
def run_flow_wizard() -> NoneInteractively create a flow config with the user and save it.
def run_setup_wizard(settings: FINNSettings) -> NoneInteractively ask the user to confirm / change / reject the default settings if no settings file was found. Saves the edited settings. IMPORTANT: This method does not check whether the file exists, or if the passed settings contain the default values. It simply runs the wizard without questions.
def prepare_finn(settings: FINNSettings,
accept_defaults: bool,
batch: bool = False) -> NonePrepare FINN to run.
@click.group(
help=
'Produce hardware designs from ONNX models. To get started use "finn build" '
"(or run or auto) to start a FINN flow.",
invoke_without_command=True,
)
@click.option("--version", "-v", is_flag=True)
def main_group(version: bool) -> NoneMain click group.
def get_function_args() -> dictReturn key-values for the calling functions arguments. Filtered, so that no arguments accidentally get returned.
def read_model_path(flowconfig: Path) -> Path | NoneTry to read the model path from the flow config.
@click.command(help="Build a hardware design")
@output
@accept_defaults
@finn_deps
@finn_deps_definitions
@finn_build_dir
@flow_config
@model
@verify_input
@verify_output
@num_default_workers
@skip_dep_update
@click.option(
"--start",
default="",
help="If no start_step is given in the dataflow build config, "
"this starts the flow from the given step.",
)
@click.option(
"--stop",
default="",
help="If no stop_step is given in the dataflow build config, "
"this stops the flow at the given step.",
)
@batch
def build(output: Path | None, accept_defaults: bool, finn_deps: Path | None,
finn_deps_definitions: Path | None, finn_build_dir: Path | None,
verify_input: Path | None, verify_output: Path | None,
num_default_workers: int, skip_dep_update: bool, start: str,
stop: str, batch: bool, flow_config: Path,
model: Path | None) -> NoneLaunch a FINN hardware build.
@click.command(help="Run a script in a FINN environment", deprecated=True)
@accept_defaults
@finn_deps
@finn_deps_definitions
@finn_build_dir
@num_default_workers
@skip_dep_update
@batch
@click.argument(
"script",
type=click.Path(exists=True,
file_okay=True,
dir_okay=False,
executable=True,
path_type=Path),
)
def run(accept_defaults: bool, finn_deps: Path | None,
finn_deps_definitions: Path | None, finn_build_dir: Path | None,
skip_dep_update: bool, num_workers: int, script: Path,
batch: bool) -> NoneClick command line option to run a script in a FINN+ context.
Can be used for backwards compability with old FINN build flows.
@click.command(
help=
"Best effort to automatically start FINN without further configuration.")
@batch
def auto(batch: bool) -> NoneTry to run FINN guessing which files to use for config and model.
@click.group(help="Run setup wizards for various tasks.")
def wizard() -> NoneCommand group for wizards that help setup FINN.
@click.command(name="flow")
def flow_wizard() -> NoneRun the wizard helping to setup a flow config.
@click.command(name="settings")
def settings_wizard() -> NoneRun the wizard helping to set up the FINN+ settings.
@click.command(help="Run a given benchmark configuration.")
@click.option("--bench_config",
help="Name or path of experiment configuration file",
required=True)
@finn_deps
@finn_deps_definitions
@finn_build_dir
@num_default_workers
@batch
def bench(bench_config: str, finn_deps: Path | None,
finn_deps_definitions: Path | None, num_default_workers: int,
finn_build_dir: Path | None, batch: bool) -> NoneRun a benchmark.
@click.command(
help=
"Run a given test. Uses /tmp/FINN_TEST_BUILD_DIR as the temporary file location"
)
@finn_deps
@finn_deps_definitions
@finn_build_dir
@num_default_workers
@skip_dep_update
@click.option(
"--variant",
"-v",
help="Which test to execute (quick, quicktest_ci, full_ci, doctest)",
default="quick",
show_default=True,
type=click.Choice(
["quick", "quicktest_ci", "full_ci", "custom", "doctest", "doctest"]),
)
@click.option(
"--name",
default="",
required=False,
help=
"Define the test to run. Only usable in combination with --variant custom. "
"Can be passed the same syntax as pytest directly (my_test_module.py "
"| my_tests.py::TestClass::myTest | etc.)",
)
@click.option("--num-test-workers", "-t", default="auto", show_default=True)
@batch
def test(variant: str, name: str, finn_deps: Path | None,
finn_deps_definitions: Path | None, num_default_workers: int,
skip_dep_update: bool, num_test_workers: str,
finn_build_dir: Path | None, batch: bool) -> NoneRun a selected subset of the FINN(+) testsuite.
@click.group(help="Dependency management")
def deps() -> NoneClick group collecting depenency related commands.
@click.command(help="Update or install dependencies to the given path")
@accept_defaults
@finn_deps
@finn_deps_definitions
@batch
@click.option(
"--force",
"-f",
help="Overwrite any existing dependencies and make a clean install.",
is_flag=True,
)
def update(accept_defaults: bool, finn_deps: Path | None,
finn_deps_definitions: Path | None, batch: bool,
force: bool) -> NoneUpdate all FINN+ dependencies and then exit.
@click.command("edit", help="Edit the dependency definition file.")
@finn_deps_definitions
def deps_edit(finn_deps_definitions: Path | None) -> NoneEdit the dependency definition file.
@click.command(name="show", help="Show the dependencies")
@finn_deps_definitions
def deps_show(finn_deps_definitions: Path | None) -> NoneShow the dependencies.
@click.group(help="Manage FINN settings")
def settings() -> NoneClick group for config related commands.
@click.command("show", help="List the settings files contents")
def config_show() -> NoneList all settings found in the current settings file.
@click.command(name="edit", help="Open the settings in your default editor.")
def config_edit() -> NoneEdit the settings in an editor.
@click.command("create",
help="Create a configuration. Same as 'finn wizard config'.")
def config_create() -> NoneRun the configuration wizard.
@click.command(
"check",
help=
"Check that FINN starts up as expected and exit. Does not update dependencies."
)
def finn_check() -> NoneStart FINN and close it after loading the environment.
def main() -> NoneClicks entrypoint function.
Manage settings for FINN+.
def path_repr(dumper, data)Represent a given object as a string.
def resolve_relative(path: Path | str, to: Path | str | None) -> PathIf path is absolute, return it. If relative, return the combined absolute path.
If to is None, just return path (absolute).
class FINNSettings(BaseModel)Keeps track of FINN+ settings. Instantiate with FINNSettings.init().
@computed_field
@property
def num_default_workers() -> intNumber of default parallel workers.
@num_default_workers.setter
def num_default_workers(new_value: int | str) -> NoneSet number of default workers.
@computed_field
@property
def finn_build_dir() -> PathAbsolute path to the FINN_BUILD_DIR.
@finn_build_dir.setter
def finn_build_dir(new_path: str | Path | None) -> NoneSet the FINN_BUILD_DIR.
@computed_field
@property
def finn_deps() -> PathAbsolute path to the FINN_DEPS dir.
@finn_deps.setter
def finn_deps(new_path: str | Path) -> NoneSet the FINN_DEPS dir.
@computed_field
@property
def finn_deps_definitions() -> PathAbsolute path to the FINN_DEPS_DEFINITIONS.
@finn_deps_definitions.setter
def finn_deps_definitions(new_path: str | Path) -> NoneSet the FINN_DEPS_DEFINITIONS.
def update_environment() -> NoneUpdate the environment variables according to field values.
@staticmethod
def resolve_settings_file(override_settings_path: Path | None) -> PathResolve the location of the settings file. Checks the following locations in the following order.
- Override (method argument)
- FINN_SETTINGS environment variable
- In the FINN+ repository root
- In ~/.finn/ If the file does not exist, the function will still return the path for 1,2 and 4. It must then be created by another function.
@staticmethod
def init(override_settings_path: Path | None = None,
must_exist: bool = False,
flow_config: Path | None = None,
auto_set_environment_vars: bool = True,
**kwargs: Any) -> FINNSettingsCreate a settings object. Tries to resolve the settings path.
The settings file directory is resolved in this order:
FINN_SETTINGS environment variable -> Repository Root -> ~/.finn/.
If override_settings_path exists, it is used instead.
The settings are updated with the lowest priority first. (Defaults -> Settings file -> Environment -> Command line param) Thus, if a command line param is given, it is used over the others.
Validation on whether the paths exist should be done by components using the settings, not the settings themselves.
If auto_set_environment_vars is True, the envvars get set automatically when setting
a value.
Arguments:
-
**kwargs- A dictionary with initial values for the settings. -
override_settings_path- If set, overrides the resolution of the settings file. -
must_exist- If True, object creation fails if the settings file does not exist. -
flow_config- If given, this can be used to resolve finn_build_dir. If not given, relative FINN_BUILD_DIR settings cannot be resolved. -
auto_set_environment_vars- If True, set the environment variables too when assigning a setting.
Returns:
FINNSettings
def update_from(data: dict[str, Any],
update_type: str | None = None) -> FINNSettingsUpdate the model from the given data (Environment, custom dict, ...) and return it.
Arguments:
-
data- The data to update from. -
update_type- If set, this is used in the error raised in case validation fails. -
ignore- List of dict keys to NOT update from.
Returns:
-
FINNSettings- Newly validated settings.
def settingsfile_exists() -> boolReturn whether the settings file exists.
def save(installation_independent: bool, path: Path | None = None) -> NoneSave settings. If None is given saves to resolved path.
Arguments:
-
installation_independent- If True, remove attributes specific to the installation calling this command. This refers to the modules resolved when creating the settings. -
path- Where to store the settings. If None, saves at the initially resolved path.Important: Although the getter methods of the settings path return the resolved absolute paths, this method saves the relative path originally given. This is so that we don't switch from a relative path to an absolute one on saving and restoring.
@staticmethod
def get_settings_keys() -> list[str]Return all settings keys there are.
def get_path() -> PathGet the settings file path.
π Navigation: β Back to API Documentation
This page was generated automatically from source code documentation.
π Home
- Migration Guide
- Building an Accelerator
- DataflowBuildConfig Documentation
- Example Models
- Build Guides:
- Brevitas - Quantization library
- FINN+ Repository
- Custom Steps Library