https://github.com/talkuhulk/ddim_scheduler_cpp
This project provides a cross-platform C++ ddim scheduler library that is consistent with the Diffusers:DDIMScheduler interface.
https://github.com/talkuhulk/ddim_scheduler_cpp
cpp ddim
Last synced: 11 months ago
JSON representation
This project provides a cross-platform C++ ddim scheduler library that is consistent with the Diffusers:DDIMScheduler interface.
- Host: GitHub
- URL: https://github.com/talkuhulk/ddim_scheduler_cpp
- Owner: TalkUHulk
- Created: 2024-05-09T14:17:05.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-06T09:48:38.000Z (almost 2 years ago)
- Last Synced: 2025-04-28T14:14:29.504Z (11 months ago)
- Topics: cpp, ddim
- Language: C++
- Homepage:
- Size: 2.21 MB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ddim_scheduler_cpp
This project provides a cross-platform C++ ddim scheduler library that can be universally deployed. It is consistent with the [Diffusers:DDIMScheduler](https://huggingface.co/docs/diffusers/api/schedulers/ddim) interface. You can easily convert Python code to C++.
ddim_scheduler_cpp是一个C++版本的ddim-scheduler库。矩阵运算使用了Eigen库,所以理论上是支持各个平台的。ddim_scheduler_cpp提供了与[Diffusers:DDIMScheduler](https://huggingface.co/docs/diffusers/api/schedulers/ddim) 相同的接口,可以直接拿来替换python版本。
### Getting Started
#### build
`mkdir build & cd build`
`cmake .. -DDDIM_SHARED_LIB=ON/OFF -DCMAKE_INSTALL_PREFIX="path you wanna install"`
`make -j8`
After install
```asm
install/
├── ddim_scheduler_cpp
└── ddimscheduler.hpp
└── lib
└── libddim_scheduler_cpp.a or libddim_scheduler_cpp.so
```
#### Example Code
You can get [scheduler_config.json](https://huggingface.co/runwayml/stable-diffusion-inpainting/blob/main/scheduler/scheduler_config.json) from huggingface.
```c++
// init from json
auto scheduler = DDIMScheduler("scheduler_config.json");
// set num_inference_steps
scheduler.set_timesteps(10);
// get timesteps
std::vector timesteps;
scheduler.get_timesteps(timesteps);
// random init for example
std::vector sample(1 * 4 * 64 * 64);
std::vector model_output(1 * 4 * 64 * 64);
for(int i = 0; i < 4 * 64 * 64; i++){
sample[i] = distribution(generator);
model_output[i] = distribution(generator);
}
// step
std::vector pred_sample;
for(auto t: timesteps){
scheduler.step(model_output, {1, 4, 3, 3}, sample, {1, 4, 3, 3}, pred_sample, t);
}
```