Skip to content

perf(models): profile Gemma3n decode, then add targeted compiled fusions (profile-first) #329

Closed

Description

@inureyes

Summary

Profile Gemma3n decode first; if the bottleneck is many small per-layer ops, add targeted compiled fusions around attention projection/norm/RoPE and repeated layer glue. This is explicitly profile-before-kernel and lower priority than the shared QK-norm work.

Source: idea.md "9. Gemma3n-Specific Compiled Fusions" (P3, expected payoff unknown until profiled, risk high).

Current state

  • Gemma3n has extra model-specific attention and normalization structure compared with the simpler dense transformer paths.
  • Other Gemma code already uses model-specific fused/compiled paths where the shape is stable enough to justify it.

Proposal

  • Profile Gemma3n decode FIRST, then consider compiled fusions around attention projection/norm/RoPE and any repeated layer glue that shows up as small-kernel overhead.
  • Treat this as a later, high-risk item because it is less reusable than the generic QK-norm fusion (tracked separately as the "generalize fused QKV+RMSNorm+RoPE" issue from idea.md item 2).

Validation

  • Profile before writing kernels.
  • Compare text-only and VLM prompts, because the vision-path interaction can dominate prefill while text decode exposes different bottlenecks.

Acceptance criteria

  • A decode profile of Gemma3n is captured FIRST and attached, identifying the dominant small-kernel overhead, or showing there is none.
  • Compiled fusions are added only where the profile justifies them; otherwise the issue closes with the profiling finding documented.
  • Text-only vs VLM prompt comparison recorded.
  • Any fusion validated for correctness (RMS vs the graph reference) and decode tok/s, with no regression on the non-fused path. (N/A: profile did not justify a fusion; none added. See docs/benchmark_results/gemma3n-decode-profile.md.)
  • This work does not block or outrank the shared QK-norm fusion.

Risk and priority

idea.md priority P3; risk high. Least reusable of the ideas; it should not outrank the shared QK-norm or scheduler work until traces prove it.

References

  • idea.md "9. Gemma3n-Specific Compiled Fusions".
  • Code: src/models/gemma3n*.rs. Related: the generic QK-norm fusion issue (idea.md item 2).

Metadata

Metadata

Assignees

Labels

area:corearea:modelspriority:backlogstatus:donetype:performance

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions