Skip to content

Commit 73e7975

Browse files
authored
L4 fixes (#3161)
add fix
1 parent fe56f76 commit 73e7975

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

router/src/config.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,13 @@ impl Llama4 {
229229
pub fn pixel_shuffle_ratio(&self) -> f64 {
230230
self.vision_config.pixel_shuffle_ratio
231231
}
232-
pub fn get_aspect_ratios(&self, height: usize, width: usize) -> (usize, usize) {
232+
pub fn get_aspect_ratios(
233+
&self,
234+
height: usize,
235+
width: usize,
236+
max_chunks: usize,
237+
) -> (usize, usize) {
233238
let patch_size = self.vision_config.image_size;
234-
// How to avoid hardcoding this?
235-
let max_chunks = 15;
236239
let supported = find_supported_resolutions(max_chunks, patch_size);
237240
let (target_h, target_w) = get_best_fit(height, width, &supported, false);
238241
(target_h / patch_size, target_w / patch_size)

router/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub struct Gemma3Processor {
204204
#[derive(Clone, Debug, Serialize, Deserialize)]
205205
pub struct Llama4Processor {
206206
#[serde(default)]
207-
do_image_splitting: bool,
207+
max_patches: usize,
208208
}
209209

210210
#[derive(Debug, Clone, Deserialize, Default)]

router/src/validation.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,14 @@ fn image_tokens(
698698
let image_height = config.image_size();
699699
let patch_size = config.patch_size();
700700
let pixel_shuffle_ratio = config.pixel_shuffle_ratio();
701+
let max_patches = match preprocessor_config {
702+
Some(HubPreprocessorConfig::Llama4Processor(cfg)) => cfg.max_patches,
703+
_ => panic!("Expected Llama4Processor in preprocessor_config"),
704+
};
701705
let downsample_ratio =
702706
(1.0 / (pixel_shuffle_ratio * pixel_shuffle_ratio)).round() as usize;
703707

704-
let (ratio_h, ratio_w) = config.get_aspect_ratios(height, width);
708+
let (ratio_h, ratio_w) = config.get_aspect_ratios(height, width, max_patches);
705709
let image_width = image_height; // Assuming pixel shape: [H][W][C]
706710

707711
let num_patches_per_chunk =

server/text_generation_server/models/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ def get_model(
10411041
trust_remote_code=trust_remote_code,
10421042
processor_kwargs={
10431043
"use_fast": True,
1044-
"size": {"height": 336, "width": 336},
10451044
},
10461045
)
10471046
elif model_type == BAICHUAN:

0 commit comments

Comments
 (0)