modalities.models.huggingface package

Submodules

modalities.models.huggingface.huggingface_model module

class modalities.models.huggingface.huggingface_model.HuggingFaceModelTypes(value)[source]

Bases: LookupEnum

HuggingFaceModelTypes enumeration class representing different types of HuggingFace models.

Attributes:

AutoModelForCausalLM: Represents the AutoModelForCausalLM class. AutoModelForMaskedLM: Represents the AutoModelForMaskedLM class.

AutoModelForCausalLM(*args, **kwargs) = <class 'transformers.models.auto.modeling_auto.AutoModelForCausalLM'>
Return type:

None

AutoModelForMaskedLM(*args, **kwargs) = <class 'transformers.models.auto.modeling_auto.AutoModelForMaskedLM'>
Return type:

None

class modalities.models.huggingface.huggingface_model.HuggingFacePretrainedModel(model_type, model_name, prediction_key, huggingface_prediction_subscription_key, sample_key, model_args=None, kwargs=None)[source]

Bases: NNModel

HuggingFacePretrainedModel class for HuggingFace models.

Initializes a HuggingFaceModel object.

Args:

model_type (HuggingFaceModelTypes): The type of Hugging Face model. model_name (str): The name of the Hugging Face model. prediction_key (str): The key for accessing predictions. huggingface_prediction_subscription_key (str): The subscription key for Hugging Face predictions. sample_key (str): The key for accessing samples. model_args (Any, optional): Additional arguments for the Hugging Face model. Defaults to None. kwargs (Any, optional): Additional keyword arguments for the Hugging Face model. Defaults to None.

Parameters:
forward(inputs)[source]

Forward pass of the model.

Return type:

dict[str, Tensor]

Parameters:

inputs (dict[str, Tensor])

Args:

inputs (dict[str, torch.Tensor]): A dictionary containing input tensors.

Returns:

dict[str, torch.Tensor]: A dictionary containing output tensors.

property fsdp_block_names: list[str]

Returns a list of FSDP block names.

Returns:

list[str]: A list of FSDP block names.

class modalities.models.huggingface.huggingface_model.HuggingFacePretrainedModelConfig(**data)[source]

Bases: BaseModel

Configuration class for HuggingFacePretrainedModel.

Attributes:

model_type (HuggingFaceModelTypes): The type of the HuggingFace model. model_name (Path): The path to the HuggingFace model. prediction_key (str): The key for accessing the prediction. huggingface_prediction_subscription_key (str): The subscription key for HuggingFace prediction. sample_key (str): The key for accessing the sample. model_args (Any, optional): Optional additional arguments for the model. kwargs (Any, optional): Optional additional keyword arguments.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:
huggingface_prediction_subscription_key: str
kwargs: Optional[Any]
model_args: Optional[Any]
model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_name: Path
model_type: HuggingFaceModelTypes
prediction_key: str
sample_key: str

Module contents