nndeploy C++ API  0.2.0
nndeploy C++ API
ddim_scheduler.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_MODEL_STABLE_DIFFUSION_DDIM_SCHEDULER_H_
3 #define _NNDEPLOY_MODEL_STABLE_DIFFUSION_DDIM_SCHEDULER_H_
4 
5 #include <random>
6 
7 #include "nndeploy/base/any.h"
8 #include "nndeploy/base/common.h"
10 #include "nndeploy/base/log.h"
11 #include "nndeploy/base/macro.h"
12 #include "nndeploy/base/object.h"
14 #include "nndeploy/base/param.h"
15 #include "nndeploy/base/status.h"
16 #include "nndeploy/base/string.h"
17 #include "nndeploy/dag/edge.h"
18 #include "nndeploy/dag/graph.h"
19 #include "nndeploy/dag/loop.h"
20 #include "nndeploy/dag/node.h"
21 #include "nndeploy/device/buffer.h"
22 #include "nndeploy/device/device.h"
24 #include "nndeploy/device/tensor.h"
27 
28 namespace nndeploy {
29 namespace stable_diffusion {
30 
32  public:
34  virtual ~DDIMSchedulerParam() {}
35 
38 
40  if (this == &other) {
41  return *this;
42  }
44  beta_start_ = other.beta_start_;
45  beta_end_ = other.beta_end_;
46  beta_schedule_ = other.beta_schedule_;
47  eta_ = other.eta_;
48  set_alpha_to_one_ = other.set_alpha_to_one_;
49  return *this;
50  }
51 
53 
54  public:
55  float beta_start_ = 0.00085; // beta起始值
56  float beta_end_ = 0.012; // beta结束值
57  std::string beta_schedule_ = "scaled_linear"; // beta调度方式
58  float eta_ = 0.0;
59  bool set_alpha_to_one_ = false; // 是否将alpha的累积乘积的最后一个元素设置为1
60 
61  public:
62  virtual base::Status serialize(rapidjson::Value &json,
63  rapidjson::Document::AllocatorType &allocator);
64  virtual base::Status deserialize(rapidjson::Value &json);
65 };
66 
68  public:
69  DDIMScheduler(SchedulerType scheduler_type);
70  virtual ~DDIMScheduler();
71 
72  virtual base::Status init(SchedulerParam *param);
73  virtual base::Status deinit();
74 
76 
77  virtual base::Status scaleModelInput(device::Tensor *sample, int index);
78 
79  virtual base::Status step(device::Tensor *sample, device::Tensor *timestep,
80  device::Tensor *latents,
81  device::Tensor *pre_sample);
82 
83  virtual std::vector<int> &getTimesteps();
84 
85  base::Status step_inner(std::vector<float> &sample, int timestep,
86  std::vector<float> &latents,
87  std::vector<float> &prev_sample);
88 
89  public:
90  float final_alpha_cumprod_ = 0.0;
91 
92  std::vector<float> betas_;
93  std::vector<float> alphas_;
94  std::vector<float> alphas_cumprod_;
95 
96  std::vector<int> timesteps_; // 时间步序列
97  DDIMSchedulerParam *ddim_scheduler_param_ = nullptr;
98 };
99 
100 } // namespace stable_diffusion
101 } // namespace nndeploy
102 
103 #endif
DDIMSchedulerParam & operator=(const DDIMSchedulerParam &other)
virtual base::Status deserialize(rapidjson::Value &json)
virtual base::Status serialize(rapidjson::Value &json, rapidjson::Document::AllocatorType &allocator)
virtual std::vector< int > & getTimesteps()
Get the Timestep object.
virtual base::Status init(SchedulerParam *param)
base::Status step_inner(std::vector< float > &sample, int timestep, std::vector< float > &latents, std::vector< float > &prev_sample)
DDIMScheduler(SchedulerType scheduler_type)
virtual base::Status setTimesteps()
Set the Timesteps object.
virtual base::Status step(device::Tensor *sample, device::Tensor *timestep, device::Tensor *latents, device::Tensor *pre_sample)
virtual base::Status scaleModelInput(device::Tensor *sample, int index)
SchedulerParam & operator=(const SchedulerParam &param)
Definition: scheduler.h:38
#define NNDEPLOY_CC_API
api
Definition: macro.h:29