Skip to content

Commit 4584286

Browse files
committed
fix: seed should be 64 bit
1 parent e5a7aec commit 4584286

File tree

5 files changed

+10
-10
lines changed

5 files changed

+10
-10
lines changed

examples/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct Option {
8787
int sample_steps = 20;
8888
float strength = 0.75f;
8989
RNGType rng_type = STD_DEFAULT_RNG;
90-
int seed = 42;
90+
int64_t seed = 42;
9191
bool verbose = false;
9292

9393
void print() {
@@ -106,7 +106,7 @@ struct Option {
106106
printf(" sample_steps: %d\n", sample_steps);
107107
printf(" strength: %.2f\n", strength);
108108
printf(" rng: %s\n", rng_type_to_str[rng_type]);
109-
printf(" seed: %d\n", seed);
109+
printf(" seed: %ld\n", seed);
110110
}
111111
};
112112

@@ -233,7 +233,7 @@ void parse_args(int argc, const char* argv[], Option* opt) {
233233
invalid_arg = true;
234234
break;
235235
}
236-
opt->seed = std::stoi(argv[i]);
236+
opt->seed = std::stoll(argv[i]);
237237
} else if (arg == "-h" || arg == "--help") {
238238
print_usage(argc, argv);
239239
exit(0);

rng.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class RNG {
88
public:
9-
virtual void manual_seed(uint32_t seed) = 0;
9+
virtual void manual_seed(uint64_t seed) = 0;
1010
virtual std::vector<float> randn(uint32_t n) = 0;
1111
};
1212

@@ -15,7 +15,7 @@ class STDDefaultRNG : public RNG {
1515
std::default_random_engine generator;
1616

1717
public:
18-
void manual_seed(uint32_t seed) {
18+
void manual_seed(uint64_t seed) {
1919
generator.seed(seed);
2020
}
2121

rng_philox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PhiloxRNG : public RNG {
9393
this->offset = 0;
9494
}
9595

96-
void manual_seed(uint32_t seed) {
96+
void manual_seed(uint64_t seed) {
9797
this->seed = seed;
9898
this->offset = 0;
9999
}

stable-diffusion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,7 +3823,7 @@ std::vector<uint8_t> StableDiffusion::txt2img(const std::string& prompt,
38233823
int height,
38243824
SampleMethod sample_method,
38253825
int sample_steps,
3826-
int seed) {
3826+
int64_t seed) {
38273827
std::vector<uint8_t> result;
38283828
struct ggml_init_params params;
38293829
params.mem_size = static_cast<size_t>(10 * 1024) * 1024; // 10M
@@ -3911,7 +3911,7 @@ std::vector<uint8_t> StableDiffusion::img2img(const std::vector<uint8_t>& init_i
39113911
SampleMethod sample_method,
39123912
int sample_steps,
39133913
float strength,
3914-
int seed) {
3914+
int64_t seed) {
39153915
std::vector<uint8_t> result;
39163916
if (init_img_vec.size() != width * height * 3) {
39173917
return result;

stable-diffusion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class StableDiffusion {
4040
int height,
4141
SampleMethod sample_method,
4242
int sample_steps,
43-
int seed);
43+
int64_t seed);
4444
std::vector<uint8_t> img2img(
4545
const std::vector<uint8_t>& init_img,
4646
const std::string& prompt,
@@ -51,7 +51,7 @@ class StableDiffusion {
5151
SampleMethod sample_method,
5252
int sample_steps,
5353
float strength,
54-
int seed);
54+
int64_t seed);
5555
};
5656

5757
void set_sd_log_level(SDLogLevel level);

0 commit comments

Comments
 (0)