LightningIRClassFactory

class lightning_ir.base.class_factory.LightningIRClassFactory(MixinConfig: Type[LightningIRConfig])[source]

Bases: ABC

Base class for creating derived Lightning IR classes from HuggingFace classes.

__init__(MixinConfig: Type[LightningIRConfig]) None[source]

Creates a new LightningIRClassFactory.

Parameters:

MixinConfig (Type[LightningIRConfig]) – LightningIRConfig mixin class.

Methods

__init__(MixinConfig)

Creates a new LightningIRClassFactory.

cc_lir_model_type(Config)

Camel case model type of the Lightning IR model.

from_backbone_class(BackboneClass)

Creates a derived Lightning IR class from a backbone HuggingFace class.

from_pretrained(model_name_or_path, *args, ...)

Loads a derived Lightning IR class from a pretrained HuggingFace model.

get_backbone_config(model_name_or_path)

Grabs the configuration from a checkpoint of a pretrained HuggingFace model.

get_backbone_model_type(model_name_or_path, ...)

Grabs the model type from a checkpoint of a pretrained HuggingFace model.

get_lightning_ir_config(model_name_or_path)

Grabs the Lightning IR configuration from a checkpoint of a pretrained Lightning IR model.

get_lightning_ir_model_type(model_name_or_path)

Grabs the Lightning IR model type from a checkpoint of a pretrained HuggingFace model.

cc_lir_model_type(Config: Type[LightningIRConfig]) str[source]

Camel case model type of the Lightning IR model.

abstractmethod from_backbone_class(BackboneClass: Type) Type[source]

Creates a derived Lightning IR class from a backbone HuggingFace class. Must be implemented by subclasses.

Parameters:

BackboneClass (Type) – Backbone class.

Returns:

Derived Lightning IR class.

Return type:

Type

abstractmethod from_pretrained(model_name_or_path: str | Path, *args, **kwargs) Any[source]

Loads a derived Lightning IR class from a pretrained HuggingFace model. Must be implemented by subclasses.

Parameters:

model_name_or_path (str | Path) – Path to the model or its name.

Returns:

Derived Lightning IR class.

Return type:

Any

static get_backbone_config(model_name_or_path: str | Path) PretrainedConfig[source]

Grabs the configuration from a checkpoint of a pretrained HuggingFace model.

Parameters:

model_name_or_path (str | Path) – Path to the model or its name.

Returns:

Configuration of the backbone model.

Return type:

PretrainedConfig

static get_backbone_model_type(model_name_or_path: str | Path, *args, **kwargs) str[source]

Grabs the model type from a checkpoint of a pretrained HuggingFace model.

Parameters:

model_name_or_path (str | Path) – Path to the model or its name.

Returns:

Model type of the backbone model.

Return type:

str

Raises:

ValueError – If the type of the model is None in the configuration.

static get_lightning_ir_config(model_name_or_path: str | Path) LightningIRConfig | None[source]

Grabs the Lightning IR configuration from a checkpoint of a pretrained Lightning IR model.

Parameters:

model_name_or_path (str | Path) – Path to the model or its name.

Returns:

Configuration class of the Lightning IR model.

Return type:

LightningIRConfig | None

static get_lightning_ir_model_type(model_name_or_path: str | Path) str | None[source]

Grabs the Lightning IR model type from a checkpoint of a pretrained HuggingFace model.

Parameters:

model_name_or_path (str | Path) – Path to the model or its name.

Returns:

Model type of the Lightning IR model.

Return type:

str | None

Raises:

ValueError – If the backbone model type is not found in the configuration.