pipeline_test.go 1.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//go:build mlx

package qwen_image

import (
	"os"
	"testing"

	"github.com/ollama/ollama/x/imagegen/mlx"
)

// TestPipelineOutput runs the full pipeline (integration test).
// Skips if model weights not found. Requires ~50GB VRAM.
func TestPipelineOutput(t *testing.T) {
	modelPath := "../../../weights/Qwen-Image-2512"
	if _, err := os.Stat(modelPath); os.IsNotExist(err) {
		t.Skip("Skipping: model weights not found at " + modelPath)
	}

	// Load model
	pm, err := LoadPersistent(modelPath)
	if err != nil {
		t.Skipf("Skipping: failed to load model: %v", err)
	}

	// Run 2-step pipeline (minimum for stable scheduler)
	cfg := &GenerateConfig{
		Prompt: "a cat",
		Width:  256,
		Height: 256,
		Steps:  2,
		Seed:   42,
	}

	output, err := pm.GenerateFromConfig(cfg)
	if err != nil {
		t.Fatalf("Pipeline failed: %v", err)
	}
	mlx.Eval(output)

	// Verify output shape [1, C, H, W]
	shape := output.Shape()
	if len(shape) != 4 {
		t.Errorf("Expected 4D output, got %v", shape)
	}
	if shape[0] != 1 || shape[1] != 3 || shape[2] != cfg.Height || shape[3] != cfg.Width {
		t.Errorf("Shape mismatch: got %v, expected [1, 3, %d, %d]", shape, cfg.Height, cfg.Width)
	}

	// Verify values in expected range [0, 1]
	data := output.Data()
	minVal, maxVal := float32(1.0), float32(0.0)
	for _, v := range data {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	t.Logf("Output range: [%.4f, %.4f]", minVal, maxVal)

	if minVal < -0.1 || maxVal > 1.1 {
		t.Errorf("Output values out of range: [%.4f, %.4f]", minVal, maxVal)
	}
}