LightningIRModelClassFactory

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

Bases: LightningIRClassFactory

Class factory for creating derived LightningIRModel classes from HuggingFace model classes.

__init__(MixinConfig: Type[LightningIRConfig]) None

Creates a new LightningIRClassFactory.

Parameters:

MixinConfig (Type[LightningIRConfig]) – LightningIRConfig mixin class

Methods

__init__(MixinConfig)

Creates a new LightningIRClassFactory.

from_backbone_class(BackboneClass)

Creates a derived LightningIRModel from a transformers.PreTrainedModel backbone model. If the backbone model

from_pretrained(model_name_or_path, *args, ...)

Loads a derived LightningIRModel from a pretrained HuggingFace model.

get_backbone_config(model_name_or_path)

Grabs the configuration class 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 LightningIR configuration class 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.

Attributes

cc_lir_model_type

Camel case model type of the LightningIR model.

property cc_lir_model_type: str

Camel case model type of the LightningIR model.

from_backbone_class(BackboneClass: Type[PreTrainedModel]) Type[LightningIRModel][source]
Creates a derived LightningIRModel from a transformers.PreTrainedModel backbone model. If the backbone model

is already a LightningIRModel, it is returned as is.

Parameters:

BackboneClass (Type[PreTrainedModel]) – Backbone model

Raises:
  • ValueError – If the backbone model is not a valid backbone model.

  • ValueError – If the backbone model is not a LightningIRModel and no LightningIRConfig is passed.

  • ValueError – If the LightningIRModel mixin is not registered with the Hugging Face model mapping.

Returns:

The derived LightningIRModel

Return type:

Type[LightningIRModel]

from_pretrained(model_name_or_path: str | Path, *args, **kwargs) Type[LightningIRModel][source]

Loads a derived LightningIRModel from a pretrained HuggingFace model.

Parameters:

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

Returns:

Derived LightningIRModel

Return type:

Type[LightningIRModel]

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

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

Parameters:

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

Returns:

Configuration class of the backbone model

Return type:

PretrainedConfig

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

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

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

Grabs the LightningIR configuration class 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:

Type[LightningIRConfig]

static get_lightning_ir_model_type(model_name_or_path: str | Path) str | None

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