update init
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ impl ModelType {
|
||||
ModelType::MiniCPM4 => {
|
||||
let model = MiniCPMGenerateModel::init(model_path, device, dtype)?;
|
||||
Ok(Box::new(model)as Box<dyn GenerateModel>)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ pub struct MiniCPMGenerateModel<'a> {
|
||||
im_end_id: u32,
|
||||
}
|
||||
|
||||
impl<'a> GenerateModel for MiniCPMGenerateModel<'a> {
|
||||
fn init(path: &str, device: Option<&Device>, dtype: Option<DType>) -> Result<Self> {
|
||||
impl<'a> MiniCPMGenerateModel<'a> {
|
||||
pub fn init(path: &str, device: Option<&Device>, dtype: Option<DType>) -> Result<Self> {
|
||||
let chat_template = ChatTemplate::init(path)?;
|
||||
let tokenizer = TokenizerModel::init(path)?;
|
||||
let config_path = path.to_string() + "/config.json";
|
||||
@@ -51,6 +51,9 @@ impl<'a> GenerateModel for MiniCPMGenerateModel<'a> {
|
||||
im_end_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GenerateModel for MiniCPMGenerateModel<'a> {
|
||||
|
||||
fn generate(&mut self, mes: ChatCompletionParameters) -> Result<ChatCompletionResponse> {
|
||||
let mut logit_processor = get_logit_processor(mes.temperature, mes.top_p);
|
||||
|
||||
+3
-3
@@ -10,9 +10,9 @@ use openai_dive::v1::resources::chat::{
|
||||
use rocket::futures::Stream;
|
||||
|
||||
pub trait GenerateModel {
|
||||
fn init(path: &str, device: Option<&Device>, dtype: Option<DType>) -> Result<Self>
|
||||
where
|
||||
Self: Sized;
|
||||
// fn init(path: &str, device: Option<&Device>, dtype: Option<DType>) -> Result<Self>
|
||||
// where
|
||||
// Self: Sized;
|
||||
fn generate(&mut self, mes: ChatCompletionParameters) -> Result<ChatCompletionResponse>;
|
||||
fn generate_stream(
|
||||
&mut self,
|
||||
|
||||
@@ -31,8 +31,8 @@ pub struct Qwen2_5VLGenerateModel<'a> {
|
||||
im_end_id: u32,
|
||||
}
|
||||
|
||||
impl<'a> GenerateModel for Qwen2_5VLGenerateModel<'a> {
|
||||
fn init(path: &str, device: Option<&Device>, dtype: Option<DType>) -> Result<Self> {
|
||||
impl<'a> Qwen2_5VLGenerateModel<'a> {
|
||||
pub fn init(path: &str, device: Option<&Device>, dtype: Option<DType>) -> Result<Self> {
|
||||
let chat_template = ChatTemplate::init(path)?;
|
||||
let tokenizer = TokenizerModel::init(path)?;
|
||||
let config_path = path.to_string() + "/config.json";
|
||||
@@ -57,6 +57,9 @@ impl<'a> GenerateModel for Qwen2_5VLGenerateModel<'a> {
|
||||
im_end_id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> GenerateModel for Qwen2_5VLGenerateModel<'a> {
|
||||
|
||||
fn generate(&mut self, mes: ChatCompletionParameters) -> Result<ChatCompletionResponse> {
|
||||
let mut logit_processor = get_logit_processor(mes.temperature, mes.top_p);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
use candle_nn::Activation;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
pub struct RopeScalingConfig {
|
||||
pub rope_type: String,
|
||||
pub long_factor: Vec<f32>,
|
||||
pub short_factor: Vec<f32>,
|
||||
pub original_max_position_embeddings: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
pub struct MiniCPM4Config {
|
||||
pub bos_token_id: u32,
|
||||
pub eos_token_id: u32,
|
||||
pub hidden_size: usize,
|
||||
pub intermediate_size: usize,
|
||||
pub max_position_embeddings: usize,
|
||||
pub num_attention_heads: usize,
|
||||
pub num_hidden_layers: usize,
|
||||
pub num_key_value_heads: usize,
|
||||
pub rms_norm_eps: f64,
|
||||
pub rope_scaling: RopeScalingConfig,
|
||||
pub torch_dtype: String,
|
||||
pub vocab_size: usize,
|
||||
// pub use_mup: bool,
|
||||
pub scale_emb:f32,
|
||||
pub dim_model_base: usize,
|
||||
pub scale_depth: f32,
|
||||
// pub rope_theta: f32,
|
||||
// pub kv_channels: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
pub struct VoxCPMEncoderConfig {
|
||||
hidden_dim: usize,
|
||||
ffn_dim: usize,
|
||||
num_heads: usize,
|
||||
num_layers: usize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
pub struct CfmConfig {
|
||||
sigma_min: f32,
|
||||
solver: String,
|
||||
t_scheduler: String,
|
||||
inference_cfg_rate: f32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, serde::Deserialize)]
|
||||
pub struct VoxCPMDitConfig {
|
||||
hidden_dim: usize,
|
||||
ffn_dim: usize,
|
||||
num_heads: usize,
|
||||
num_layers: usize,
|
||||
cfm_config: CfmConfig,
|
||||
}
|
||||
Reference in New Issue
Block a user