Implementation:Huggingface Peft FourierFTConfig
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Parameter_Efficient_Finetuning |
| Last Updated | 2026-02-07 14:00 GMT |
Overview
Concrete configuration dataclass for the FourierFT PEFT adapter method provided by the Huggingface PEFT library.
Description
FourierFTConfig controls the hyperparameters for FourierFT, which applies parameter-efficient fine-tuning using Discrete Fourier Transform learnable frequencies. The n_frequency parameter controls the number of trainable parameters per layer, and FourierFT can achieve comparable results to LoRA with significantly fewer parameters. This class extends PeftConfig and supports per-layer frequency patterns.
Usage
Import and use FourierFTConfig when you want to apply Fourier-based parameter-efficient fine-tuning to linear layers, achieving high parameter efficiency compared to LoRA while maintaining competitive accuracy on NLU, instruction tuning, and image classification tasks.
Code Reference
Source Location
- Repository: Huggingface_Peft
- File: src/peft/tuners/fourierft/config.py
- Lines: 24-207
Signature
@dataclass
class FourierFTConfig(PeftConfig):
n_frequency: int = 1000
scaling: float = 150.0
random_loc_seed: Optional[int] = 777
fan_in_fan_out: bool = False
target_modules: Optional[Union[list[str], str]] = None
exclude_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
n_frequency_pattern: Optional[dict] = field(default_factory=dict)
init_weights: bool = False
Import
from peft import FourierFTConfig
I/O Contract
Inputs
| Name | Type | Default | Description |
|---|---|---|---|
| n_frequency | int | 1000 | Number of learnable frequencies for DFT. Must be > 0 and <= d^2 for a d x d weight. |
| scaling | float | 150.0 | Scaling value for delta W matrix, analogous to lora_alpha in LoRA. |
| random_loc_seed | Optional[int] | 777 | Seed for the random location of frequencies (spectral entry matrix). |
| fan_in_fan_out | bool | False | Set True if layer stores weight as (fan_in, fan_out). |
| target_modules | Optional[Union[list[str], str]] | None | Module names or regex to apply FourierFT to. Only linear layers supported. |
| exclude_modules | Optional[Union[list[str], str]] | None | Module names or regex to exclude from FourierFT. |
| bias | str | "none" | Bias type. Can be 'none', 'all', or 'fourier_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 transform. |
| layers_pattern | Optional[Union[list[str], str]] | None | Layer pattern name when layers_to_transform is set. |
| n_frequency_pattern | Optional[dict] | {} | Mapping from layer names or regex to custom n_frequency values per layer. |
| init_weights | bool | False | If False (default), spectrum initialized to standard normal. If True, initialized to zeros. |
Outputs
| Name | Type | Description |
|---|---|---|
| instance | FourierFTConfig | Configuration object to pass to get_peft_model |
Usage Examples
Basic Configuration
from peft import FourierFTConfig, get_peft_model
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("model-name")
config = FourierFTConfig(
n_frequency=1000,
scaling=150.0,
target_modules=["q_proj", "v_proj"],
)
model = get_peft_model(model, config)