-
Notifications
You must be signed in to change notification settings - Fork 33
Open
Description
I tried to fine tune TinyLlama with this crate. After training, the safetensors saved only contains two tensors:
lora_llama.b0
lora_llama.a0
I expand the macro in mod llama and find that these two layers will be used in embedding layers.
pub fn get_lora_model<'a>(
&'a mut self,
lora_config: candle_lora::LoraConfig,
vb: &candle_nn::VarBuilder,
linear_config: Option<candle_lora::LoraLinearConfig>,
conv1d_config: Option<candle_lora::LoraConv1dConfig>,
conv2d_config: Option<candle_lora::LoraConv2dConfig>,
embed_config: Option<candle_lora::LoraEmbeddingConfig>,
) {
let mut linear: ::std::collections::HashMap<
String,
&dyn candle_lora::LinearLayerLike,
> = ::std::collections::HashMap::new();
let mut conv1d: ::std::collections::HashMap<
String,
&dyn candle_lora::Conv1dLayerLike,
> = ::std::collections::HashMap::new();
let mut conv2d: ::std::collections::HashMap<
String,
&dyn candle_lora::Conv2dLayerLike,
> = ::std::collections::HashMap::new();
let mut embed: ::std::collections::HashMap<
String,
&dyn candle_lora::EmbeddingLayerLike,
> = ::std::collections::HashMap::new();
[(embed.insert("wte".to_string(), &*self.wte))];
if !linear.is_empty() && linear_config.is_none() {
{
::core::panicking::panic_fmt(
format_args!("Config not speified for linear layers."),
);
};
}
if !conv1d.is_empty() && conv1d_config.is_none() {
{
::core::panicking::panic_fmt(
format_args!("Config not speified for conv1d layers."),
);
};
}
if !conv2d.is_empty() && conv2d_config.is_none() {
{
::core::panicking::panic_fmt(
format_args!("Config not speified for conv2d layers."),
);
};
}
if !embed.is_empty() && embed_config.is_none() {
{
::core::panicking::panic_fmt(
format_args!("Config not speified for embedding layers."),
);
};
}
let mut builder = candle_lora::SelectedLayersBuilder::new();
if linear_config.is_some() {
builder = builder.add_linear_layers(linear, linear_config.unwrap());
}
if conv1d_config.is_some() {
builder = builder.add_conv1d_layers(conv1d, conv1d_config.unwrap());
}
if conv2d_config.is_some() {
builder = builder.add_conv2d_layers(conv2d, conv2d_config.unwrap());
}
if embed_config.is_some() {
builder = builder.add_embed_layers(embed, embed_config.unwrap());
}
let selection = builder.build();
let new_layers = candle_lora::Lora::convert_model(selection, lora_config, &vb);
[
(self
.wte = ::std::sync::Arc::new(
new_layers.embed.get("wte").unwrap().clone(),
)),
];
}So none of linear layer in the self-attention block is converted to lora layer. When I use my fine-tuned model, it behave exactly the same as before.
vrama628
Metadata
Metadata
Assignees
Labels
No labels