|
21 | 21 | from mobius.tasks._base import ( |
22 | 22 | ComponentSpec, |
23 | 23 | ModelTask, |
| 24 | + _cast_encoder_input, |
24 | 25 | _make_graph, |
25 | 26 | _make_model, |
26 | 27 | build_decoder_from_embeds, |
@@ -84,15 +85,12 @@ def _build_vision( |
84 | 85 |
|
85 | 86 | graph, builder = _make_graph(name="vision_encoder") |
86 | 87 | op = builder.op |
87 | | - # Vision encoder input is always f32 (matching GenAI's image processor |
88 | | - # output). Cast at graph entry for f16/bf16 builds. |
89 | 88 | pixel_values = builder.input( |
90 | 89 | "pixel_values", |
91 | 90 | dtype=ir.DataType.FLOAT, |
92 | 91 | shape=[batch, 3, image_size, image_size], |
93 | 92 | ) |
94 | | - if config.dtype and config.dtype != ir.DataType.FLOAT: |
95 | | - pixel_values = op.Cast(pixel_values, to=config.dtype) |
| 93 | + pixel_values = _cast_encoder_input(op, pixel_values, config) |
96 | 94 | image_features = vision(op, pixel_values=pixel_values) |
97 | 95 |
|
98 | 96 | builder.add_output(image_features, "image_features") |
@@ -140,15 +138,12 @@ def _build_vision( |
140 | 138 |
|
141 | 139 | graph, builder = _make_graph(name="vision_encoder") |
142 | 140 | op = builder.op |
143 | | - # Vision encoder input is always f32 (matching GenAI's image processor |
144 | | - # output). Cast at graph entry for f16/bf16 builds. |
145 | 141 | pixel_values = builder.input( |
146 | 142 | "pixel_values", |
147 | 143 | dtype=ir.DataType.FLOAT, |
148 | 144 | shape=[total_patches, pixel_dim], |
149 | 145 | ) |
150 | | - if config.dtype and config.dtype != ir.DataType.FLOAT: |
151 | | - pixel_values = op.Cast(pixel_values, to=config.dtype) |
| 146 | + pixel_values = _cast_encoder_input(op, pixel_values, config) |
152 | 147 | image_grid_thw = builder.input( |
153 | 148 | "image_grid_thw", |
154 | 149 | dtype=ir.DataType.INT64, |
@@ -220,15 +215,12 @@ def _build_vision( |
220 | 215 |
|
221 | 216 | graph, builder = _make_graph(name="vision_encoder") |
222 | 217 | op = builder.op |
223 | | - # Vision encoder input is always f32 (matching GenAI's image processor |
224 | | - # output). Cast at graph entry for f16/bf16 builds. |
225 | 218 | pixel_values = builder.input( |
226 | 219 | "pixel_values", |
227 | 220 | dtype=ir.DataType.FLOAT, |
228 | 221 | shape=[batch, 3, height, width], |
229 | 222 | ) |
230 | | - if config.dtype and config.dtype != ir.DataType.FLOAT: |
231 | | - pixel_values = op.Cast(pixel_values, to=config.dtype) |
| 223 | + pixel_values = _cast_encoder_input(op, pixel_values, config) |
232 | 224 |
|
233 | 225 | image_features = vision( |
234 | 226 | op, |
|
0 commit comments