Implementation:Huggingface Peft BoneModel
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Parameter_Efficient_Finetuning |
| Last Updated | 2026-02-07 14:00 GMT |
Overview
Concrete tool for applying Bone (Block Affine) adaptation to pretrained models, provided by the Huggingface PEFT library.
Description
BoneModel is a tuner class that creates a Bone adaptation model from a pretrained transformers model. It injects trainable low-rank block affine transformations into target Linear layers. The method belongs to the family of orthogonal/structured adaptation approaches and is described in https://huggingface.co/papers/2409.15371.
Usage
BoneModel is typically created internally by calling get_peft_model with a BoneConfig. It can also be instantiated directly by passing a base model, a BoneConfig, and an adapter name.
Code Reference
Source Location
- Repository: Huggingface_Peft
- File: src/peft/tuners/bone/model.py
- Lines: 24-127
Signature
class BoneModel(BaseTuner):
prefix: str = "bone_"
# Inherits __init__ from BaseTuner:
# def __init__(self, model, config, adapter_name):
# ...
Import
from peft.tuners.bone import BoneModel
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| model | nn.Module | Yes | The pretrained model to adapt |
| config | BoneConfig | Yes | Configuration for the Bone adapter (rank r, init_weights) |
| adapter_name | str | Yes | Name identifier for the adapter, defaults to "default" |
Outputs
| Name | Type | Description |
|---|---|---|
| adapted_model | BoneModel | Model with Bone adapter layers injected into target Linear modules |
Usage Examples
Basic Usage
from peft import get_peft_model, BoneConfig
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("model-name")
config = BoneConfig(
r=8,
target_modules=["k_proj", "q_proj", "v_proj", "out_proj", "fc1", "fc2"],
init_weights=True,
)
model = get_peft_model(model, config)