ml_switcheroo.frameworks.loader¶

Framework Definition Loader.

This module provides utilities to load static operation definitions from JSON files located in src/ml_switcheroo/frameworks/definitions/. It utilizes caching to ensure efficient access during runtime and discovery.

Attributes¶

DEFINITIONS_DIR

Functions¶

load_definitions(→ Dict[str, ...)

Loads static definitions for a specific framework from its JSON file.

clear_definition_cache(→ None)

Clears the LRU cache for definitions.

get_definitions_path(→ pathlib.Path)

Returns the resolved path for a framework's definition JSON.

Module Contents¶

ml_switcheroo.frameworks.loader.DEFINITIONS_DIR¶
ml_switcheroo.frameworks.loader.load_definitions(framework: str) → Dict[str, ml_switcheroo.frameworks.base.StandardMap][source]¶

Loads static definitions for a specific framework from its JSON file.

Uses functools.lru_cache to ensure the file is read and parsed only once per execution. Converts raw JSON dictionaries into StandardMap Pydantic objects.

Parameters:

framework (str) – The framework key (e.g., ‘torch’, ‘jax’).

Returns:

A dictionary mapping Operation Names to StandardDefs. Returns an empty dict if the definition file does not exist.

Return type:

Dict[str, StandardMap]

ml_switcheroo.frameworks.loader.clear_definition_cache() → None[source]¶

Clears the LRU cache for definitions. Useful for tests or hot-reloading scenarios.

ml_switcheroo.frameworks.loader.get_definitions_path(framework: str) → pathlib.Path[source]¶

Returns the resolved path for a framework’s definition JSON.

Parameters:

framework (str) – The framework key.

Returns:

The absolute path to the intended JSON file.

Return type:

Path