kaira.models.ModelConfig

Inheritance diagram of ModelConfig

Inheritance diagram for ModelConfig

class kaira.models.ModelConfig(hidden_dim: int = 256, **kwargs)[source]

Bases: ConfigMixin, PretrainedConfig

Base configuration class for Kaira models.

Provides a unified configuration interface that works with: - Hugging Face ecosystem (PretrainedConfig) - Hydra configuration management - Plain Python dictionaries

Methods

__init__

Initialize KairaModelConfig.

dict_torch_dtype_to_str

Checks whether the passed dictionary and its nested dicts have a torch_dtype key and if it's not None, converts torch.dtype to a string of just the type.

from_dict

Create config from plain dictionary.

from_hydra_config

Create config from Hydra DictConfig.

from_json_file

Instantiates a [PretrainedConfig] from the path to a JSON file of parameters.

get_config_dict

From a pretrained_model_name_or_path, resolve to a dictionary of parameters, to be used for instantiating a [PretrainedConfig] using from_dict.

get_text_config

Returns the config that is meant to be used with text IO.

register_for_auto_class

Register this class with a given auto class.

save_pretrained

Save a configuration object to the directory save_directory, so that it can be re-loaded using the [~PretrainedConfig.from_pretrained] class method.

to_dict

Serializes this instance to a Python dictionary.

to_diff_dict

Removes all attributes from the configuration that correspond to the default config attributes for better readability, while always retaining the config attribute from the class.

to_json_file

Save this instance to a JSON file.

to_json_string

Serializes this instance to a JSON string.

update

Updates attributes of this class with attributes from config_dict.

update_from_string

Updates attributes of this class with attributes from update_str.

Attributes

attribute_map

base_config_key

base_model_pp_plan

base_model_tp_plan

has_no_defaults_at_init

model_type

name_or_path

num_labels

The number of labels for classification models.

output_attentions

Whether or not the model should returns all attentions.

sub_configs

use_return_dict

Whether or not return [~utils.ModelOutput] instead of tuples.

model_type: str = 'kaira_base'
__init__(hidden_dim: int = 256, **kwargs)[source]

Initialize KairaModelConfig.

Parameters:
  • hidden_dim – Hidden dimension size

  • **kwargs – Additional configuration parameters

attribute_map: dict[str, str] = {}
base_config_key: str = ''
base_model_pp_plan: dict[str, tuple[list[str]]] | None = None
base_model_tp_plan: dict[str, Any] | None = None
dict_torch_dtype_to_str(d: dict[str, Any]) None

Checks whether the passed dictionary and its nested dicts have a torch_dtype key and if it’s not None, converts torch.dtype to a string of just the type. For example, torch.float32 get converted into “float32” string, which can then be stored in the json format.

classmethod from_dict(config_dict: Dict[str, Any], **kwargs)

Create config from plain dictionary.

classmethod from_hydra_config(hydra_config: DictConfig, **kwargs)

Create config from Hydra DictConfig.

classmethod from_json_file(json_file: str | PathLike) PretrainedConfig

Instantiates a [PretrainedConfig] from the path to a JSON file of parameters.

Parameters:

json_file (str or os.PathLike) – Path to the JSON file containing the parameters.

Returns:

The configuration object instantiated from that JSON file.

Return type:

[PretrainedConfig]

classmethod get_config_dict(pretrained_model_name_or_path: str | PathLike, **kwargs) tuple[dict[str, Any], dict[str, Any]]

From a pretrained_model_name_or_path, resolve to a dictionary of parameters, to be used for instantiating a [PretrainedConfig] using from_dict.

Parameters:

pretrained_model_name_or_path (str or os.PathLike) – The identifier of the pre-trained checkpoint from which we want the dictionary of parameters.

Returns:

The dictionary(ies) that will be used to instantiate the configuration object.

Return type:

tuple[Dict, Dict]

get_text_config(decoder=False) PretrainedConfig

Returns the config that is meant to be used with text IO. On most models, it is the original config instance itself. On specific composite models, it is under a set of valid names.

Parameters:

decoder (Optional[bool], optional, defaults to False) – If set to True, then only search for decoder config names.

has_no_defaults_at_init: bool = False
property name_or_path: str
property num_labels: int

The number of labels for classification models.

Type:

int

property output_attentions

Whether or not the model should returns all attentions.

Type:

bool

classmethod register_for_auto_class(auto_class='AutoConfig')

Register this class with a given auto class. This should only be used for custom configurations as the ones in the library are already mapped with AutoConfig.

Parameters:

auto_class (str or type, optional, defaults to “AutoConfig”) – The auto class to register this new configuration with.

save_pretrained(save_directory: str | PathLike, push_to_hub: bool = False, **kwargs)

Save a configuration object to the directory save_directory, so that it can be re-loaded using the [~PretrainedConfig.from_pretrained] class method.

Parameters:
  • save_directory (str or os.PathLike) – Directory where the configuration JSON file will be saved (will be created if it does not exist).

  • push_to_hub (bool, optional, defaults to False) – Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the repository you want to push to with repo_id (will default to the name of save_directory in your namespace).

  • kwargs (dict[str, Any], optional) – Additional key word arguments passed along to the [~utils.PushToHubMixin.push_to_hub] method.

sub_configs: dict[str, PretrainedConfig] = {}
to_dict() dict[str, Any]

Serializes this instance to a Python dictionary.

Returns:

Dictionary of all the attributes that make up this configuration instance.

Return type:

dict[str, Any]

to_diff_dict() dict[str, Any]

Removes all attributes from the configuration that correspond to the default config attributes for better readability, while always retaining the config attribute from the class. Serializes to a Python dictionary.

Returns:

Dictionary of all the attributes that make up this configuration instance.

Return type:

dict[str, Any]

to_json_file(json_file_path: str | PathLike, use_diff: bool = True)

Save this instance to a JSON file.

Parameters:
  • json_file_path (str or os.PathLike) – Path to the JSON file in which this configuration instance’s parameters will be saved.

  • use_diff (bool, optional, defaults to True) – If set to True, only the difference between the config instance and the default PretrainedConfig() is serialized to JSON file.

to_json_string(use_diff: bool = True) str

Serializes this instance to a JSON string.

Parameters:

use_diff (bool, optional, defaults to True) – If set to True, only the difference between the config instance and the default PretrainedConfig() is serialized to JSON string.

Returns:

String containing all the attributes that make up this configuration instance in JSON format.

Return type:

str

update(config_dict: dict[str, Any])

Updates attributes of this class with attributes from config_dict.

Parameters:

config_dict (dict[str, Any]) – Dictionary of attributes that should be updated for this class.

update_from_string(update_str: str)

Updates attributes of this class with attributes from update_str.

The expected format is ints, floats and strings as is, and for booleans use true or false. For example: “n_embd=10,resid_pdrop=0.2,scale_attn_weights=false,summary_type=cls_index”

The keys to change have to already exist in the config object.

Parameters:

update_str (str) – String with attributes that should be updated for this class.

property use_return_dict: bool

Whether or not return [~utils.ModelOutput] instead of tuples.

Type:

bool