From ceca124d80baaa53374bd1944bd42ed3dcf01820 Mon Sep 17 00:00:00 2001 From: pirumpi Date: Fri, 18 Sep 2026 15:29:10 -0600 Subject: [PATCH 1/2] Use fixed Diffusers shard loader in fresh runtimes --- internal/imageruntime/requirements.txt | 2 +- internal/imageruntime/runtime.go | 3 ++- internal/imageruntime/runtime_test.go | 11 +++++++++++ internal/videoruntime/requirements-diffusers.txt | 2 +- internal/videoruntime/runtime.go | 7 ++++++- internal/videoruntime/runtime_test.go | 10 ++++++++++ 6 files changed, 31 insertions(+), 4 deletions(-) diff --git a/internal/imageruntime/requirements.txt b/internal/imageruntime/requirements.txt index 81d69dd..3b53d7b 100644 --- a/internal/imageruntime/requirements.txt +++ b/internal/imageruntime/requirements.txt @@ -1,4 +1,4 @@ -diffusers==0.39.0 +diffusers==0.40.0 transformers>=4.51 accelerate>=1.6 safetensors>=0.5 diff --git a/internal/imageruntime/runtime.go b/internal/imageruntime/runtime.go index 418ddc7..53ee1fb 100644 --- a/internal/imageruntime/runtime.go +++ b/internal/imageruntime/runtime.go @@ -377,7 +377,8 @@ func runDiffusers(ctx context.Context, cacheDir string, request Request) error { if request.Backend == "diffusers" && runtime.GOOS != "windows" && runtime.GOOS != "linux" { return errors.New("the CUDA image backend requires Windows or Linux") } - root := filepath.Join(cacheDir, "diffusers-runtime", "0.2.0") + // A new directory forces pre-upgrade environments to reinstall the fixed loader. + root := filepath.Join(cacheDir, "diffusers-runtime", "0.3.0-diffusers040") for _, name := range []string{"image_diffusion.py", "requirements.txt"} { data, err := source.ReadFile(name) if err != nil { diff --git a/internal/imageruntime/runtime_test.go b/internal/imageruntime/runtime_test.go index e5e71a3..4df4f9d 100644 --- a/internal/imageruntime/runtime_test.go +++ b/internal/imageruntime/runtime_test.go @@ -3,11 +3,22 @@ package imageruntime import ( "path/filepath" "slices" + "strings" "testing" "github.com/carlos/tapioca/internal/adapter" ) +func TestDiffusersUsesFixedShardLoader(t *testing.T) { + requirements, err := source.ReadFile("requirements.txt") + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(requirements), "diffusers==0.40.0\n") { + t.Fatalf("image runtime must pin the fixed Diffusers loader: %s", requirements) + } +} + func TestMFluxArgumentsIncludeEditingAndAdapters(t *testing.T) { command, args := mfluxArguments(Request{ ModelPath: "/models/flux", Prompt: "edit", Output: "/out.png", diff --git a/internal/videoruntime/requirements-diffusers.txt b/internal/videoruntime/requirements-diffusers.txt index 7a03227..9bd89be 100644 --- a/internal/videoruntime/requirements-diffusers.txt +++ b/internal/videoruntime/requirements-diffusers.txt @@ -1,4 +1,4 @@ -diffusers>=0.38,<0.40 +diffusers==0.40.0 transformers>=4.51 accelerate>=1.6 safetensors>=0.5 diff --git a/internal/videoruntime/runtime.go b/internal/videoruntime/runtime.go index e0814a1..fefb773 100644 --- a/internal/videoruntime/runtime.go +++ b/internal/videoruntime/runtime.go @@ -624,7 +624,12 @@ func waitForServer(ctx context.Context, base string, timeout time.Duration) erro } func runPython(ctx context.Context, cacheDir string, request Request, flavor string) error { - root := filepath.Join(cacheDir, "video-runtime", "0.1.1-"+flavor) + version := "0.1.1" + if flavor == "diffusers" { + // Do not reuse an environment with the vulnerable pre-0.40 shard loader. + version = "0.1.2-diffusers040" + } + root := filepath.Join(cacheDir, "video-runtime", version+"-"+flavor) script := flavor + "_video.py" requirements := "requirements-" + flavor + ".txt" for _, name := range []string{script, requirements} { diff --git a/internal/videoruntime/runtime_test.go b/internal/videoruntime/runtime_test.go index 44ac4f3..90c55eb 100644 --- a/internal/videoruntime/runtime_test.go +++ b/internal/videoruntime/runtime_test.go @@ -14,6 +14,16 @@ import ( "github.com/carlos/tapioca/internal/adapter" ) +func TestDiffusersVideoUsesFixedShardLoader(t *testing.T) { + requirements, err := source.ReadFile("requirements-diffusers.txt") + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(requirements), "diffusers==0.40.0\n") { + t.Fatalf("video runtime must pin the fixed Diffusers loader: %s", requirements) + } +} + func TestH3GraphChainsAdaptersIntoSchedulerAndGuider(t *testing.T) { python, err := exec.LookPath("python3") if err != nil { From baf27d10bfbc98a939dec29c9f86aedf066399ef Mon Sep 17 00:00:00 2001 From: pirumpi Date: Fri, 18 Sep 2026 16:27:27 -0600 Subject: [PATCH 2/2] Add opt-in Diffusers hardware smoke test --- internal/imageruntime/integration_test.go | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 internal/imageruntime/integration_test.go diff --git a/internal/imageruntime/integration_test.go b/internal/imageruntime/integration_test.go new file mode 100644 index 0000000..4a1a573 --- /dev/null +++ b/internal/imageruntime/integration_test.go @@ -0,0 +1,44 @@ +package imageruntime + +import ( + "context" + "image/png" + "os" + "path/filepath" + "runtime" + "testing" + "time" +) + +// Set TAPIOCA_DIFFUSERS_SMOKE_MODEL to a locally downloaded Diffusers model +// directory to exercise the pinned runtime on real hardware. This is opt-in +// because it installs PyTorch and generates an image. +func TestDiffusersHardwareSmoke(t *testing.T) { + modelPath := os.Getenv("TAPIOCA_DIFFUSERS_SMOKE_MODEL") + if modelPath == "" { + t.Skip("set TAPIOCA_DIFFUSERS_SMOKE_MODEL for a hardware smoke test") + } + backend := "diffusers" + if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" { + backend = "diffusers-mps" + } + output := filepath.Join(t.TempDir(), "smoke.png") + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) + defer cancel() + if err := Run(ctx, filepath.Join(t.TempDir(), "runtime"), Request{ + ModelPath: modelPath, Prompt: "A red sphere on a white table", + Output: output, Width: 512, Height: 512, Steps: 2, Seed: 1, + Backend: backend, + }); err != nil { + t.Fatal(err) + } + file, err := os.Open(output) + if err != nil { + t.Fatal(err) + } + defer file.Close() + image, err := png.DecodeConfig(file) + if err != nil || image.Width != 512 || image.Height != 512 { + t.Fatalf("invalid generated PNG: dimensions=%dx%d, error=%v", image.Width, image.Height, err) + } +}