IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

LoRAModel

LoRAModel​

class max.pipelines.lora.LoRAModel(name, path, base_dtype, max_lora_rank, n_heads, n_kv_heads, head_dim, strict=True)

source

Bases: object

Manages LoRA weights and configuration for a single adapter.

Initializes a LoRAModel by loading its configuration and weights.

lora = LoRAModel("my_adapter", "/path/to/lora", base_dtype, max_lora_rank,
                 n_heads=32, n_kv_heads=8, head_dim=128)

Parameters:

  • name (str) – A string identifier for this adapter.
  • path (str) – Filesystem path is only supported
  • base_dtype (DType) – The base model dtype.
  • max_lora_rank (int) – The maximum LoRA rank supported by the system.
  • n_heads (int) – Number of attention heads in the base model.
  • n_kv_heads (int) – Number of key-value heads in the base model.
  • head_dim (int) – Dimension of each attention head.
  • strict (bool) – Whether to enforce strict validation while loading the adapter.

Raises:

ValueError – If weight files are not in the supported safetensors format, or if the keys in the weights are malformed or incomplete.

adapter_config​

property adapter_config: dict[str, Any]

source

A dictionary containing metadata/configuration for the LoRA adapter.

get()​

get(key)

source

Gets the WeightData from the key. If key doesn’t exist in model, then None is returned.

Parameters:

key (str) – Key of LoRA

Returns:

WeightData for the key or None if it doesn’t exist.

Return type:

WeightData | None

lora_A​

property lora_A: dict[str, WeightData]

source

A dictionary mapping weight keys to LoRA A WeightData.

lora_B​

property lora_B: dict[str, WeightData]

source

A dictionary mapping weight keys to LoRA B WeightData.

lora_bias​

property lora_bias: dict[str, WeightData]

source

A dictionary mapping weight keys to LoRA bias WeightData.