diff --git a/src/models/glm_ocr/config.rs b/src/models/glm_ocr/config.rs index f1b246a..f3bda34 100644 --- a/src/models/glm_ocr/config.rs +++ b/src/models/glm_ocr/config.rs @@ -42,7 +42,6 @@ pub struct GlmOcrRopeParameters { pub rope_theta: f32, } - /// Text decoder configuration for GLM-OCR. #[derive(Debug, Clone, PartialEq, Deserialize, Default)] pub struct GlmOcrTextConfig { diff --git a/src/models/glm_ocr/generate.rs b/src/models/glm_ocr/generate.rs index c6c8d41..2f072a7 100644 --- a/src/models/glm_ocr/generate.rs +++ b/src/models/glm_ocr/generate.rs @@ -5,7 +5,6 @@ use aha_openai_dive::v1::resources::chat::{ use anyhow::{Result, anyhow}; use candle_core::{DType, Device, IndexOp, Tensor}; use candle_nn::VarBuilder; -use candle_transformers::utils::apply_repeat_penalty; use rocket::async_stream::stream; use rocket::futures::Stream; @@ -20,7 +19,10 @@ use crate::{ }, }, tokenizer::TokenizerModel, - utils::{build_completion_chunk_response, build_completion_response, extract_user_text, find_type_files, get_device, get_dtype, get_logit_processor, img_utils::extract_image_url}, + utils::{ + build_completion_chunk_response, build_completion_response, extract_user_text, + find_type_files, get_device, get_dtype, get_logit_processor, img_utils::extract_image_url, + }, }; pub struct GlmOcrGenerateModel { @@ -30,7 +32,6 @@ pub struct GlmOcrGenerateModel { model: GlmOcrModel, device: Device, eos_token_ids: Vec, - generation_config: GlmOcrGenerationConfig, model_name: String, image_token_id: u32, image_start_token_id: u32, @@ -64,7 +65,6 @@ impl GlmOcrGenerateModel { model, device, eos_token_ids: generation_config.eos_token_id.clone(), - generation_config, model_name: "glm-ocr".to_string(), image_token_id: cfg.image_token_id, image_start_token_id: cfg.image_start_token_id, @@ -136,7 +136,7 @@ impl GenerateModel for GlmOcrGenerateModel { }, seqlen_offset, )?; - let logits = logits.i((0, seq_len - 1, ..))?.to_dtype(DType::F32)?; + let logits = logits.i((0, seq_len - 1, ..))?.to_dtype(DType::F32)?; let next_token = logit_processor.sample(&logits)?; generate.push(next_token); @@ -215,7 +215,7 @@ impl GenerateModel for GlmOcrGenerateModel { seqlen_offset, ).map_err(|e| anyhow!(format!("forward error: {e}")))?; let logits = logits.i((0, seq_len - 1, ..)).map_err(|e| anyhow!(format!("index error: {e}")))?.to_dtype(DType::F32).map_err(|e| anyhow!(format!("dtype error: {e}")))?; - + let next_token = logit_processor.sample(&logits).map_err(|e| anyhow!(format!("sample error: {e}")))?; generated.push(next_token); @@ -254,6 +254,3 @@ impl GenerateModel for GlmOcrGenerateModel { Ok(Box::new(Box::pin(stream))) } } - - - diff --git a/src/models/glm_ocr/model.rs b/src/models/glm_ocr/model.rs index ef09dd1..95cd471 100644 --- a/src/models/glm_ocr/model.rs +++ b/src/models/glm_ocr/model.rs @@ -10,9 +10,7 @@ use candle_nn::{ use crate::{ models::{ common::GateUpDownMLP, - glm_ocr::config::{ - GlmOcrConfig, GlmOcrTextConfig, GlmOcrVisionConfig, - }, + glm_ocr::config::{GlmOcrConfig, GlmOcrTextConfig, GlmOcrVisionConfig}, }, position_embed::rope::{apply_rotary_pos_emb_vision, glm_ocr_apply_rotary_pos_emb}, utils::tensor_utils::{prepare_causal_attention_mask, repeat_kv}, diff --git a/src/models/glm_ocr/processor.rs b/src/models/glm_ocr/processor.rs index 950aa64..fa324df 100644 --- a/src/models/glm_ocr/processor.rs +++ b/src/models/glm_ocr/processor.rs @@ -87,11 +87,7 @@ impl GlmOcrProcessor { )?; // Resize image - let img = img.resize_exact( - target_w, - target_h, - image::imageops::FilterType::Lanczos3, - ); + let img = img.resize_exact(target_w, target_h, image::imageops::FilterType::Lanczos3); let target_h = target_h as usize; let target_w = target_w as usize; @@ -118,7 +114,8 @@ impl GlmOcrProcessor { let grid_h = target_h / self.patch_size; let grid_w = target_w / self.patch_size; let channels = 3; - let tensor = tensor.reshape((grid_h, self.patch_size, grid_w, self.patch_size, channels))?; + let tensor = + tensor.reshape((grid_h, self.patch_size, grid_w, self.patch_size, channels))?; let tensor = tensor.permute((0, 2, 4, 1, 3))?; let num_patches = grid_h * grid_w; let tensor = tensor.reshape((num_patches, channels, self.patch_size, self.patch_size))?; diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e0c5a3a..9120cba 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -731,7 +731,7 @@ pub fn extract_user_text(mes: &ChatCompletionParameters) -> Result { } } } - }, + } _ => {} } } diff --git a/src/utils/video_utils.rs b/src/utils/video_utils.rs index aaecf44..a64ec36 100644 --- a/src/utils/video_utils.rs +++ b/src/utils/video_utils.rs @@ -58,7 +58,6 @@ pub fn video_smart_resize( Ok((h_bar, w_bar)) } - // #[allow(unused)] // fn save_file( // frame: &ffmpeg::frame::Video,