Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 90 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ DOCKER_BUILD_ARGS := \
# Test configuration
BUILD_DMR ?= 1

# Main targets
.PHONY: build run clean test integration-tests test-docker-ce-installation docker-build docker-build-multiplatform docker-run docker-build-vllm docker-run-vllm docker-build-sglang docker-run-sglang docker-run-impl help validate validate-all lint docker-build-diffusers docker-run-diffusers vllm-metal-build vllm-metal-install vllm-metal-dev vllm-metal-clean build-cli install-cli
# Phony targets grouped by category
.PHONY: build run clean test integration-tests build-cli install-cli
.PHONY: validate validate-all lint help
.PHONY: docker-build docker-build-multiplatform docker-run docker-run-impl
.PHONY: docker-build-vllm docker-run-vllm docker-build-sglang docker-run-sglang
.PHONY: docker-build-diffusers docker-run-diffusers
.PHONY: test-docker-ce-installation
.PHONY: vllm-metal-build vllm-metal-install vllm-metal-dev vllm-metal-clean
.PHONY: diffusers-build diffusers-install diffusers-dev diffusers-clean
# Default target
.DEFAULT_GOAL := build

Expand Down Expand Up @@ -242,6 +249,75 @@ vllm-metal-clean:
rm -f $(VLLM_METAL_TARBALL)
@echo "vllm-metal cleaned!"

# diffusers (macOS ARM64 and Linux)
# The tarball is self-contained: includes a standalone Python 3.12 + all packages.
DIFFUSERS_RELEASE ?= v0.1.0-20260216-000000
DIFFUSERS_INSTALL_DIR := $(HOME)/.docker/model-runner/diffusers
DIFFUSERS_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
DIFFUSERS_ARCH := $(shell uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')
DIFFUSERS_TARBALL := diffusers-$(DIFFUSERS_OS)-$(DIFFUSERS_ARCH)-$(DIFFUSERS_RELEASE).tar.gz

diffusers-build:
@if [ -f "$(DIFFUSERS_TARBALL)" ]; then \
echo "Tarball already exists: $(DIFFUSERS_TARBALL)"; \
else \
echo "Building diffusers tarball..."; \
scripts/build-diffusers-tarball.sh $(DIFFUSERS_RELEASE) $(DIFFUSERS_TARBALL); \
echo "Tarball created: $(DIFFUSERS_TARBALL)"; \
fi

diffusers-install:
@VERSION_FILE="$(DIFFUSERS_INSTALL_DIR)/.diffusers-version"; \
if [ -f "$$VERSION_FILE" ] && [ "$$(cat "$$VERSION_FILE")" = "$(DIFFUSERS_RELEASE)" ]; then \
echo "diffusers $(DIFFUSERS_RELEASE) already installed"; \
exit 0; \
fi; \
if [ ! -f "$(DIFFUSERS_TARBALL)" ]; then \
echo "Error: $(DIFFUSERS_TARBALL) not found. Run 'make diffusers-build' first."; \
exit 1; \
fi; \
echo "Installing diffusers to $(DIFFUSERS_INSTALL_DIR)..."; \
rm -rf "$(DIFFUSERS_INSTALL_DIR)"; \
mkdir -p "$(DIFFUSERS_INSTALL_DIR)"; \
tar -xzf "$(DIFFUSERS_TARBALL)" -C "$(DIFFUSERS_INSTALL_DIR)"; \
echo "$(DIFFUSERS_RELEASE)" > "$$VERSION_FILE"; \
echo "diffusers $(DIFFUSERS_RELEASE) installed successfully!"
Comment on lines +269 to +284
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): diffusers-install unconditionally wipes the install dir before verifying that extraction succeeds, which can leave users without a working install on failure.

Because the target does rm -rf "$(DIFFUSERS_INSTALL_DIR)" before tar -xzf, any extraction failure (e.g., corrupt tarball, out of disk space) will remove the last working install. Consider extracting to a temporary directory under the same parent, and only deleting the old directory and moving the new one into place after extraction and verification succeed.

Suggested change
diffusers-install:
@VERSION_FILE="$(DIFFUSERS_INSTALL_DIR)/.diffusers-version"; \
if [ -f "$$VERSION_FILE" ] && [ "$$(cat "$$VERSION_FILE")" = "$(DIFFUSERS_RELEASE)" ]; then \
echo "diffusers $(DIFFUSERS_RELEASE) already installed"; \
exit 0; \
fi; \
if [ ! -f "$(DIFFUSERS_TARBALL)" ]; then \
echo "Error: $(DIFFUSERS_TARBALL) not found. Run 'make diffusers-build' first."; \
exit 1; \
fi; \
echo "Installing diffusers to $(DIFFUSERS_INSTALL_DIR)..."; \
rm -rf "$(DIFFUSERS_INSTALL_DIR)"; \
mkdir -p "$(DIFFUSERS_INSTALL_DIR)"; \
tar -xzf "$(DIFFUSERS_TARBALL)" -C "$(DIFFUSERS_INSTALL_DIR)"; \
echo "$(DIFFUSERS_RELEASE)" > "$$VERSION_FILE"; \
echo "diffusers $(DIFFUSERS_RELEASE) installed successfully!"
diffusers-install:
@VERSION_FILE="$(DIFFUSERS_INSTALL_DIR)/.diffusers-version"; \
if [ -f "$$VERSION_FILE" ] && [ "$$(cat "$$VERSION_FILE")" = "$(DIFFUSERS_RELEASE)" ]; then \
echo "diffusers $(DIFFUSERS_RELEASE) already installed"; \
exit 0; \
fi; \
if [ ! -f "$(DIFFUSERS_TARBALL)" ]; then \
echo "Error: $(DIFFUSERS_TARBALL) not found. Run 'make diffusers-build' first."; \
exit 1; \
fi; \
PARENT_DIR="$$(dirname "$(DIFFUSERS_INSTALL_DIR)")"; \
TMP_DIR="$$(mktemp -d "$$PARENT_DIR/diffusers.XXXXXX")"; \
if [ -z "$$TMP_DIR" ] || [ ! -d "$$TMP_DIR" ]; then \
echo "Error: failed to create temporary install directory"; \
exit 1; \
fi; \
echo "Installing diffusers to $(DIFFUSERS_INSTALL_DIR) via $$TMP_DIR..."; \
if ! tar -xzf "$(DIFFUSERS_TARBALL)" -C "$$TMP_DIR"; then \
echo "Error: failed to extract $(DIFFUSERS_TARBALL)"; \
rm -rf "$$TMP_DIR"; \
exit 1; \
fi; \
if [ -z "$$(ls -A "$$TMP_DIR" 2>/dev/null)" ]; then \
echo "Error: extracted diffusers directory is empty"; \
rm -rf "$$TMP_DIR"; \
exit 1; \
fi; \
rm -rf "$(DIFFUSERS_INSTALL_DIR)"; \
mv "$$TMP_DIR" "$(DIFFUSERS_INSTALL_DIR)"; \
echo "$(DIFFUSERS_RELEASE)" > "$$VERSION_FILE"; \
echo "diffusers $(DIFFUSERS_RELEASE) installed successfully!"


diffusers-dev:
@if [ -z "$(DIFFUSERS_PATH)" ]; then \
echo "Usage: make diffusers-dev DIFFUSERS_PATH=../path-to-diffusers-server"; \
exit 1; \
fi
@PYTHON_BIN=""; \
if command -v python3.12 >/dev/null 2>&1; then \
PYTHON_BIN="python3.12"; \
elif command -v python3 >/dev/null 2>&1; then \
version=$$(python3 --version 2>&1 | grep -oE '[0-9]+\.[0-9]+'); \
if [ "$$version" = "3.12" ]; then \
PYTHON_BIN="python3"; \
fi; \
fi; \
if [ -z "$$PYTHON_BIN" ]; then \
echo "Error: Python 3.12 required"; \
echo "Install with: brew install python@3.12"; \
exit 1; \
fi; \
echo "Installing diffusers from $(DIFFUSERS_PATH)..."; \
rm -rf "$(DIFFUSERS_INSTALL_DIR)"; \
$$PYTHON_BIN -m venv "$(DIFFUSERS_INSTALL_DIR)"; \
. "$(DIFFUSERS_INSTALL_DIR)/bin/activate" && \
pip install "diffusers==0.36.0" "torch==2.9.1" "transformers==4.57.5" "accelerate==1.3.0" "safetensors==0.5.2" "huggingface_hub==0.34.0" "bitsandbytes==0.49.1" "fastapi==0.115.12" "uvicorn[standard]==0.34.1" "pillow==11.2.1" && \
SITE_PACKAGES="$(DIFFUSERS_INSTALL_DIR)/lib/python3.12/site-packages" && \
cp -Rp "$(DIFFUSERS_PATH)/python/diffusers_server" "$$SITE_PACKAGES/diffusers_server" && \
echo "dev" > "$(DIFFUSERS_INSTALL_DIR)/.diffusers-version"; \
echo "diffusers dev installed from $(DIFFUSERS_PATH)"

diffusers-clean:
@echo "Removing diffusers installation and build artifacts..."
rm -rf "$(DIFFUSERS_INSTALL_DIR)"
rm -f $(DIFFUSERS_TARBALL)
@echo "diffusers cleaned!"

help:
@echo "Available targets:"
@echo " build - Build the Go application"
Expand Down Expand Up @@ -269,6 +345,10 @@ help:
@echo " vllm-metal-install - Install vllm-metal from local tarball"
@echo " vllm-metal-dev - Install vllm-metal from local source (editable)"
@echo " vllm-metal-clean - Clean vllm-metal installation and tarball"
@echo " diffusers-build - Build diffusers tarball locally"
@echo " diffusers-install - Install diffusers from local tarball"
@echo " diffusers-dev - Install diffusers from local source (editable)"
@echo " diffusers-clean - Clean diffusers installation and tarball"
@echo " help - Show this help message"
@echo ""
@echo "Backend configuration options:"
Expand All @@ -287,3 +367,11 @@ help:
@echo " make vllm-metal-build && make vllm-metal-install && make run"
@echo " 3. Install from local source (for development, requires Python 3.12):"
@echo " make vllm-metal-dev VLLM_METAL_PATH=../vllm-metal && make run"
@echo ""
@echo "diffusers (macOS ARM64 and Linux):"
@echo " 1. Auto-pull from Docker Hub (clean dev installs first: make diffusers-clean):"
@echo " make run"
@echo " 2. Build and install from tarball:"
@echo " make diffusers-build && make diffusers-install && make run"
@echo " 3. Install from local source (for development, requires Python 3.12):"
@echo " make diffusers-dev DIFFUSERS_PATH=. && make run"
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func main() {
if mlxServerPath != "" {
log.Info("MLX_SERVER_PATH", "path", mlxServerPath)
}
if diffusersServerPath != "" {
log.Info("DIFFUSERS_SERVER_PATH", "path", diffusersServerPath)
}
if vllmMetalServerPath != "" {
log.Info("VLLM_METAL_SERVER_PATH", "path", vllmMetalServerPath)
}
Expand Down Expand Up @@ -145,6 +148,8 @@ func main() {
IncludeVLLM: includeVLLM,
VLLMPath: vllmServerPath,
VLLMMetalPath: vllmMetalServerPath,
IncludeDiffusers: true,
DiffusersPath: diffusersServerPath,
}),
routing.BackendDef{Name: sglang.Name, Init: func(mm *models.Manager) (inference.Backend, error) {
return sglang.New(log, mm, log.With("component", sglang.Name), nil, sglangServerPath)
Expand All @@ -167,7 +172,7 @@ func main() {
),
IncludeResponsesAPI: true,
ExtraRoutes: func(r *routing.NormalizedServeMux, s *routing.Service) {
// Root handler - only catches exact "/" requests
// Root handler only catches exact "/" requests
r.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
if req.URL.Path != "/" {
http.NotFound(w, req)
Expand Down
Loading