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:
  • component_key (str)

  • variant_key (str)

  • component_type (Type | Callable)

  • component_config_type (Type[BaseModel])

component_config_type: Type[BaseModel] = <dataclasses._MISSING_TYPE object>
component_key: str = <dataclasses._MISSING_TYPE object>
component_type: Union[Type, Callable] = <dataclasses._MISSING_TYPE object>
variant_key: str = <dataclasses._MISSING_TYPE object>

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:

None

Parameters:
  • component_key (str)

  • variant_key (str)

  • component_type (Type)

  • component_config_type (Type[BaseModel])

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.

Return type:

Type

Parameters:
  • component_key (str)

  • variant_key (str)

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.

Return type:

Type[BaseModel]

Parameters:
  • component_key (str)

  • variant_key (str)

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

Module contents