Repository navigation
Commit 661b235
authored
Add Gemma4 image_processor.json generation with onnxruntime-extension… (#209)
## Summary
Updates the ort-genai runtime integration to generate the correct image
processor config format for Gemma4 models.
## Problem
The `OrtxCreateProcessor` API in onnxruntime-extensions requires a JSON
config with a `processor.transforms` array defining an ordered pipeline
of image processing operations. Previously, Gemma4 models generated a
HuggingFace-style `processor_config.json` with raw config values
(`image_size`, `patch_size`, etc.), which caused a runtime crash:
RuntimeError: [json.exception.out_of_range.403] key 'transforms' not
found
## Changes
**`src/mobius/integrations/ort_genai/auto_export.py`**
- `_write_processor_config()`: For `gemma4`/`gemma4_text` models,
generates `image_processor.json` with the onnxruntime-extensions
transforms pipeline format (`DecodeImage` → `Gemma4ImageTransform`)
instead of the HF-style `processor_config.json`. Reads `patch_size`,
`max_soft_tokens`, and `pooling_kernel_size` from the model config.
- `_write_genai_config()`: Sets `vision.config_filename` to
`"image_processor.json"` for Gemma4 models so the genai runtime points
to the correct file.
Non-Gemma4 models are unaffected and continue generating
`processor_config.json`.
## Generated `image_processor.json` example
```json
{
"processor": {
"name": "gemma_4_image_processing",
"transforms": [
{
"operation": {
"name": "decode_image",
"type": "DecodeImage",
"attrs": { "color_space": "RGB" }
}
},
{
"operation": {
"name": "gemma4_image_transform",
"type": "Gemma4ImageTransform",
"attrs": {
"patch_size": 16,
"max_soft_tokens": 280,
"pooling_kernel_size": 3
}
}
}
]
}
}1 parent d562440 commit 661b235
2 files changed
Lines changed: 114 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
| 165 | + | |
166 | 166 | | |
167 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
168 | 177 | | |
169 | 178 | | |
170 | 179 | | |
| |||
173 | 182 | | |
174 | 183 | | |
175 | 184 | | |
176 | | - | |
177 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
178 | 193 | | |
179 | 194 | | |
180 | | - | |
181 | 195 | | |
182 | 196 | | |
183 | | - | |
184 | 197 | | |
185 | | - | |
| 198 | + | |
| 199 | + | |
186 | 200 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
191 | 222 | | |
192 | 223 | | |
| 224 | + | |
193 | 225 | | |
194 | 226 | | |
195 | 227 | | |
196 | 228 | | |
197 | 229 | | |
198 | | - | |
199 | | - | |
| 230 | + | |
200 | 231 | | |
201 | 232 | | |
202 | 233 | | |
| |||
280 | 311 | | |
281 | 312 | | |
282 | 313 | | |
| 314 | + | |
283 | 315 | | |
284 | 316 | | |
285 | 317 | | |
| |||
450 | 482 | | |
451 | 483 | | |
452 | 484 | | |
453 | | - | |
| 485 | + | |
454 | 486 | | |
455 | 487 | | |
456 | 488 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
317 | 380 | | |
318 | 381 | | |
319 | 382 | | |
| |||
780 | 843 | | |
781 | 844 | | |
782 | 845 | | |
783 | | - | |
| 846 | + | |
784 | 847 | | |
785 | 848 | | |
786 | 849 | | |
| |||
0 commit comments