update fmt

This commit is contained in:
jhqxxx
2026-03-07 18:09:29 +08:00
parent d2524d6a19
commit 20b5260633
6 changed files with 11 additions and 21 deletions
-1
View File
@@ -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 {
+6 -9
View File
@@ -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<u32>,
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)))
}
}
+1 -3
View File
@@ -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},
+3 -6
View File
@@ -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))?;
+1 -1
View File
@@ -731,7 +731,7 @@ pub fn extract_user_text(mes: &ChatCompletionParameters) -> Result<String> {
}
}
}
},
}
_ => {}
}
}
-1
View File
@@ -58,7 +58,6 @@ pub fn video_smart_resize(
Ok((h_bar, w_bar))
}
// #[allow(unused)]
// fn save_file(
// frame: &ffmpeg::frame::Video,