Skip to content

gemma4: one image.zig for Metal and CUDA, the picture steps over the caller's core/picture - #1589

Merged
ashhart merged 2 commits into
ashhart:mainfrom
jschmied:gemma4-one-image
Oct 29, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
jschmied:gemma4-one-image

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

What

families/gemma4/cuda_image.zig was image.zig line for line, except for its picture import. Metal's build reaches core/picture by path; the CUDA module can only reach it by name. The twin test in cuda.zig kept the two copies equal.

Now there is one file. image.zig keeps the processor's constants, targetSize and budget at the top level. These now return a narrower SizeError. The picture-side steps (Error, decoderProblem, prepare) come through For(picture), the pattern glm/image_core.zig already uses:

  • Metal: gemma4.zig exports image_steps = image.For(@import("../../core/picture/picture.zig")). Its users change from image.prepare to image_steps.prepare: native/gemma4.zig and tests/gemma4/vision.zig.
  • CUDA: cuda_vision.zig instantiates it with @import("core").picture. cuda_tower.zig, cuda_backend.zig and cuda.zig import image.zig.
  • cuda_image.zig is deleted, and its pair leaves the twin test.

The function bodies move unchanged, only re-indented into For, so the patches each step produces are the same bytes.

Checks

  • Linux: lean checker adds no problems; zig build test passes.
  • macOS (M3 Pro):
    • zig build passes, including tf-gemma4-vision;
    • zig build native passes;
    • zig build test passes: 568/568 steps.
  • Not run: tf-gemma4-vision against its fixtures. There is no Gemma 4 checkpoint on that Mac.

jschmied and others added 2 commits October 29, 2026 23:43
…caller's core/picture

cuda_image.zig was image.zig line for line but for its picture import: Metal's
build reaches core/picture by path, the CUDA module by name. image.zig now
keeps the processor's constants, sizes and budgets as they were and gives the
picture-side steps (Error, decoderProblem, prepare) through For(picture), as
glm/image_core.zig does. gemma4.zig instantiates it as image_steps for Metal,
cuda_vision.zig with @import("core").picture; the twin test loses its image
pair and cuda_image.zig is gone. The bytes each step produces are unchanged.
@ashhart
ashhart merged commit 99511e8 into ashhart:main Oct 29, 2026
8 of 9 checks passed
@ashhart

ashhart commented Oct 31, 2026

Copy link
Copy Markdown
Owner

Thank you @jschmied. This is in TensorFold 1.2.0, released today: https://github.com/ashhart/TensorFold/releases/tag/v1.2.0

It landed with your commits under your own name, so you're listed as a TensorFold contributor, and it's credited to you in the release notes and the changelog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants