chore: add .clang-format
This commit is contained in:
parent
64f6002457
commit
176a00b606
13
.clang-format
Normal file
13
.clang-format
Normal file
@ -0,0 +1,13 @@
|
||||
BasedOnStyle: Chromium
|
||||
UseTab: Never
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
IndentCaseLabels: false
|
||||
ColumnLimit: 0
|
||||
AccessModifierOffset: -4
|
||||
NamespaceIndentation: All
|
||||
FixNamespaceComments: false
|
||||
AlignAfterOpenBracket: true
|
||||
AlignConsecutiveAssignments: true
|
||||
IndentCaseLabels: true
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ test/
|
||||
|
||||
.cache/
|
||||
*.swp
|
||||
.vscode/
|
||||
|
@ -88,8 +88,7 @@ const char* sample_method_str[] = {
|
||||
const char* schedule_str[] = {
|
||||
"default",
|
||||
"discrete",
|
||||
"karras"
|
||||
};
|
||||
"karras"};
|
||||
|
||||
struct Option {
|
||||
int n_threads = -1;
|
||||
@ -129,7 +128,7 @@ struct Option {
|
||||
printf(" sample_steps: %d\n", sample_steps);
|
||||
printf(" strength: %.2f\n", strength);
|
||||
printf(" rng: %s\n", rng_type_to_str[rng_type]);
|
||||
printf(" seed: %lld\n", seed);
|
||||
printf(" seed: %ld\n", seed);
|
||||
}
|
||||
};
|
||||
|
||||
@ -405,6 +404,7 @@ int main(int argc, const char* argv[]) {
|
||||
vae_decode_only = false;
|
||||
|
||||
int c = 0;
|
||||
|
||||
unsigned char* img_data = stbi_load(opt.init_img.c_str(), &opt.w, &opt.h, &c, 3);
|
||||
if (img_data == NULL) {
|
||||
fprintf(stderr, "load image from '%s' failed\n", opt.init_img.c_str());
|
||||
|
6
rng.h
6
rng.h
@ -5,16 +5,16 @@
|
||||
#include <vector>
|
||||
|
||||
class RNG {
|
||||
public:
|
||||
public:
|
||||
virtual void manual_seed(uint64_t seed) = 0;
|
||||
virtual std::vector<float> randn(uint32_t n) = 0;
|
||||
};
|
||||
|
||||
class STDDefaultRNG : public RNG {
|
||||
private:
|
||||
private:
|
||||
std::default_random_engine generator;
|
||||
|
||||
public:
|
||||
public:
|
||||
void manual_seed(uint64_t seed) {
|
||||
generator.seed((unsigned int)seed);
|
||||
}
|
||||
|
@ -9,11 +9,11 @@
|
||||
// RNG imitiating torch cuda randn on CPU.
|
||||
// Port from: https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/5ef669de080814067961f28357256e8fe27544f4/modules/rng_philox.py
|
||||
class PhiloxRNG : public RNG {
|
||||
private:
|
||||
private:
|
||||
uint64_t seed;
|
||||
uint32_t offset;
|
||||
|
||||
private:
|
||||
private:
|
||||
std::vector<uint32_t> philox_m = {0xD2511F53, 0xCD9E8D57};
|
||||
std::vector<uint32_t> philox_w = {0x9E3779B9, 0xBB67AE85};
|
||||
float two_pow32_inv = 2.3283064e-10f;
|
||||
@ -87,7 +87,7 @@ class PhiloxRNG : public RNG {
|
||||
return r1;
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
PhiloxRNG(uint64_t seed = 0) {
|
||||
this->seed = seed;
|
||||
this->offset = 0;
|
||||
|
@ -322,7 +322,7 @@ const int PAD_TOKEN_ID = 49407;
|
||||
// Ref: https://github.com/openai/CLIP/blob/main/clip/simple_tokenizer.py
|
||||
// TODO: implement bpe
|
||||
class CLIPTokenizer {
|
||||
private:
|
||||
private:
|
||||
ModelType model_type = SD1;
|
||||
std::map<std::string, int32_t> encoder;
|
||||
std::regex pat;
|
||||
@ -345,7 +345,7 @@ class CLIPTokenizer {
|
||||
return text;
|
||||
}
|
||||
|
||||
public:
|
||||
public:
|
||||
CLIPTokenizer(ModelType model_type = SD1)
|
||||
: model_type(model_type){};
|
||||
std::string bpe(std::string token) {
|
||||
@ -2811,7 +2811,7 @@ struct CompVisVDenoiser : public Denoiser {
|
||||
/*=============================================== StableDiffusionGGML ================================================*/
|
||||
|
||||
class StableDiffusionGGML {
|
||||
public:
|
||||
public:
|
||||
ggml_context* clip_params_ctx = NULL;
|
||||
ggml_context* unet_params_ctx = NULL;
|
||||
ggml_context* vae_params_ctx = NULL;
|
||||
|
@ -38,10 +38,10 @@ enum Schedule {
|
||||
class StableDiffusionGGML;
|
||||
|
||||
class StableDiffusion {
|
||||
private:
|
||||
private:
|
||||
std::shared_ptr<StableDiffusionGGML> sd;
|
||||
|
||||
public:
|
||||
public:
|
||||
StableDiffusion(int n_threads = -1,
|
||||
bool vae_decode_only = false,
|
||||
bool free_params_immediately = false,
|
||||
|
Loading…
Reference in New Issue
Block a user