inferencerlabs commited on
Commit
a3560a5
·
verified ·
1 Parent(s): 6d856ec

Upload model file

Browse files
Files changed (1) hide show
  1. configuration.py +44 -0
configuration.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Optional
2
+ import logging
3
+ from transformers import LlavaNextConfig
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+
8
+ class Granite4VisionConfig(LlavaNextConfig):
9
+ model_type = "granite4_vision"
10
+ def __init__(
11
+ self,
12
+ downsample_rate=None,
13
+ use_image_newline_parameter=True,
14
+ deepstack_layer_map: Optional[list] = None,
15
+ use_spatial_sampling: bool = False,
16
+ spatial_stride: int = 2,
17
+ spatial_vision_layer: int = -1,
18
+ spatial_target_layers: Optional[list] = None,
19
+ projector_dropout=0.1,
20
+ **kwargs
21
+ ):
22
+ self.downsample_rate = downsample_rate
23
+ self.use_image_newline_parameter = use_image_newline_parameter
24
+ self.projector_dropout = projector_dropout
25
+
26
+ # Deepstack layer map: list of (vision_layer_idx, llm_layer_idx) tuples.
27
+ # Features from each vision layer are extracted, downsampled, and injected
28
+ # at the corresponding LLM layer during forward pass.
29
+ # e.g., [(-25, 12), (-17, 8), (-9, 4), (-1, 0)]
30
+ if deepstack_layer_map is not None:
31
+ self.deepstack_layer_map = [(int(v), int(l)) for v, l in deepstack_layer_map]
32
+ assert len(self.deepstack_layer_map) == len(set(self.deepstack_layer_map)), "expecting no duplicates"
33
+ else:
34
+ self.deepstack_layer_map = None
35
+
36
+ # Spatial sampling: extracts 4 groups from a single vision layer using
37
+ # spatial offset sampling (top-left, top-right, bottom-left, bottom-right
38
+ # of each 2x2 block), each injected at a different LLM layer.
39
+ self.use_spatial_sampling = use_spatial_sampling
40
+ self.spatial_stride = spatial_stride
41
+ self.spatial_vision_layer = spatial_vision_layer
42
+ self.spatial_target_layers = spatial_target_layers or [0, 10, 20, 30]
43
+
44
+ super().__init__(**kwargs)