Skip to content

Commit

Permalink
feat: support 16 channel tae (taesd/taef1) (leejet#527)
Browse files Browse the repository at this point in the history
  • Loading branch information
stduhpf authored and Stéphane du Hamel committed Dec 28, 2024
1 parent a083ca9 commit 6737c88
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion stable-diffusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ class StableDiffusionGGML {
first_stage_model->get_param_tensors(tensors, "first_stage_model");
}
if (use_tiny_autoencoder) {
tae_first_stage = std::make_shared<TinyAutoEncoder>(backend, model_loader.tensor_storages_types, "decoder.layers", vae_decode_only);
tae_first_stage = std::make_shared<TinyAutoEncoder>(backend, model_loader.tensor_storages_types, "decoder.layers", vae_decode_only, version);
}
// first_stage_model->get_param_tensors(tensors, "first_stage_model.");

Expand Down
23 changes: 16 additions & 7 deletions tae.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ class TinyEncoder : public UnaryBlock {
int num_blocks = 3;

public:
TinyEncoder() {
TinyEncoder(int z_channels = 4)
: z_channels(z_channels) {
int index = 0;
blocks[std::to_string(index++)] = std::shared_ptr<GGMLBlock>(new Conv2d(in_channels, channels, {3, 3}, {1, 1}, {1, 1}));
blocks[std::to_string(index++)] = std::shared_ptr<GGMLBlock>(new TAEBlock(channels, channels));
Expand Down Expand Up @@ -106,7 +107,10 @@ class TinyDecoder : public UnaryBlock {
int num_blocks = 3;

public:
TinyDecoder(int index = 0) {
TinyDecoder(int z_channels = 4)
: z_channels(z_channels) {
int index = 0;

blocks[std::to_string(index++)] = std::shared_ptr<GGMLBlock>(new Conv2d(z_channels, channels, {3, 3}, {1, 1}, {1, 1}));
index++; // nn.ReLU()

Expand Down Expand Up @@ -163,12 +167,16 @@ class TAESD : public GGMLBlock {
bool decode_only;

public:
TAESD(bool decode_only = true)
TAESD(bool decode_only = true, SDVersion version = VERSION_SD1)
: decode_only(decode_only) {
blocks["decoder.layers"] = std::shared_ptr<GGMLBlock>(new TinyDecoder());
int z_channels = 4;
if (sd_version_is_dit(version)) {
z_channels = 16;
}
blocks["decoder.layers"] = std::shared_ptr<GGMLBlock>(new TinyDecoder(z_channels));

if (!decode_only) {
blocks["encoder.layers"] = std::shared_ptr<GGMLBlock>(new TinyEncoder());
blocks["encoder.layers"] = std::shared_ptr<GGMLBlock>(new TinyEncoder(z_channels));
}
}

Expand All @@ -190,9 +198,10 @@ struct TinyAutoEncoder : public GGMLRunner {
TinyAutoEncoder(ggml_backend_t backend,
std::map<std::string, enum ggml_type>& tensor_types,
const std::string prefix,
bool decoder_only = true)
bool decoder_only = true,
SDVersion version = VERSION_SD1)
: decode_only(decoder_only),
taesd(decode_only),
taesd(decode_only, version),
GGMLRunner(backend) {
taesd.init(params_ctx, tensor_types, prefix);
}
Expand Down

0 comments on commit 6737c88

Please sign in to comment.