Implementation:Huggingface Peft C3AModel
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Parameter_Efficient_Finetuning |
| Last Updated | 2026-02-07 14:00 GMT |
Overview
Concrete tool for applying C3A (Column-Column-Column Adaptation) to pretrained transformer models, provided by the Huggingface PEFT library.
Description
C3AModel is a tuner class that creates a C3A model from a pretrained transformers model. It injects block-structured adapter layers into target Linear modules, where the block size can be configured per module via pattern matching. The method is described in detail in https://huggingface.co/papers/2407.19342.
Usage
C3AModel is typically created internally by calling get_peft_model with a C3AConfig. It can also be instantiated directly by passing a base model, a C3AConfig, and an adapter name.
Code Reference
Source Location
- Repository: Huggingface_Peft
- File: src/peft/tuners/c3a/model.py
- Lines: 29-102
Signature
class C3AModel(BaseTuner):
prefix: str = "c3a_"
# Inherits __init__ from BaseTuner:
# def __init__(self, model, config, adapter_name):
# ...
Import
from peft.tuners.c3a import C3AModel
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | nn.Module | Yes | The pretrained model to adapt |
| config | C3AConfig | Yes | Configuration for the C3A adapter (block_size, block_size_pattern, init_weights) |
| adapter_name | str | Yes | Name identifier for the adapter, defaults to "default" |
Outputs
| Name | Type | Description |
|---|---|---|
| adapted_model | C3AModel | Model with C3A adapter layers injected into target Linear modules |
Usage Examples
Basic Usage
from peft import get_peft_model, C3AConfig
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("model-name")
config = C3AConfig(
block_size=16,
target_modules=["q_proj", "v_proj"],
)
model = get_peft_model(model, config)