Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Huggingface Peft C3AConfig

From Leeroopedia


Knowledge Sources
Domains Deep_Learning, Parameter_Efficient_Finetuning
Last Updated 2026-02-07 14:00 GMT

Overview

Concrete configuration dataclass for the C3A PEFT adapter method provided by the Huggingface PEFT library.

Description

C3AConfig controls the hyperparameters for the C3A adapter, a parameter-efficient fine-tuning method that uses block-structured weight updates. The block_size parameter must be divisible by both input and output dimensions of target layers, and increasing it reduces parameter count. This class extends PeftConfig and supports multiple weight initialization strategies.

Usage

Import and use C3AConfig when you want to apply block-structured parameter-efficient fine-tuning to a pretrained model, with configurable block sizes per layer and multiple initialization options including xavier_uniform, gaussian, and kaiming_uniform.

Code Reference

Source Location

Signature

@dataclass
class C3AConfig(PeftConfig):
    block_size: int = 256
    target_modules: Optional[Union[list[str], str]] = None
    bias: str = "none"
    modules_to_save: Optional[list[str]] = None
    layers_to_transform: Optional[Union[list[int], int]] = None
    layers_pattern: Optional[Union[list[str], str]] = None
    block_size_pattern: Optional[dict] = field(default_factory=dict)
    init_weights: Optional[Union[bool, Literal["gaussian", "kaiming_uniform", "xavier_uniform"]]] = "xavier_uniform"

Import

from peft import C3AConfig

I/O Contract

Inputs

Name Type Default Description
block_size int 256 Block size for C3A. Must be divisible by both input and output sizes of the target layer.
target_modules Optional[Union[list[str], str]] None Module names or regex to apply C3A to.
bias str "none" Bias type. Can be 'none', 'all', or 'c3a_only'.
modules_to_save Optional[list[str]] None Additional modules to set as trainable and save in the final checkpoint.
layers_to_transform Optional[Union[list[int], int]] None Specific layer indexes to apply C3A to.
layers_pattern Optional[Union[list[str], str]] None Layer pattern name when layers_to_transform is set.
block_size_pattern Optional[dict] {} Mapping from layer names or regex to custom block_size values per layer.
init_weights Optional[Union[bool, Literal["gaussian", "kaiming_uniform", "xavier_uniform"]]] "xavier_uniform" Weight initialization method. True initializes to zeros (no-op). False defaults to xavier_uniform.

Outputs

Name Type Description
instance C3AConfig Configuration object to pass to get_peft_model

Usage Examples

Basic Configuration

from peft import C3AConfig, get_peft_model
from transformers import AutoModelForCausalLM

model = AutoModelForCausalLM.from_pretrained("model-name")
config = C3AConfig(
    block_size=256,
    target_modules=["q_proj", "v_proj"],
    init_weights="xavier_uniform",
)
model = get_peft_model(model, config)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment