loaders.utils

loaders.utils

Utilities for axolotl.loaders module

Functions

Name Description
check_model_config Validates and adjusts model config based on axolotl config.
ensure_dtype Ensures all modules in the model are converted to the specified data type.
get_linear_embedding_layers Returns layer names of linear embeddings needed for LoRA based on model type.
get_module_class_from_name Gets a class from a module by its name. Copied from accelerate.utils.dataclasses
load_model_config Loads and configures a model configuration from HuggingFace or local sources.

check_model_config

loaders.utils.check_model_config(cfg, model_config)

Validates and adjusts model config based on axolotl config.

This function performs several important checks and adjustments

  • Disables model caching for better memory efficiency
  • Handles multimodal model-specific configurations
  • Validates quantization settings
  • Ensures proper LoRA configuration when using adapters with new tokens

Parameters

Name Type Description Default
cfg DictDefault Dictionary mapping axolotl config keys to values. required
model_config PretrainedConfig The model’s configuration object from transformers. required

Raises

Name Type Description
ValueError If a multimodal model lacks text configuration, if GPTQ settings are inconsistent, or if LoRA modules_to_save is improperly configured with new tokens.

ensure_dtype

loaders.utils.ensure_dtype(model, dtype=torch.bfloat16)

Ensures all modules in the model are converted to the specified data type.

get_linear_embedding_layers

loaders.utils.get_linear_embedding_layers(model_type)

Returns layer names of linear embeddings needed for LoRA based on model type.

get_module_class_from_name

loaders.utils.get_module_class_from_name(module, name)

Gets a class from a module by its name. Copied from accelerate.utils.dataclasses (https://github.com/huggingface/accelerate/blob/main/src/accelerate/utils/dataclasses.py#L2805).

Parameters

Name Type Description Default
module torch.nn.Module The module to get the class from. required
name str The name of the class. required

Returns

Name Type Description
Type[torch.nn.Module] | None The class type of the matching module, or None if no match is found.

load_model_config

loaders.utils.load_model_config(cfg)

Loads and configures a model configuration from HuggingFace or local sources.

This function determines the appropriate model config source, loads it, applies any necessary overrides, and validates it for compatibility with the axolotl config.

If cfg.cls_model_config is set, a custom config class from transformers will be used instead of AutoConfig (e.g., ‘LlamaConfig’, ‘MistralConfig’).

Parameters

Name Type Description Default
cfg DictDefault Dictionary mapping axolotl config keys to values. required

Returns

Name Type Description
PretrainedConfig | addict.Dict A configured model configuration object (AutoConfig instance), or a simple dictionary configuration for special cases like Mamba models.

Raises

Name Type Description
ValueError If configuration loading fails for reasons other than special cases that are handled (e.g., Mamba models).