modalities.registry package
Submodules
modalities.registry.components module
- class modalities.registry.components.ComponentEntity(component_key, variant_key, component_type, component_config_type)[source]
Bases:
object
Dataclass to store the component entity. The component entity stores the component key, the variant key, the component type and the component config type. The component key is used to identify the component type, whereas the variant key is used to identify the component. An example of a component entity is the GPT2 model with the component key “model” and the variant key “gpt2”.
- Args:
component_key (str): Key to identify the component type. variant_key (str): Variant key to identify the component. component_type (Type | Callable): Type of the component. component_config_type (Type[BaseModel]): Type of the component config.
- Parameters:
modalities.registry.registry module
- class modalities.registry.registry.Registry(components=None)[source]
Bases:
object
Registry class to store the components and their config classes.
Initializes the Registry class with an optional list of components.
- Args:
- components (list[ComponentEntity], optional): List of components to
intialize the registry with . Defaults to None.
- Parameters:
components (list[ComponentEntity] | None)
- add_entity(component_key, variant_key, component_type, component_config_type)[source]
Adds a component to the registry.
The registry has a two-level dictionary structure, where the first level is the component_key and the second level is the variant_key. The component_key is used to identify the component type, whereas the variant_key is used to identify the component variant. For instance, for a GPT 2 model the component key could be “model” and the variant key could be “gpt2”.
- Return type:
- Parameters:
- Args:
component_key (str): Key to identify the component type. variant_key (str): Variant key to identify the component. component_type (Type): Type of the component. component_config_type (Type[BaseModel]): Type of the component config.
- get_component(component_key, variant_key)[source]
Returns the component type for a given component_key and variant_key.
- Args:
component_key (str): Component key to identify the component type. variant_key (str): Variant key to identify the component variant.
- Raises:
ValueError: Raises a ValueError if the component_key or variant_key are not valid keys in the registry.
- Returns:
Type: Component type.
- get_config(component_key, variant_key)[source]
Returns the config type for a given component_key and variant_key.
- Args:
component_key (str): Component key to identify the component type. variant_key (str): Variant key to identify the component variant.
- Raises:
ValueError: Raises a ValueError if the component_key or variant_key are not valid keys in the registry.
- Returns:
Type[BaseModel]: Config type