Commit ccf96d6
examples/gemma4_multimodal.py: pass per_layer_inputs to decoder (#320)
## Summary
After #296 ("Move Gemma4 per-layer embeddings to embedding model") the
Gemma4 embedding sub-model emits a second output `per_layer_inputs`
(`[B, S, num_layers * per_layer_dim]`) that the decoder consumes on
every step. `examples/gemma4_multimodal.py` wasn't updated to forward
this output, so any Gemma 4 build with `hidden_size_per_layer_input > 0`
(e.g. `google/gemma-4-E2B-it`) crashes at the first `decoder.run()`:
```
ValueError: Required inputs (['per_layer_inputs']) are missing from input feed
(['inputs_embeds', ..., 'attention_mask', 'position_ids'])
```
## Fix
- `prepare_decoder_feeds()`: accept an optional `per_layer_inputs`
argument and add it to the feeds dict when present. Builds without
per-layer inputs (`hidden_size_per_layer_input == 0`, e.g. larger Gemma
4 variants) keep working — the kwarg is optional.
- `generate()`: pull `embed_out.get("per_layer_inputs")` and pass it to
`prepare_decoder_feeds` on every step.
## Verification
```
$ python examples/gemma4_multimodal.py --mode text --prompt "What is 2+2?"
...
📝 TEXT-ONLY GENERATION
================================================================
Prompt: What is 2+2?
----------------------------------------------------------------
2 + 2 = **4**
```
## Related
This is the example-side counterpart to #318 which fixed the same gap in
the L4/L5 e2e test harness.
---------
Signed-off-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchuby@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent 3084bf4 commit ccf96d6
1 file changed
Lines changed: 22 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | 233 | | |
| |||
239 | 240 | | |
240 | 241 | | |
241 | 242 | | |
242 | | - | |
243 | | - | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
244 | 253 | | |
245 | 254 | | |
246 | 255 | | |
247 | 256 | | |
248 | 257 | | |
249 | 258 | | |
250 | 259 | | |
251 | | - | |
| 260 | + | |
252 | 261 | | |
253 | 262 | | |
254 | 263 | | |
255 | 264 | | |
256 | 265 | | |
257 | 266 | | |
258 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
259 | 271 | | |
260 | 272 | | |
261 | 273 | | |
| |||
479 | 491 | | |
480 | 492 | | |
481 | 493 | | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
482 | 498 | | |
483 | 499 | | |
484 | 500 | | |
485 | | - | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
486 | 504 | | |
487 | 505 | | |
488 | 506 | | |
| |||
0 commit comments