1use serde::{Deserialize, Serialize};
4
5use crate::error::{PeftError, Result};
6use crate::traits::AdapterConfig;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct BaseAdapterConfig {
11 pub target_modules: Vec<String>,
13
14 #[serde(default)]
16 pub fan_in_fan_out: bool,
17
18 #[serde(default)]
20 pub modules_to_exclude: Vec<String>,
21}
22
23impl Default for BaseAdapterConfig {
24 fn default() -> Self {
25 Self {
26 target_modules: vec![
27 "q_proj".into(),
28 "k_proj".into(),
29 "v_proj".into(),
30 "o_proj".into(),
31 ],
32 fan_in_fan_out: false,
33 modules_to_exclude: Vec::new(),
34 }
35 }
36}
37
38impl AdapterConfig for BaseAdapterConfig {
39 fn validate(&self) -> Result<()> {
40 if self.target_modules.is_empty() {
41 return Err(PeftError::InvalidConfig(
42 "target_modules cannot be empty".into(),
43 ));
44 }
45 Ok(())
46 }
47}