kaira.models.ModelConfig

Inheritance diagram for ModelConfig
- class kaira.models.ModelConfig(hidden_dim: int = 256, **kwargs)[source]
Bases:
ConfigMixin,PretrainedConfigBase configuration class for Kaira models.
Provides a unified configuration interface that works with: - Hugging Face ecosystem (PretrainedConfig) - Hydra configuration management - Plain Python dictionaries
Methods
Initialize KairaModelConfig.
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.
Create config from plain dictionary.
Create config from Hydra DictConfig.
Instantiates a [PretrainedConfig] from the path to a JSON file of parameters.
From a pretrained_model_name_or_path, resolve to a dictionary of parameters, to be used for instantiating a [PretrainedConfig] using from_dict.
Returns the config that is meant to be used with text IO.
Register this class with a given auto class.
Save a configuration object to the directory save_directory, so that it can be re-loaded using the [~PretrainedConfig.from_pretrained] class method.
Serializes this instance to a Python dictionary.
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.
Save this instance to a JSON file.
Serializes this instance to a JSON string.
Updates attributes of this class with attributes from config_dict.
Updates attributes of this class with attributes from update_str.
Attributes
The number of labels for classification models.
Whether or not the model should returns all attentions.
Whether or not return [~utils.ModelOutput] instead of tuples.
- __init__(hidden_dim: int = 256, **kwargs)[source]
Initialize KairaModelConfig.
- Parameters:
hidden_dim – Hidden dimension size
**kwargs – Additional configuration parameters
- 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_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.
- 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.
- 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.
- 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.