Skip to content

Commit

Permalink
Add stable-diffusion.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Jun 5, 2024
1 parent 8e23c73 commit 3b7b1e3
Show file tree
Hide file tree
Showing 44 changed files with 554,069 additions and 7 deletions.
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ include build/rules.mk

include llamafile/BUILD.mk
include llama.cpp/BUILD.mk
include stable-diffusion.cpp/BUILD.mk
include stb/BUILD.mk

# the root package is `o//` by default
# building a package also builds its sub-packages
.PHONY: o/$(MODE)/
o/$(MODE)/: o/$(MODE)/llama.cpp o/$(MODE)/llamafile o/$(MODE)/depend.test
o/$(MODE)/: o/$(MODE)/llamafile \
o/$(MODE)/stable-diffusion.cpp \
o/$(MODE)/stb \
o/$(MODE)/depend.test

# for installing to `make PREFIX=/usr/local`
.PHONY: install
Expand Down
1 change: 0 additions & 1 deletion llama.cpp/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ o/$(MODE)/llama.cpp/ggml-backend.o \
o/$(MODE)/llama.cpp/grammar-parser.o \
o/$(MODE)/llama.cpp/json-schema-to-grammar.o \
o/$(MODE)/llama.cpp/llama.o \
o/$(MODE)/llama.cpp/stb_image.o \
o/$(MODE)/llama.cpp/unicode.o \
o/$(MODE)/llama.cpp/sampling.o \
o/$(MODE)/llama.cpp/ggml-alloc.o \
Expand Down
10 changes: 9 additions & 1 deletion llama.cpp/ggml.c
Original file line number Diff line number Diff line change
Expand Up @@ -11848,6 +11848,7 @@ IQK_MulMat_Not_Available:;

// ggml_compute_forward_out_prod

__target_clones("avx2") // [jart]
static void ggml_compute_forward_out_prod_f32(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -12266,6 +12267,7 @@ static void ggml_compute_forward_scale(

// ggml_compute_forward_set

__target_clones("avx2") // [jart]
static void ggml_compute_forward_set_f32(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -12684,6 +12686,7 @@ static void ggml_compute_forward_get_rows(

// ggml_compute_forward_get_rows_back

__target_clones("avx2") // [jart]
static void ggml_compute_forward_get_rows_back_f32_f16(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -12723,6 +12726,7 @@ static void ggml_compute_forward_get_rows_back_f32_f16(
}
}

__target_clones("avx2") // [jart]
static void ggml_compute_forward_get_rows_back_f32(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -12866,6 +12870,7 @@ static void ggml_compute_forward_diag(

// ggml_compute_forward_diag_mask_inf

__target_clones("avx2") // [jart]
static void ggml_compute_forward_diag_mask_f32(
const struct ggml_compute_params * params,
struct ggml_tensor * dst,
Expand Down Expand Up @@ -13954,6 +13959,7 @@ static void ggml_compute_forward_conv_transpose_1d(
// src0: kernel [OC, IC, KH, KW]
// src1: image [N, IC, IH, IW]
// dst: result [N, OH, OW, IC*KH*KW]
__target_clones("arch=znver4,avx2") // [jart]
static void ggml_compute_forward_im2col_f32(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -14148,6 +14154,7 @@ static void ggml_compute_forward_im2col(

// ggml_compute_forward_conv_transpose_2d

__target_clones("avx2") // [jart]
static void ggml_compute_forward_conv_transpose_2d(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -15947,6 +15954,7 @@ static void ggml_compute_forward_ssm_conv(

// ggml_compute_forward_ssm_scan

__target_clones("avx2") // [jart]
static void ggml_compute_forward_ssm_scan_f32(
const struct ggml_compute_params * params,
struct ggml_tensor * dst) {
Expand Down Expand Up @@ -21249,7 +21257,7 @@ size_t ggml_quantize_chunk(
assert(false);
}

GGML_ASSERT(result == nrows * row_size);
// GGML_ASSERT(result == nrows * row_size); // [jart] should return error

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion llama.cpp/ggml.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
#define GGML_MAX_CONTEXTS 64
#define GGML_MAX_SRC 10
#ifndef GGML_MAX_NAME
#define GGML_MAX_NAME 64
#define GGML_MAX_NAME 128 // [jart] for stable diffusion
#endif
#define GGML_MAX_OP_PARAMS 64
#define GGML_DEFAULT_N_THREADS 4
Expand Down
3 changes: 2 additions & 1 deletion llama.cpp/llava/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ o/$(MODE)/llama.cpp/llava/llava-quantize: \
o/$(MODE)/llama.cpp/llava/llava-quantize.o \
o/$(MODE)/llama.cpp/llava/llava-quantize.1.asc.zip.o \
o/$(MODE)/llama.cpp/llava/llava.a \
o/$(MODE)/llama.cpp/llama.cpp.a
o/$(MODE)/llama.cpp/llama.cpp.a \
o/$(MODE)/stb/stb.a

o/$(MODE)/llama.cpp/llava/clip.o \
o/$(MODE)/llama.cpp/llava/llava.o \
Expand Down
2 changes: 1 addition & 1 deletion llama.cpp/llava/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include "llama.cpp/llava/clip.h"
#include "llama.cpp/ggml-metal.h"
#include "llama.cpp/ggml-cuda.h"
#include "llama.cpp/stb_image.h"
#include "llama.cpp/ggml.h"
#include "stb/stb_image.h"

//#define CLIP_DEBUG_FUNCTIONS

Expand Down
1 change: 1 addition & 0 deletions llama.cpp/main/BUILD.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ o/$(MODE)/llama.cpp/main/main: \
o/$(MODE)/llama.cpp/server/server.a \
o/$(MODE)/llama.cpp/llava/llava.a \
o/$(MODE)/llama.cpp/llama.cpp.a \
o/$(MODE)/stb/stb.a \
o/$(MODE)/llama.cpp/main/main.1.asc.zip.o \
$(LLAMA_CPP_SERVER_ASSETS:%=o/$(MODE)/%.zip.o)

Expand Down
2 changes: 1 addition & 1 deletion llama.cpp/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "llama.cpp/llama.h"
#include "llama.cpp/grammar-parser.h"
#include "llama.cpp/llava/llava.h"
#include "llama.cpp/stb_image.h"
#include "stb/stb_image.h"
#include "utils.h"
#include "oai.h"
#include "llamafile/micros.h"
Expand Down
40 changes: 40 additions & 0 deletions stable-diffusion.cpp/BUILD.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#── vi: set noet ft=make ts=8 sw=8 fenc=utf-8 :vi ────────────────────┘

PKGS += STABLE_DIFFUSION_CPP

STABLE_DIFFUSION_CPP_FILES := $(wildcard stable-diffusion.cpp/*.*)
STABLE_DIFFUSION_CPP_HDRS = $(filter %.h,$(STABLE_DIFFUSION_CPP_FILES)) \
$(filter %.hpp,$(STABLE_DIFFUSION_CPP_FILES))
STABLE_DIFFUSION_CPP_INCS = $(filter %.inc,$(STABLE_DIFFUSION_CPP_FILES))
STABLE_DIFFUSION_CPP_SRCS_C = $(filter %.c,$(STABLE_DIFFUSION_CPP_FILES))
STABLE_DIFFUSION_CPP_SRCS_CPP = $(filter %.cpp,$(STABLE_DIFFUSION_CPP_FILES))
STABLE_DIFFUSION_CPP_SRCS = $(STABLE_DIFFUSION_CPP_SRCS_C) $(STABLE_DIFFUSION_CPP_SRCS_CPP)

STABLE_DIFFUSION_CPP_OBJS = \
$(LLAMAFILE_OBJS) \
$(STABLE_DIFFUSION_CPP_SRCS_C:%.c=o/$(MODE)/%.o) \
$(STABLE_DIFFUSION_CPP_SRCS_CPP:%.cpp=o/$(MODE)/%.o) \
$(STABLE_DIFFUSION_CPP_FILES:%=o/$(MODE)/%.zip.o)

o/$(MODE)/stable-diffusion.cpp/stable-diffusion.cpp.a: $(STABLE_DIFFUSION_CPP_OBJS)

$(STABLE_DIFFUSION_CPP_OBJS): private \
CCFLAGS += \
-DGGML_MULTIPLATFORM

$(STABLE_DIFFUSION_CPP_OBJS): private \
CXXFLAGS += \
-frtti

o/$(MODE)/stable-diffusion.cpp/main: \
o/$(MODE)/stable-diffusion.cpp/main.o \
o/$(MODE)/stable-diffusion.cpp/stable-diffusion.cpp.a \
o/$(MODE)/llama.cpp/llama.cpp.a \
o/$(MODE)/stb/stb.a

$(STABLE_DIFFUSION_CPP_OBJS): stable-diffusion.cpp/BUILD.mk

.PHONY: o/$(MODE)/stable-diffusion.cpp
o/$(MODE)/stable-diffusion.cpp: \
o/$(MODE)/stable-diffusion.cpp/main
21 changes: 21 additions & 0 deletions stable-diffusion.cpp/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 leejet

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
19 changes: 19 additions & 0 deletions stable-diffusion.cpp/README.llamafile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
DESCRIPTION

stable-diffusion.cpp is an image file generator

LICENSE

MIT

ORIGIN

git@github.com:leejet/stable-diffusion.cpp.git
1d2af5ca3fc30dec9657a6cca8f87c20dfd83f1c
Tue May 14 23:06:52 2024 +0800

LOCAL MODIFICATIONS

- Made crc32 go faster
- Make work with llama.cpp flavor of ggml
- Remove sd_type_t (error prone intended to be ggml_type)
Loading

0 comments on commit 3b7b1e3

Please sign in to comment.