IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /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. /get-started.md).

Python class

LinearLoRA

LinearLoRA​

class max.nn.LinearLoRA(in_dim, out_dim, max_num_loras, max_lora_rank, dtype, device, has_lora_bias=False, name=None, quantization_encoding=None)

source

Bases: Module, SupportsLoRA

Applies a linear transformation and LoRA to input:

yl=(xAT)@BTy_l = (xA^T) @ B^T. y=(xWT+b)+yly = (xW^T + b) + y_l

from max.driver import Accelerator, CPU, accelerator_count
from max.dtype import DType
from max.graph import DeviceRef
from max.nn.lora import LinearLoRA

device = Accelerator() if accelerator_count() > 0 else CPU()
device_ref = DeviceRef.from_device(device)

linear_layer = LinearLoRA(
    in_dim=256,
    out_dim=128,
    max_lora_rank=16,
    max_num_loras=100,
    dtype=DType.float32,
    device=device_ref,
    has_lora_bias=True,
    name="lora_linear"
)

Parameters:

set_lora_batch_info()​

set_lora_batch_info(lora_ids, lora_ranks, lora_grouped_offsets, num_active_loras, lora_end_idx, batch_seq_len)

source

Parameters:

Return type:

None